Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introducing DayTime #109

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Introducing DayTime #109

wants to merge 5 commits into from

Conversation

jchambers
Copy link

As discussed in #108, this introduces a DayTime class that combines a day-of-week and time-of-day (e.g. "Monday at 13:45").

I know I said I'd do some style-normalizing work first, but it occurred to me that there may some more structural things that need feedback, and so it's probably best to get an early round of review. I still fully intend to sort out the code style differences.

This closes #108.


@Override
public String toString() {
return dayOfWeek.getDisplayName(TextStyle.FULL, Locale.getDefault()) + " " + localTime.toString();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I'm looking at it, this probably shouldn't be locale-sensitive; if we want locale-sensitivity, that probably belongs in a dedicated "get for display" method that takes a Locale as an argument.

Copy link
Member

@jodastephen jodastephen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. This is an initial review. I think all the basics are here, although it will need a full review later,

src/main/java/org/threeten/extra/DayTime.java Show resolved Hide resolved
private static final long SECONDS_PER_DAY = MILLIS_PER_DAY / 1000;
private static final long MINUTES_PER_DAY = SECONDS_PER_DAY / 60;

private DayTime(final DayOfWeek dayOfWeek, final LocalTime localTime) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All methods should not use final on parameters

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this project, even private methods have full Javadoc

/**
* Obtains a {@code DayTime} with the given day of the week and local time.
*
* @param dayOfWeek the day of the week to represent; must not be {@code null}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two spaces after parameter name: dayOfWeek the day -> dayOfWeek the day

; must not be {@code null} -> , not null

(same comment on all methods)

*
* @param dayOfWeek the day of the week to represent; must not be {@code null}
* @param localTime the local time of day to represent; must not be {@code null}
*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No blank line between @param and @return

return new DayTime(dayOfWeek, localTime);
}

public static DayTime from(final TemporalAccessor temporalAccessor) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Javadoc

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. Wrong comment. Not done yet!

src/main/java/org/threeten/extra/DayTime.java Outdated Show resolved Hide resolved
src/main/java/org/threeten/extra/DayTime.java Outdated Show resolved Hide resolved
src/main/java/org/threeten/extra/DayTime.java Outdated Show resolved Hide resolved

import static org.junit.Assert.*;

public class DayTimeTest {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment

@jchambers
Copy link
Author

Thanks for the review! That all sounds totally reasonable and doable, and I'll get on it shortly. I should also mention that my other broad goal is to raise test coverage; the current coverage is well below what I'm seeing in other classes in threeten-extra.

@joshuaali
Copy link

This looks very useful. Is there anything I can do to help push this along?

@jchambers
Copy link
Author

jchambers commented Sep 1, 2019

I have a lovely team of seven engineers. Would you mind managing them for a week or two? ;)

In all seriousness, most of the work that remains is bringing unit tests in line with the standards of the rest of the threeten-extra project in terms of coverage and style. If you wanted to take a shot at that, it'd certainly be welcome!

I do fully intend to finish this work as soon as time allows, for what it's worth. I'm afraid the opportunity has been slow to present itself, though.

@MCEmperor
Copy link

I was just about to pull-request an implementation of this concept, elaborating on Basil's answer to a question on Stack Overflow. But then I saw this, which looks very nice.
Is there a way to collaborate, so this pull-request can be completed?

@jchambers
Copy link
Author

Well, I think the assessment of the work that remains is still accurate. If you want to smooth out the tests, please feel free (mechanically, I think that would mean adding my fork as a remote, then branching off of my branch). Otherwise, I guess I'm really not going anywhere on the weekends these days, so given the reminder, I can probably just knock this out soon.

@codecov
Copy link

codecov bot commented Jun 13, 2020

Codecov Report

Merging #109 into master will decrease coverage by 0.81%.
The diff coverage is 55.14%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #109      +/-   ##
============================================
- Coverage     88.81%   87.99%   -0.82%     
- Complexity     2288     2320      +32     
============================================
  Files            57       58       +1     
  Lines          4290     4397     +107     
  Branches        609      622      +13     
============================================
+ Hits           3810     3869      +59     
- Misses          324      364      +40     
- Partials        156      164       +8     
Impacted Files Coverage Δ Complexity Δ
src/main/java/org/threeten/extra/DayTime.java 55.14% <55.14%> (ø) 32.00 <32.00> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f0b679e...7153eb4. Read the comment docs.

@jchambers
Copy link
Author

I'm working on finishing the docs and tests this weekend and—as one would hope of writing docs and tests—the process is leading me to think more carefully about some decisions.

I mentioned in an earlier comment that I had made some decisions for my own project about comparability that may not be universally-applicable. Looking at this again, DayTime implements Comparable (as a Temporal must), and I'm struggling to reconcile a few problems:

  • LocalTime makes the decision to compare times based on their timeline positions, but times within a day have a logical start and end. To do the same for a DayTime, need to make a judgment about when a week starts and ends.
  • Taking a linear approach to comparison can lead to surprising results to callers who don't know what we're calling the start of the week. Maybe that's okay as long as we're clear about it in the docs, though?
  • The most sensible approach to implementing until is—in my mind at least—to take a "time always moves forward" approach, so "Monday at 11:59" until "Monday at noon" would be one minute, but "Monday at noon" until "Monday at 11:59" would be one week minus one minute.
  • Taking a time-moves-forward approach to until would produce results that conflict with a linear model of compareTo. Maybe that's okay, though!

I'm not convinced there's a single right answer here, but I'd welcome perspective and suggestions. Thanks kindly!

@MCEmperor
Copy link

@jchambers Those are hard questions. It may seem intuitive to regard DayTime in a circular fashion, as a value represented by DayTime` is a recurring value.

I think a linear approach of DayTime seems the best fit. It is consistent with both DayOfWeek and LocalTime. DayOfWeek itself simply defines Monday to be the start of the week, and for example TUESDAY.compareTo(THURSDAY) returns a value < 0. This approach seems to be followed in this pull request. Of course, this needs to be made explicit in the docs.

However, regarding the implementation of the until method – I'm not sure about the until-always-forward approach. It seems sensible, yes, but as you already mentioned, it conflicts with compareTo. The question is whether that's okay or not. I do not know.
Another approach could be to implement the until method in a linear matter, that means that the method may return negative values if the end lies "before" the start, "before" being Monday at 00:00:00.000000000. And then add an extra method untilNext which exposes the time-moves-forward behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Add a DayTime Temporal
4 participants