-
-
Notifications
You must be signed in to change notification settings - Fork 429
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
Relative functions for DateTimeType #4276
base: main
Are you sure you want to change the base?
Changes from 3 commits
cdfceb1
5d4ed15
8f5bff9
a866b07
8394e4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -43,6 +43,7 @@ | |||||
* @author Erdoan Hadzhiyusein - Added ZonedDateTime tests | ||||||
* @author Laurent Garnier - Enhanced tests | ||||||
* @author Gaël L'hopital - added ability to use second and milliseconds unix time | ||||||
* @author Gaël L'hopital - added isToday, isTomorrow, isYesterday tests | ||||||
*/ | ||||||
@NonNullByDefault | ||||||
public class DateTimeTypeTest { | ||||||
|
@@ -290,6 +291,21 @@ public void epochTest() { | |||||
assertThat(epochStandard, is(zdtStandard)); | ||||||
} | ||||||
|
||||||
@Test | ||||||
public void relativeTest() { | ||||||
DateTimeType dt1 = new DateTimeType("2019-06-12T17:30:00Z"); | ||||||
DateTimeType dt2 = new DateTimeType("2019-06-12T00:00:00+0000"); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To ensure that this checks for the same instant: dt1 = "2019-06-13T01:10:00+02" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed |
||||||
|
||||||
assertTrue(dt1.sameDay(dt2)); | ||||||
assertTrue(new DateTimeType().isToday()); | ||||||
|
||||||
DateTimeType now = new DateTimeType(); | ||||||
DateTimeType tomorrow = new DateTimeType(now.getZonedDateTime().plusHours(24)); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I know this is an edge case, but the length of the day isn't always precisely 24h. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to avoid using the same method than what's used in the object itself. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed |
||||||
DateTimeType yesterday = new DateTimeType(now.getZonedDateTime().minusHours(24)); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed |
||||||
assertTrue(tomorrow.isTomorrow()); | ||||||
assertTrue(yesterday.isYesterday()); | ||||||
} | ||||||
|
||||||
@ParameterizedTest | ||||||
@MethodSource("parameters") | ||||||
public void createDate(ParameterSet parameterSet) { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this use
witZoneSameInstant
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed