Java Code Examples for java.time.ZonedDateTime#getZone()

The following examples show how to use java.time.ZonedDateTime#getZone() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimeMetadataProvider.java    From recheck with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Map<String, String> retrieve() {
	final Map<String, String> map = new HashMap<>();

	final ZonedDateTime now = ZonedDateTime.now();
	final LocalTime time = now.toLocalTime();
	final LocalDate date = now.toLocalDate();
	final ZoneId zone = now.getZone();
	final ZoneOffset offset = now.getOffset();

	map.put( TIME, time.format( TIME_FORMATTER ) );
	map.put( DATE, date.format( DATE_FORMATTER ) );
	map.put( ZONE, zone.getId() );
	map.put( OFFSET, offset.getId() );

	return map;
}
 
Example 2
Source File: SparseArrayOfZonedDateTimes.java    From morpheus-core with Apache License 2.0 6 votes vote down vote up
@Override
public final boolean isEqualTo(int index, ZonedDateTime value) {
    if (value == null) {
        return isNull(index);
    } else {
        final long epochMills = value.toInstant().toEpochMilli();
        if (epochMills != values.get(index)) {
            return false;
        } else {
            final ZoneId zoneId = value.getZone();
            final short code1 = zoneIdMap1.get(zoneId);
            final short code2 = zoneIds.get(index);
            return code1 == code2;
        }
    }
}
 
Example 3
Source File: MappedArrayOfZonedDateTimes.java    From morpheus-core with Apache License 2.0 6 votes vote down vote up
@Override
public final boolean isEqualTo(int index, ZonedDateTime value) {
    final long epochMillis = byteBuffer.getLong(index * BYTE_COUNT);
    if (value == null) {
        return epochMillis == nullValue;
    } else {
        final long valueAsEpochMills = value.toInstant().toEpochMilli();
        if (epochMillis == valueAsEpochMills) {
            return false;
        } else {
            final ZoneId zoneId = value.getZone();
            final short code1 = zoneIdMap1.get(zoneId);
            final short code2 = byteBuffer.getShort(index * BYTE_COUNT + 8);
            return code1 == code2;
        }
    }
}
 
Example 4
Source File: DenseArrayOfZonedDateTimes.java    From morpheus-core with Apache License 2.0 6 votes vote down vote up
@Override
public final boolean isEqualTo(int index, ZonedDateTime value) {
    if (value == null) {
        return values[index] == nullValue;
    } else {
        final long epochMills = value.toInstant().toEpochMilli();
        if (epochMills != values[index]) {
            return false;
        } else {
            final ZoneId zoneId = value.getZone();
            final short code1 = zoneIdMap1.get(zoneId);
            final short code2 = zoneIds[index];
            return code1 == code2;
        }
    }
}
 
Example 5
Source File: TestAtopSplit.java    From presto with Apache License 2.0 5 votes vote down vote up
@Test
public void testSerialization()
{
    JsonCodec<AtopSplit> codec = JsonCodec.jsonCodec(AtopSplit.class);
    ZonedDateTime now = ZonedDateTime.now(ZoneId.of("+01:23"));
    AtopSplit split = new AtopSplit(HostAddress.fromParts("localhost", 123), now.toEpochSecond(), now.getZone());
    AtopSplit decoded = codec.fromJson(codec.toJson(split));
    assertEquals(decoded.getHost(), split.getHost());
    assertEquals(decoded.getDate(), split.getDate());
    assertEquals(decoded.getEpochSeconds(), split.getEpochSeconds());
    assertEquals(decoded.getTimeZone(), split.getTimeZone());
}
 
Example 6
Source File: ZonedDateTimeHandle.java    From joyrpc with Apache License 2.0 5 votes vote down vote up
@Override
public void wrap(final ZonedDateTime zonedDateTime) {
    this.dateTime = zonedDateTime.toLocalDateTime();
    this.offset = zonedDateTime.getOffset();
    if (zonedDateTime.getZone() != null) {
        this.zoneId = zonedDateTime.getZone().getId();
    }
}
 
Example 7
Source File: ZonedDateTimeSchema.java    From joyrpc with Apache License 2.0 5 votes vote down vote up
@Override
public void writeTo(final Output output, final ZonedDateTime message) throws IOException {
    output.writeObject(1, message.toLocalDateTime(), LocalDateTimeSchema.INSTANCE, false);
    output.writeObject(2, message.getOffset(), ZoneOffsetSchema.INSTANCE, false);
    if (message.getZone() != null) {
        output.writeObject(3, message.getZone(), ZoneIdSchema.INSTANCE, false);
    }
}
 
Example 8
Source File: DateTimeController.java    From Spring-Boot-2-Fundamentals with MIT License 5 votes vote down vote up
@GetMapping("/api/datetime")
public DateTime datetime() {
    ZonedDateTime now = ZonedDateTime.now();
    String date = now.format(DateTimeFormatter.ISO_LOCAL_DATE);
    String time = now.format(DateTimeFormatter.ISO_LOCAL_TIME);
    ZoneId zone = now.getZone();
    ZoneOffset offset = zone.getRules().getOffset(now.toLocalDateTime());
    String zoneString = String.format("%s (%s)",
            zone.getDisplayName(FULL, Locale.UK), zone.getDisplayName(SHORT, Locale.UK));

    return new DateTime(date, time, zoneString, zone.getId(), offset.getId());
}
 
Example 9
Source File: DateTimeParserContext.java    From jphp with Apache License 2.0 5 votes vote down vote up
DateTimeParserContext(List<DateTimeTokenizer.Token> tokens, Cursor cursor, DateTimeTokenizer tokenizer,
                      ZonedDateTime dateTime) {
    this.tokens = tokens;
    this.cursor = cursor;
    this.tokenizer = tokenizer;
    this.modified = new HashSet<>();
    this.dateTime = dateTime.toLocalDateTime();
    this.zoneId = dateTime.getZone();
}
 
Example 10
Source File: ZoneIdFactory.java    From jphp with Apache License 2.0 5 votes vote down vote up
public static String aliasFor(ZonedDateTime dateTime) {
    String id = dateTime.getZone().getId();
    switch (id) {
        case "GMT":
        case "UTC":
            return id;
    }

    List<TimezoneWithAlias> aliases = idToAliases.get(id);
    if (aliases == null) {
        return null;
    }

    ZoneId zone = dateTime.getZone();
    ZoneRules rules = zone.getRules();
    boolean dst = zone.getRules().isDaylightSavings(dateTime.toInstant());
    ZoneOffset zoneOffset = rules.getOffset(dateTime.toInstant());

    int offset = zoneOffset.getTotalSeconds();

    for (TimezoneWithAlias alias : aliases) {
        if (alias.timezone.getOffset() == offset && alias.timezone.isDst() == dst) {
            return alias.alias.toUpperCase();
        }
    }

    return null;
}
 
Example 11
Source File: ReportService.java    From vind with Apache License 2.0 4 votes vote down vote up
public ReportService(ReportConfiguration configuration, ZonedDateTime from, ZonedDateTime to){
    this.from = from;
    this.to = to;
    this.zoneId = from.getZone();
    this.configuration = configuration;
}
 
Example 12
Source File: PersistentZonedDateTimeAsStringAndStringZone.java    From jadira with Apache License 2.0 4 votes vote down vote up
@Override
protected Object[] toConvertedColumns(ZonedDateTime value) {

    return new Object[] { value.toLocalDateTime(), value.getZone() };
}