static ZoneOffset parseOffset( Matcher matcher ) { String zone = matcher.group( "zone" ); if ( null == zone ) { return null; } if ( "Z".equalsIgnoreCase( zone ) ) { return UTC; } int factor = zone.charAt( 0 ) == '+' ? 1 : -1; int hours = parseInt( matcher.group( "zoneHour" ) ); int minutes = optInt( matcher.group( "zoneMinute" ) ); return assertValidZone( () -> ZoneOffset.ofHoursMinutes( factor * hours, factor * minutes ) ); }
@Test void shouldTruncateOffsetSeconds() { OffsetTime time = OffsetTime.of( 14, 55, 50, 0, ZoneOffset.ofHoursMinutesSeconds( 2, 15, 45 ) ); OffsetTime truncatedTime = TemporalUtil.truncateOffsetToMinutes( time ); assertEquals( OffsetTime.of( 14, 55, 5, 0, ZoneOffset.ofHoursMinutes( 2, 15 ) ), truncatedTime ); }
@Test public void shouldSendDateTimeWithTimeZoneOffset() throws Exception { testSendingOfBoltV2Value( datetime( 424242, 0, ZoneOffset.ofHoursMinutes( -7, -15 ) ) ); }
@Test public void shouldSendAndReceiveDateTimeWithTimeZoneOffset() throws Exception { testSendingAndReceivingOfBoltV2Value( datetime( 1899, 1, 1, 12, 12, 32, 0, ZoneOffset.ofHoursMinutes( -4, -15 ) ) ); }
@Test public void shouldReceiveDateTimeWithTimeZoneOffset() throws Exception { testReceivingOfBoltV2Value( "RETURN datetime({year:2022, month:3, day:2, hour:19, minute:10, timezone:'+02:30'})", datetime( 2022, 3, 2, 19, 10, 0, 0, ZoneOffset.ofHoursMinutes( 2, 30 ) ) ); }
@Test public void shouldPackLocalDateTimeWithTimeZoneOffset() { LocalDateTime localDateTime = LocalDateTime.of( 2015, 3, 23, 19, 15, 59, 10 ); ZoneOffset offset = ZoneOffset.ofHoursMinutes( -5, -15 ); ZonedDateTime zonedDateTime = ZonedDateTime.of( localDateTime, offset ); PackedOutputArray packedOutput = pack( datetime( zonedDateTime ) ); ByteBuffer buffer = ByteBuffer.wrap( packedOutput.bytes() ); buffer.getShort(); // skip struct header assertEquals( INT_32, buffer.get() ); assertEquals( localDateTime.toEpochSecond( UTC ), buffer.getInt() ); assertEquals( localDateTime.getNano(), buffer.get() ); assertEquals( INT_16, buffer.get() ); assertEquals( offset.getTotalSeconds(), buffer.getShort() ); }
@Test void shouldDoNothingForOffsetWithoutSeconds() { OffsetTime time = OffsetTime.of( 23, 30, 10, 0, ZoneOffset.ofHoursMinutes( -5, -30 ) ); OffsetTime truncatedTime = TemporalUtil.truncateOffsetToMinutes( time ); assertEquals( time, truncatedTime ); }
@Test void shouldHandleDateTimeWithTimeZoneOffset() { DateTimeValue datetime = datetime( 1988, 4, 19, 10, 12, 59, 112233445, ZoneOffset.ofHoursMinutes( 3, 15 ) ); PrettyPrinter printer = new PrettyPrinter(); datetime.writeTo( printer ); assertEquals( "{datetime: \"1988-04-19T10:12:59.112233445+03:15\"}", printer.value() ); }
@Test void shouldHandleTime() { TimeValue time = time( 11, 19, 11, 123456789, ZoneOffset.ofHoursMinutes( -9, -30 ) ); PrettyPrinter printer = new PrettyPrinter(); time.writeTo( printer ); assertEquals( "{time: \"11:19:11.123456789-09:30\"}", printer.value() ); }
private static ZoneOffset extractOffset(byte[] bytes) { int hours = bytes[11] - 20; int minutes = bytes[12] - 60; if (hours == 0 && minutes == 0) { return ZoneOffset.UTC; } return ZoneOffset.ofHoursMinutes(hours, minutes); }
private static ZoneOffset extractOffset(byte[] bytes) { int hours = bytes[11] - 20; int minutes = bytes[12] - 60; if (hours == 0 && minutes == 0) { return ZoneOffset.UTC; } return ZoneOffset.ofHoursMinutes(hours, minutes); }
public static List<String> getRegionNamesForOffset(int hours, int minutes) { ZoneOffset offset = ZoneOffset.ofHoursMinutes(hours, minutes); return getRegionNamesForOffset(offset); } }
@Test void offsetShouldBeParsed() { ZonedDateTime dateTime = ZonedDateTime.parse("3 Jun 2017 04:35:11 -0712", ImapDateTimeFormatter.rfc5322()); assertThat(dateTime.getOffset()).isEqualTo(ZoneOffset.ofHoursMinutes(-7, -12)); }
@Test public void offsetShouldBeParsed() { ZonedDateTime dateTime = ZonedDateTime.parse("3 Jun 2017 04:35:11 -0712", ImapDateTimeFormatter.rfc5322()); assertThat(dateTime.getOffset()).isEqualTo(ZoneOffset.ofHoursMinutes(-7, -12)); }
@Test public void itConvertsStringToTime() { String datetime = "2018-07-14T14:31:30+0530"; String format = "yyyy-MM-dd'T'HH:mm:ssZ"; PyishDate expected = new PyishDate(ZonedDateTime.of(2018, 7, 14, 14, 31, 30, 0, ZoneOffset.ofHoursMinutes(5, 30))); assertThat(Functions.stringToTime(datetime, format)).isEqualTo(expected); }
@Test public void itConvertsStringToTime() { String datetime = "2018-07-14T14:31:30+0530"; String format = "yyyy-MM-dd'T'HH:mm:ssZ"; PyishDate expected = new PyishDate(ZonedDateTime.of(2018, 7, 14, 14, 31, 30, 0, ZoneOffset.ofHoursMinutes(5, 30))); assertThat(Functions.stringToTime(datetime, format)).isEqualTo(expected); }
@Test(expected = InterpretException.class) public void itFailsOnInvalidFormat() { String datetime = "2018-07-14T14:31:30+0530"; String format = "not a time format"; PyishDate expected = new PyishDate(ZonedDateTime.of(2018, 7, 14, 14, 31, 30, 0, ZoneOffset.ofHoursMinutes(5, 30))); assertThat(Functions.stringToTime(datetime, format)).isEqualTo(expected); }
@Test(expected = InterpretException.class) public void itFailsOnInvalidFormat() { String datetime = "2018-07-14T14:31:30+0530"; String format = "not a time format"; PyishDate expected = new PyishDate(ZonedDateTime.of(2018, 7, 14, 14, 31, 30, 0, ZoneOffset.ofHoursMinutes(5, 30))); assertThat(Functions.stringToTime(datetime, format)).isEqualTo(expected); }
@Test(expected = InterpretException.class) public void itFailsOnTimeFormatMismatch() { String datetime = "Saturday, Jul 14, 2018 14:31:06 PM"; String format = "yyyy-MM-dd'T'HH:mm:ssZ"; PyishDate expected = new PyishDate(ZonedDateTime.of(2018, 7, 14, 14, 31, 30, 0, ZoneOffset.ofHoursMinutes(5, 30))); assertThat(Functions.stringToTime(datetime, format)).isEqualTo(expected); }
@Test(expected = InterpretException.class) public void itFailsOnTimeFormatMismatch() { String datetime = "Saturday, Jul 14, 2018 14:31:06 PM"; String format = "yyyy-MM-dd'T'HH:mm:ssZ"; PyishDate expected = new PyishDate(ZonedDateTime.of(2018, 7, 14, 14, 31, 30, 0, ZoneOffset.ofHoursMinutes(5, 30))); assertThat(Functions.stringToTime(datetime, format)).isEqualTo(expected); }