Skip to content

Commit

Permalink
Adding a test to verify parsing of the timestamp example used in Time…
Browse files Browse the repository at this point in the history
…seriesController and basically every Controller.
  • Loading branch information
rma-rripken committed Jul 23, 2024
1 parent bfa9bfd commit aed7fc7
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions cwms-data-api/src/test/java/cwms/cda/helpers/DateUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import cwms.cda.api.Controllers;
import cwms.cda.data.dto.TimeSeries;
import java.time.DateTimeException;
import java.time.Instant;
Expand Down Expand Up @@ -122,4 +124,23 @@ void test_PT_doesnt_care_about_zone(){
assertEquals(ptZdt.toInstant(), ptChZdt.toInstant(), "PT-24H should be the same in any zone");
}

@Test
void test_controllers_example_date(){
ZonedDateTime zdt = DateUtils.parseUserDate(Controllers.EXAMPLE_DATE, "UTC");
assertNotNull(zdt);
Instant expected = ZonedDateTime.of(2021,6,10,13,0,0,0,
ZoneId.of("PST8PDT")).toInstant();
assertEquals(expected, zdt.toInstant());
}

@Test
void test_DateTimeFormatter_iso_zoned_example(){
String isoExample = "2011-12-03T10:15:30+01:00[Europe/Paris]"; // Example from java.time.format.DateTimeFormatter javadoc.
ZonedDateTime zdt = DateUtils.parseUserDate(isoExample, "UTC");
assertNotNull(zdt);
Instant expected = ZonedDateTime.of(2011,12,3,10,15,30,0,
ZoneId.of("Europe/Paris")).toInstant();
assertEquals(expected, zdt.toInstant());
}

}

0 comments on commit aed7fc7

Please sign in to comment.