/** * Converts a {@code TimeZone} to a {@code ZoneId}. * * @param timeZone the time-zone, not null * @return the zone, not null */ public static ZoneId toZoneId(TimeZone timeZone) { return ZoneId.of(timeZone.getID(), ZoneId.SHORT_IDS); }
/** * Converts a {@code TimeZone} to a {@code ZoneId}. * * @param timeZone the time-zone, not null * @return the zone, not null */ public static ZoneId toZoneId(TimeZone timeZone) { return ZoneId.of(timeZone.getID(), ZoneId.SHORT_IDS); }
@Nonnull @Override public ZoneId convert(String source) { return ZoneId.of(source); } }
private ZoneId convertToZone(Set<String> regionIds, String parsedZoneId, boolean caseSensitive) { if (parsedZoneId == null) { return null; } if (caseSensitive) { return (regionIds.contains(parsedZoneId) ? ZoneId.of(parsedZoneId) : null); } else { for (String regionId : regionIds) { if (regionId.equalsIgnoreCase(parsedZoneId)) { return ZoneId.of(regionId); } } return null; } }
private ZoneId convertToZone(Set<String> regionIds, String parsedZoneId, boolean caseSensitive) { if (parsedZoneId == null) { return null; } if (caseSensitive) { return (regionIds.contains(parsedZoneId) ? ZoneId.of(parsedZoneId) : null); } else { for (String regionId : regionIds) { if (regionId.equalsIgnoreCase(parsedZoneId)) { return ZoneId.of(regionId); } } return null; } }
/** * Gets the system default time-zone. * <p> * This queries {@link TimeZone#getDefault()} to find the default time-zone * and converts it to a {@code ZoneId}. If the system default time-zone is changed, * then the result of this method will also change. * * @return the zone ID, not null * @throws DateTimeException if the converted zone ID has an invalid format * @throws ZoneRulesException if the converted zone region ID cannot be found */ public static ZoneId systemDefault() { return ZoneId.of(TimeZone.getDefault().getID(), SHORT_IDS); }
/** * Gets the system default time-zone. * <p> * This queries {@link TimeZone#getDefault()} to find the default time-zone * and converts it to a {@code ZoneId}. If the system default time-zone is changed, * then the result of this method will also change. * * @return the zone ID, not null * @throws DateTimeException if the converted zone ID has an invalid format * @throws ZoneRulesException if the converted zone region ID cannot be found */ public static ZoneId systemDefault() { return ZoneId.of(TimeZone.getDefault().getID(), SHORT_IDS); }
@Override protected Object deserialize(String key, DeserializationContext ctxt) throws IOException { try { return ZoneId.of(key); } catch (DateTimeException e) { return _rethrowDateTimeException(ctxt, ZoneId.class, e, key); } } }
/** * Obtains an instance of {@code ZoneId} using its ID using a map * of aliases to supplement the standard zone IDs. * <p> * Many users of time-zones use short abbreviations, such as PST for * 'Pacific Standard Time' and PDT for 'Pacific Daylight Time'. * These abbreviations are not unique, and so cannot be used as IDs. * This method allows a map of string to time-zone to be setup and reused * within an application. * * @param zoneId the time-zone ID, not null * @param aliasMap a map of alias zone IDs (typically abbreviations) to real zone IDs, not null * @return the zone ID, not null * @throws DateTimeException if the zone ID has an invalid format * @throws ZoneRulesException if the zone ID is a region ID that cannot be found */ public static ZoneId of(String zoneId, Map<String, String> aliasMap) { Jdk8Methods.requireNonNull(zoneId, "zoneId"); Jdk8Methods.requireNonNull(aliasMap, "aliasMap"); String id = aliasMap.get(zoneId); id = (id != null ? id : zoneId); return of(id); }
@Override public int parse(DateTimeParseContext context, CharSequence text, int position) { // this is a poor implementation that handles some but not all of the spec // JDK8 has a lot of extra information here Map<String, String> ids = new TreeMap<String, String>(LENGTH_COMPARATOR); for (String id : ZoneId.getAvailableZoneIds()) { ids.put(id, id); TimeZone tz = TimeZone.getTimeZone(id); int tzstyle = (textStyle.asNormal() == TextStyle.FULL ? TimeZone.LONG : TimeZone.SHORT); String textWinter = tz.getDisplayName(false, tzstyle, context.getLocale()); if (id.startsWith("Etc/") || (!textWinter.startsWith("GMT+") && !textWinter.startsWith("GMT+"))) { ids.put(textWinter, id); } String textSummer = tz.getDisplayName(true, tzstyle, context.getLocale()); if (id.startsWith("Etc/") || (!textSummer.startsWith("GMT+") && !textSummer.startsWith("GMT+"))) { ids.put(textSummer, id); } } for (Entry<String, String> entry : ids.entrySet()) { String name = entry.getKey(); if (context.subSequenceEquals(text, position, name, 0, name.length())) { context.setParsed(ZoneId.of(entry.getValue())); return position + name.length(); } } return ~position; }
@Override public int parse(DateTimeParseContext context, CharSequence text, int position) { // this is a poor implementation that handles some but not all of the spec // JDK8 has a lot of extra information here Map<String, String> ids = new TreeMap<String, String>(LENGTH_COMPARATOR); for (String id : ZoneId.getAvailableZoneIds()) { ids.put(id, id); TimeZone tz = TimeZone.getTimeZone(id); int tzstyle = (textStyle.asNormal() == TextStyle.FULL ? TimeZone.LONG : TimeZone.SHORT); String textWinter = tz.getDisplayName(false, tzstyle, context.getLocale()); if (id.startsWith("Etc/") || (!textWinter.startsWith("GMT+") && !textWinter.startsWith("GMT+"))) { ids.put(textWinter, id); } String textSummer = tz.getDisplayName(true, tzstyle, context.getLocale()); if (id.startsWith("Etc/") || (!textSummer.startsWith("GMT+") && !textSummer.startsWith("GMT+"))) { ids.put(textSummer, id); } } for (Entry<String, String> entry : ids.entrySet()) { String name = entry.getKey(); if (context.subSequenceEquals(text, position, name, 0, name.length())) { context.setParsed(ZoneId.of(entry.getValue())); return position + name.length(); } } return ~position; }
/** * Obtains an instance of {@code ZoneId} using its ID using a map * of aliases to supplement the standard zone IDs. * <p> * Many users of time-zones use short abbreviations, such as PST for * 'Pacific Standard Time' and PDT for 'Pacific Daylight Time'. * These abbreviations are not unique, and so cannot be used as IDs. * This method allows a map of string to time-zone to be setup and reused * within an application. * * @param zoneId the time-zone ID, not null * @param aliasMap a map of alias zone IDs (typically abbreviations) to real zone IDs, not null * @return the zone ID, not null * @throws DateTimeException if the zone ID has an invalid format * @throws ZoneRulesException if the zone ID is a region ID that cannot be found */ public static ZoneId of(String zoneId, Map<String, String> aliasMap) { Jdk8Methods.requireNonNull(zoneId, "zoneId"); Jdk8Methods.requireNonNull(aliasMap, "aliasMap"); String id = aliasMap.get(zoneId); id = (id != null ? id : zoneId); return of(id); }
@Override public List<SlackMessagePosted> fetchHistoryOfChannel(String channelId, LocalDate day, int numberOfMessages, Set<String> allowedSubtypes) { Map<String, String> params = new HashMap<>(); params.put("channel", channelId); if (day != null) { ZonedDateTime start = ZonedDateTime.of(day.atStartOfDay(), ZoneId.of("UTC")); ZonedDateTime end = ZonedDateTime.of(day.atStartOfDay().plusDays(1).minus(1, ChronoUnit.MILLIS), ZoneId.of("UTC")); params.put("oldest", convertDateToSlackTimestamp(start)); params.put("latest", convertDateToSlackTimestamp(end)); } if (numberOfMessages > -1) { params.put("count", String.valueOf(numberOfMessages)); } else { params.put("count", String.valueOf(DEFAULT_HISTORY_FETCH_SIZE)); } SlackChannel channel = session.findChannelById(channelId); switch (channel.getType()) { case INSTANT_MESSAGING: return fetchHistoryOfChannel(params,FETCH_IM_HISTORY_COMMAND, allowedSubtypes); case PRIVATE_GROUP: return fetchHistoryOfChannel(params,FETCH_GROUP_HISTORY_COMMAND, allowedSubtypes); default: return fetchHistoryOfChannel(params,FETCH_CHANNEL_HISTORY_COMMAND, allowedSubtypes); } }
private static VTimeZone generateTimezoneForId(String timezoneId) throws ParseException { if(!TIMEZONE_DEFINITIONS.contains(timezoneId)){ return null; } java.util.TimeZone javaTz = java.util.TimeZone.getTimeZone(timezoneId); ZoneId zoneId = ZoneId.of(javaTz.getID(), ZoneId.SHORT_IDS); int rawTimeZoneOffsetInSeconds = javaTz.getRawOffset() / 1000; VTimeZone timezone = new VTimeZone(); timezone.getProperties().add(new TzId(timezoneId)); addTransitions(zoneId, timezone, rawTimeZoneOffsetInSeconds); addTransitionRules(zoneId, rawTimeZoneOffsetInSeconds, timezone); if(timezone.getObservances() == null || timezone.getObservances().isEmpty()){ timezone.getObservances().add(NO_TRANSITIONS); } return timezone; }
@Override public Object deserialize(JsonParser parser, DeserializationContext context) throws IOException { if (parser.hasToken(JsonToken.VALUE_STRING)) { String string = parser.getText().trim(); if (string.length() == 0) { return null; } try { switch (_valueType) { case TYPE_PERIOD: return Period.parse(string); case TYPE_ZONE_ID: return ZoneId.of(string); case TYPE_ZONE_OFFSET: return ZoneOffset.of(string); } } catch (DateTimeException e) { _rethrowDateTimeException(parser, context, e, string); } } if (parser.hasToken(JsonToken.VALUE_EMBEDDED_OBJECT)) { // 20-Apr-2016, tatu: Related to [databind#1208], can try supporting embedded // values quite easily return parser.getEmbeddedObject(); } throw context.wrongTokenException(parser, JsonToken.VALUE_STRING, null); }