|
|
@@ -3,7 +3,6 @@ package net.ranides.assira.time;
|
|
|
import org.junit.Test;
|
|
|
|
|
|
import java.time.DateTimeException;
|
|
|
-import java.time.Duration;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalTime;
|
|
|
import java.time.ZoneId;
|
|
|
@@ -11,17 +10,24 @@ import java.time.ZonedDateTime;
|
|
|
import java.time.temporal.ChronoUnit;
|
|
|
|
|
|
import static net.ranides.assira.time.DateTimeZones.PL;
|
|
|
+import static net.ranides.assira.time.DateTimeZones.TV;
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
import static org.junit.Assert.assertThrows;
|
|
|
|
|
|
-public class ZonedTimeTest1 {
|
|
|
+public class ZonedTimeTest {
|
|
|
|
|
|
@Test
|
|
|
public void testWithDate() {
|
|
|
ZonedTime time = ZonedTime.of(PL, LocalTime.of(14, 25, 31));
|
|
|
|
|
|
- System.out.println(time);
|
|
|
- System.out.println(time.withDate(ZonedDate.of(PL, LocalDate.of(0,1,1))));
|
|
|
+ ZonedDate date1 = ZonedDate.of(PL, LocalDate.of(0, 1, 1));
|
|
|
+ assertEquals("0000-01-01T14:25:31+01:24[Europe/Warsaw]", time.withDate(date1).toString());
|
|
|
+
|
|
|
+ ZonedDate date2 = ZonedDate.of(PL, LocalDate.of(1976, 5, 18));
|
|
|
+ assertEquals("1976-05-18T14:25:31+01:00[Europe/Warsaw]", time.withDate(date2).toString());
|
|
|
+
|
|
|
+ ZonedDate date3 = ZonedDate.of(TV, LocalDate.of(1976, 5, 18));
|
|
|
+ assertThrows(DateTimeException.class, () -> time.withDate(date3));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
@@ -31,30 +37,15 @@ public class ZonedTimeTest1 {
|
|
|
|
|
|
assertEquals(65L, time1a.until(time1b, ChronoUnit.MINUTES));
|
|
|
|
|
|
- ZonedTime time2a = ZonedTime.of(PL, LocalTime.of(8, 15, 0));
|
|
|
- ZonedTime time2b = ZonedTime.of(PL, LocalTime.of(9, 20, 0));
|
|
|
+ ZonedTime time2a = DateTimeLiteral.time(PL, 8, 15, 0);
|
|
|
+ ZonedTime time2b = DateTimeLiteral.time(PL, 9, 20, 0);
|
|
|
|
|
|
assertEquals(65L, time2a.until(time2b, ChronoUnit.MINUTES));
|
|
|
|
|
|
- ZonedTime time3a = ZonedTime.of(ZonedDateTime.of(1980, 1, 1, 8, 15, 0, 0, PL));
|
|
|
- ZonedTime time3b = ZonedTime.of(ZonedDateTime.of(1980, 1, 1, 9, 20, 0, 0, PL));
|
|
|
-
|
|
|
- assertEquals(65L, time3a.until(time3b, ChronoUnit.MINUTES));
|
|
|
-
|
|
|
- // @todo move to another test
|
|
|
- ZonedDateTime datetime4a = DateTimeLiteral.datetimeUtc(1980, 1, 1, 23, 45, 0);
|
|
|
- ZonedDateTime datetime4b = DateTimeLiteral.datetime(1980, 1, 1, 23, 45, 0);
|
|
|
-
|
|
|
- assertEquals(Duration.ofHours(1), DateTimeUtils.diff(datetime4a, datetime4b));
|
|
|
- assertEquals(Duration.ofHours(1), DateTimeUtils.diff(datetime4b, datetime4a));
|
|
|
-
|
|
|
-
|
|
|
- ZonedTime time4a = DateTimeLiteral.timeUtc(23, 45, 0);
|
|
|
- ZonedTime time4b = DateTimeLiteral.time(22, 45, 0);
|
|
|
-
|
|
|
- assertEquals(Duration.ofHours(23), DateTimeUtils.diff(time4a, time4b));
|
|
|
- assertEquals(Duration.ofHours(1), DateTimeUtils.diff(time4b, time4a));
|
|
|
+ ZonedTime time3a = DateTimeLiteral.time(PL, 8, 15, 0);
|
|
|
+ ZonedTime time3b = DateTimeLiteral.time(TV, 9, 20, 0);
|
|
|
|
|
|
+ assertThrows(DateTimeException.class, () -> time3a.until(time3b, ChronoUnit.MINUTES));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
@@ -70,14 +61,13 @@ public class ZonedTimeTest1 {
|
|
|
ZonedTime time2 = ZonedTime.of(ZonedDateTime.of(1970, 1, 1, 6, 45, 0, 0, zone));
|
|
|
|
|
|
assertEquals("1980-01-01T06:45Z[UTC]", time1.withDate(base1).toString());
|
|
|
-// assertEquals("1979-12-31T18:45Z[UTC]", time1.withDate(base2).toString());
|
|
|
-// assertEquals("2009-12-31T18:45Z[UTC]", time1.withDate(base3).toString());
|
|
|
-// assertEquals("1899-12-31T19:12:56Z[UTC]", time1.withDate(base4).toString());
|
|
|
+ assertThrows(DateTimeException.class, () -> time1.withDate(base2));
|
|
|
+ assertThrows(DateTimeException.class, () -> time1.withDate(base3));
|
|
|
+ assertThrows(DateTimeException.class, () -> time1.withDate(base4));
|
|
|
|
|
|
-// assertEquals("1980-01-01T18:45+12:00[Pacific/Funafuti]", time2.withDate(base1).toString());
|
|
|
+ assertThrows(DateTimeException.class, () -> time2.withDate(base1).toString());
|
|
|
assertEquals("1980-01-01T06:45+12:00[Pacific/Funafuti]", time2.withDate(base2).toString());
|
|
|
assertEquals("2010-01-01T06:45+12:00[Pacific/Funafuti]", time2.withDate(base3).toString());
|
|
|
- // @todo difference between JDK 8 & 11: 1900-01-01T06:45+11:32:04[Pacific/Funafuti]
|
|
|
assertEquals("1900-01-01T06:45+11:56:52[Pacific/Funafuti]", time2.withDate(base4).toString());
|
|
|
|
|
|
|
|
|
@@ -85,20 +75,19 @@ public class ZonedTimeTest1 {
|
|
|
ZonedDate date1 = ZonedDate.of(ZonedDateTime.of(2001, 2, 2, 0, 0, 0, 0, PL));
|
|
|
ZonedDate date2 = ZonedDate.of(ZonedDateTime.of(2001, 7, 7, 0, 0, 0, 0, PL));
|
|
|
|
|
|
-// assertEquals("2001-02-02T12:15Z[UTC]", time3.withDate(date1).toString());
|
|
|
-// assertEquals("2001-02-02T12:15Z[UTC]", date1.withTime(time3).toString());
|
|
|
-// assertEquals("2001-07-07T11:15Z[UTC]", time3.withDate(date2).toString());
|
|
|
-// assertEquals("2001-07-07T11:15Z[UTC]", date2.withTime(time3).toString());
|
|
|
+ assertThrows(DateTimeException.class, () -> time3.withDate(date1).toString());
|
|
|
+ assertThrows(DateTimeException.class, () -> date1.withTime(time3).toString());
|
|
|
+ assertThrows(DateTimeException.class, () -> time3.withDate(date2).toString());
|
|
|
+ assertThrows(DateTimeException.class, () -> date2.withTime(time3).toString());
|
|
|
|
|
|
ZonedTime time4 = ZonedTime.of(ZonedDateTime.of(1970, 1, 1, 13, 15, 0, 0, PL));
|
|
|
ZonedDate date3 = ZonedDate.of(ZonedDateTime.of(2001, 7, 7, 0, 0, 0, 0, DateTimeZones.UTC));
|
|
|
ZonedDate date4 = ZonedDate.of(ZonedDateTime.of(2001, 7, 7, 0, 0, 0, 0, DateTimeZones.UTC));
|
|
|
|
|
|
-// assertEquals("2001-07-07T15:15+02:00[Poland]", time4.withDate(date3).toString());
|
|
|
-// assertEquals("2001-07-07T15:15+02:00[Poland]", date3.withTime(time4).toString());
|
|
|
-// assertEquals("2001-07-07T15:15+02:00[Poland]", time4.withDate(date4).toString());
|
|
|
-// assertEquals("2001-07-07T15:15+02:00[Poland]", date4.withTime(time4).toString());
|
|
|
-
|
|
|
+ assertThrows(DateTimeException.class, () -> time4.withDate(date3).toString());
|
|
|
+ assertThrows(DateTimeException.class, () -> date3.withTime(time4).toString());
|
|
|
+ assertThrows(DateTimeException.class, () -> time4.withDate(date4).toString());
|
|
|
+ assertThrows(DateTimeException.class, () -> date4.withTime(time4).toString());
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
@@ -114,46 +103,28 @@ public class ZonedTimeTest1 {
|
|
|
ZonedTime time2 = DateTimeLiteral.time(zone, 6, 45, 0);
|
|
|
|
|
|
assertEquals("1980-01-01T06:45Z[UTC]", time1.withDate(base1).toString());
|
|
|
- assertThrows(DateTimeException.class, () -> {
|
|
|
- time1.withDate(base2).toString();
|
|
|
- });
|
|
|
- assertThrows(DateTimeException.class, () -> {
|
|
|
- time1.withDate(base3).toString();
|
|
|
- });
|
|
|
- assertThrows(DateTimeException.class, () -> {
|
|
|
- time1.withDate(base4).toString();
|
|
|
- });
|
|
|
-
|
|
|
- assertThrows(DateTimeException.class, () -> {
|
|
|
- time2.withDate(base1).toString();
|
|
|
- });
|
|
|
+ assertThrows(DateTimeException.class, () -> time1.withDate(base2).toString());
|
|
|
+ assertThrows(DateTimeException.class, () -> time1.withDate(base3).toString());
|
|
|
+ assertThrows(DateTimeException.class, () -> time1.withDate(base4).toString());
|
|
|
+
|
|
|
+ assertThrows(DateTimeException.class, () -> time2.withDate(base1).toString());
|
|
|
assertEquals("1980-01-01T06:45+12:00[Pacific/Funafuti]", time2.withDate(base2).toString());
|
|
|
assertEquals("1980-01-01T06:45+12:00[Pacific/Funafuti]", base2.withTime(time2).toString());
|
|
|
assertEquals("2010-01-01T06:45+12:00[Pacific/Funafuti]", time2.withDate(base3).toString());
|
|
|
assertEquals("2010-01-01T06:45+12:00[Pacific/Funafuti]", base3.withTime(time2).toString());
|
|
|
|
|
|
- // @todo difference between JDK 8 & 11: 1900-01-01T06:45+11:32:04[Pacific/Funafuti]
|
|
|
assertEquals("1900-01-01T06:45+11:56:52[Pacific/Funafuti]", time2.withDate(base4).toString());
|
|
|
assertEquals("1900-01-01T06:45+11:56:52[Pacific/Funafuti]", base4.withTime(time2).toString());
|
|
|
|
|
|
-
|
|
|
ZonedTime time3 = DateTimeLiteral.timeUtc(13, 15, 0);
|
|
|
ZonedTime time4 = DateTimeLiteral.time(PL, 13, 15, 0);
|
|
|
ZonedDate date1 = DateTimeLiteral.date(PL, 2001, 2, 2);
|
|
|
ZonedDate date2 = DateTimeLiteral.date(PL, 2001, 7, 7);
|
|
|
|
|
|
- assertThrows(DateTimeException.class, () -> {
|
|
|
- time3.withDate(date1).toString();
|
|
|
- });
|
|
|
- assertThrows(DateTimeException.class, () -> {
|
|
|
- time3.withDate(date2).toString();
|
|
|
- });
|
|
|
- assertThrows(DateTimeException.class, () -> {
|
|
|
- date1.withTime(time3).toString();
|
|
|
- });
|
|
|
- assertThrows(DateTimeException.class, () -> {
|
|
|
- date2.withTime(time3).toString();
|
|
|
- });
|
|
|
+ assertThrows(DateTimeException.class, () -> time3.withDate(date1).toString());
|
|
|
+ assertThrows(DateTimeException.class, () -> time3.withDate(date2).toString());
|
|
|
+ assertThrows(DateTimeException.class, () -> date1.withTime(time3).toString());
|
|
|
+ assertThrows(DateTimeException.class, () -> date2.withTime(time3).toString());
|
|
|
|
|
|
assertEquals("2001-02-02T13:15+01:00[Europe/Warsaw]", date1.withTime(time4).toString());
|
|
|
assertEquals("2001-07-07T13:15+02:00[Europe/Warsaw]", date2.withTime(time4).toString());
|