Refactoring of time handling objects #572
Conversation
|
this alters the jvm state as setDefault for TimeZone will change the state globally and modifying global state in a test case is a no-go. please see https://docs.oracle.com/javase/8/docs/api/java/util/TimeZone.html#getDefault-- |
|
I wonder if it would be better to add an additional ctor to |
|
Will refactor to have a constructor with a timezone and otherwise use system default timezone |
eemhu
left a comment
There was a problem hiding this comment.
Changes look good to me, but should the DefaultTimeFormatTest and DPLTimeFormatTest also be changed to use the new ctor?
|
yea I will update the other tests also |
|
Made #573 for other test cases still using |
|
Noted that If the value for example Meaning that if timestamp has valid zone info it will overwrite timezone set by |
|
Some DPL tests have time value with lower case This happens only if the default absolute timestamp formats are used to parse the value. Fix?
|
743fff7 to
cbd07aa
Compare
|
rebased |
|
Refactoring time relative objects |
a2a1884 to
7c00fc5
Compare
|
rebased |
|
Refactored relative time objects |
| private long offsetAmount() { | ||
| final String validAmountString = new ValidOffsetAmountText(offsetText).read(); | ||
| return Long.parseLong(validAmountString); | ||
| } | ||
|
|
||
| private OffsetUnit offsetUnit() { | ||
| final String validUnitString = new ValidOffsetUnitText(offsetText).read(); |
There was a problem hiding this comment.
maybe these two should be their own objects?
| List<String> expectedResults = Collections | ||
| .singletonList( | ||
| "978303661" // +0300 timezone | ||
| "978310861" // +0300 timezone |
There was a problem hiding this comment.
Tests default timezone changed to UTC I updated the comment
| } | ||
|
|
||
| @Test | ||
| public void testUserDefinedFormat() { |
There was a problem hiding this comment.
test invalid user defined format also
There was a problem hiding this comment.
added invalid input test
| // Assert equals with expected | ||
| Assertions.assertEquals(1644487237L, lstA.get(0).getLong(0)); | ||
| Assertions.assertEquals(1645048800L, lstB.get(0).getLong(0)); | ||
| Assertions.assertEquals(1645056000L, lstB.get(0).getLong(0)); |
| Instant now = timestamp.toInstant().plus(-3, ChronoUnit.HOURS); | ||
|
|
||
| String expected = String.valueOf(now.getEpochSecond()).substring(0, 7); // don't check the seconds within a minute, as the query takes some time and might be a few seconds off | ||
| long latestEpoch = ZonedDateTime.now(utcZone).minusHours(3).toEpochSecond(); |
There was a problem hiding this comment.
should be able to define startTime now so no substring trickery needed
There was a problem hiding this comment.
Cleaned up the relativeTimeTest all tests now directly assert the expected epochs against the actualy epochs in the query
8857d24 to
9764a82
Compare
|
Rebased |
… missing package renaming
…d of find() to force matching from start of string
…rt time to dpl context used by relative timestamps
…mes and add equals + hashcode + contract tests where missing
…rserConfig, update tests to set query start time before earliest
…is no user defined provided + cleanup and fixes from review
…e assertions to DPLTimeFormatString and to DPLFormat implementing classes.
…use system default timezone, add zone id to Relative_time UDF
…nused object DPLTimeFormat and test
… now. update time stamps tests to use UTC and set query start time
9764a82 to
a0d9d47
Compare
Refactor the responsibilities of time handling objects
Parsing of incoming pure string values
Introduces new way of parsing and handling timestamps.
Incoming pure string values of timestamp and time format are handled by the
DPLTimestampStringobject that accepts the value, accepted parsing formats and the base time, user can provide own timeformat in other case a set list of default time formats is used. Parsing result is accepted only if a single value is matched against the provided formats.DPLTimestampStringhasasDPLTimestampmethod that produces aDPLTimestampinterface that represents the parsed timestamp, if no acceptable parsing result was found the result will be a stub object.DPL timestamp interface to represent a parsed timestamp
DPLTimestampinterface has a method to produces a Java'sZonedDateTimeobject for the timestamp that can be used to calculate epoch seconds and various other time values for the timestampDPLTimestampimplementing classesAbsoluteTimestampis responsible for handling dates eg.2020-01-01.RelativeTimestampcalculates relative values e.g.-1daythat are calculated from the provided base time.Test cases are updated to use UTC without reliance on system default and changing of JVM default timezone.