List of usage examples for java.time ZoneId of
public static ZoneId of(String zoneId)
From source file:com.intuit.wasabi.api.pagination.filters.FilterUtil.java
/** * Converts the old {@link Date} to a new {@link OffsetDateTime}, taking the UTC offset into account. * * @param date the date to convert/*from ww w .j a va2 s. c o m*/ * @return the converted date */ public static OffsetDateTime convertDateToOffsetDateTime(Date date) { return OffsetDateTime.ofInstant(date.toInstant(), ZoneId.of("UTC")); }
From source file:ac.simons.tweetarchive.tweets.TweetStorageService.java
@Transactional public TweetEntity store(final Status status, final String rawContent) { final Optional<TweetEntity> existingTweet = this.tweetRepository.findOne(status.getId()); if (existingTweet.isPresent()) { final TweetEntity rv = existingTweet.get(); log.warn("Tweet with status {} already existed...", rv.getId()); return rv; }/*from www.ja v a2 s.c om*/ final TweetEntity tweet = new TweetEntity(status.getId(), status.getUser().getId(), status.getUser().getScreenName(), status.getCreatedAt().toInstant().atZone(ZoneId.of("UTC")), extractContent(status), extractSource(status), rawContent); tweet.setCountryCode(Optional.ofNullable(status.getPlace()).map(Place::getCountryCode).orElse(null)); if (status.getInReplyToStatusId() != -1L && status.getInReplyToUserId() != -1L && status.getInReplyToScreenName() != null) { tweet.setInReplyTo(new InReplyTo(status.getInReplyToStatusId(), status.getInReplyToScreenName(), status.getInReplyToUserId())); } tweet.setLang(status.getLang()); tweet.setLocation(Optional.ofNullable(status.getGeoLocation()) .map(g -> new TweetEntity.Location(g.getLatitude(), g.getLongitude())).orElse(null)); // TODO Handle quoted tweets return this.tweetRepository.save(tweet); }
From source file:sh.scrap.scrapper.functions.DateFunctionFactory.java
@Override public DataScrapperFunction create(String name, DataScrapperFunctionLibrary library, String pattern, Map<String, Object> annotations) { return context -> subscription -> { Locale locale = parseLocale(annotations.getOrDefault("locale", EN_US)); ZoneId zoneId = ZoneId.of((String) annotations.getOrDefault("timezone", "UTC")); Locale finalLocale = locale; subscription.onSubscribe(new Subscription() { @Override/*from w w w . ja v a 2 s .c o m*/ public void request(long n) { String data = context.data().toString(); ZonedDateTime parsed; context.objectProcessed(data); try { switch (name) { case "parse": parsed = parse(data, pattern, finalLocale, zoneId); context.objectProcessed(parsed); subscription.onNext(context.withData(format(parsed, ISO8601, EN_US, ZoneId.of("UTC")))); subscription.onComplete(); return; case "format": parsed = parse(data, ISO8601, EN_US, ZoneId.of("UTC")); context.objectProcessed(parsed); subscription.onNext(context.withData(format(parsed, pattern, finalLocale, zoneId))); subscription.onComplete(); return; } } catch (DateTimeParseException e) { subscription.onError(e); subscription.onComplete(); return; } } @Override public void cancel() { } }); }; }
From source file:de.rkl.tools.tzconv.model.ApplicationModel.java
private static SetMultimap<ZoneOffset, ZoneId> sortAvailableZoneIds() { final SortedSetMultimap<ZoneOffset, ZoneId> zoneIdMap = TreeMultimap.create(Ordering.natural().reverse(), new Ordering<ZoneId>() { @Override/*w w w.j a v a 2 s . c om*/ public int compare(final ZoneId zoneId1, final ZoneId zoneId2) { return ComparisonChain.start().compare(zoneId1.toString(), zoneId2.toString()).result(); } }.nullsFirst()); ZoneId.getAvailableZoneIds().stream().forEach(zoneId -> { final ZoneId zoneIdObject = ZoneId.of(zoneId); zoneIdMap.put(zoneIdObject.getRules().getStandardOffset(Instant.now()), zoneIdObject); }); return ImmutableSetMultimap.copyOf(zoneIdMap); }
From source file:org.sakaiproject.commons.api.datamodel.Comment.java
public Comment(ResultSet rs) throws SQLException { this.setId(rs.getString("ID")); this.setPostId(rs.getString("POST_ID")); this.setContent(rs.getString("CONTENT")); this.setCreatorId(rs.getString("CREATOR_ID")); // retrieve time's in UTC since that's how it's stored this.setCreatedDate( rs.getTimestamp("CREATED_DATE", Calendar.getInstance(TimeZone.getTimeZone(ZoneId.of("UTC")))) .getTime());// w w w . j a v a2s . c o m this.setModifiedDate( rs.getTimestamp("MODIFIED_DATE", Calendar.getInstance(TimeZone.getTimeZone(ZoneId.of("UTC")))) .getTime()); }
From source file:daylightchart.daylightchart.calculation.RiseSetUtility.java
/** * Calculator for sunrise and sunset times for a year. * * @param location//from w w w .j a va 2 s. c om * Location * @param year * Year * @param options * Options * @return Full years sunset and sunrise times for a location */ public static RiseSetYearData createRiseSetYear(final Location location, final int year, final Options options) { final TimeZoneOption timeZoneOption = options.getTimeZoneOption(); final ZoneId zoneId; if (location != null) { final String timeZoneId; if (timeZoneOption != null && timeZoneOption == TimeZoneOption.USE_TIME_ZONE) { timeZoneId = location.getTimeZoneId(); } else { timeZoneId = DefaultTimezones.createGMTTimeZoneId(location.getPointLocation().getLongitude()); } zoneId = ZoneId.of(timeZoneId); } else { zoneId = ZoneId.systemDefault(); } final boolean timeZoneUsesDaylightTime = !zoneId.getRules().getTransitionRules().isEmpty(); final boolean useDaylightTime = timeZoneUsesDaylightTime && timeZoneOption != TimeZoneOption.USE_LOCAL_TIME; boolean wasDaylightSavings = false; final TwilightType twilight = options.getTwilightType(); final RiseSetYearData riseSetYear = new RiseSetYearData(location, twilight, year); riseSetYear.setUsesDaylightTime(useDaylightTime); for (final LocalDate date : getYearsDates(year)) { final boolean inDaylightSavings = zoneId.getRules() .isDaylightSavings(date.atStartOfDay().atZone(zoneId).toInstant()); if (wasDaylightSavings != inDaylightSavings) { if (!wasDaylightSavings) { riseSetYear.setDstStart(date); } else { riseSetYear.setDstEnd(date); } } wasDaylightSavings = inDaylightSavings; final RawRiseSet riseSet = calculateRiseSet(location, date, useDaylightTime, inDaylightSavings, TwilightType.NO); riseSetYear.addRiseSet(riseSet); if (twilight != null) { final RawRiseSet twilights = calculateRiseSet(location, date, useDaylightTime, inDaylightSavings, twilight); riseSetYear.addTwilight(twilights); } } // Create band for twilight, clock-shift taken into account createBands(riseSetYear, DaylightBandType.twilight); // Create band, clock-shift taken into account createBands(riseSetYear, DaylightBandType.with_clock_shift); // Create band, without clock shift createBands(riseSetYear, DaylightBandType.without_clock_shift); return riseSetYear; }
From source file:io.stallion.jobs.Schedule.java
/** * Gets the next datetime matching the schedule, in the Users timezone * * @return/* w w w . j a v a 2 s . co m*/ */ public ZonedDateTime nextAt() { ZoneId zoneId = null; if (!StringUtils.isEmpty(timeZoneId)) { zoneId = ZoneId.of(timeZoneId); } else if (timeZoneForUserId != null) { IUser user = UserController.instance().forId(timeZoneForUserId); if (user != null && !StringUtils.isEmpty(user.getTimeZoneId())) { zoneId = ZoneId.of(user.getTimeZoneId()); } } if (zoneId == null) { zoneId = ZoneId.of("UTC"); } ZonedDateTime dt = ZonedDateTime.now(zoneId); return nextAt(dt); }
From source file:org.apache.james.mailbox.elasticsearch.json.IndexableMessageTest.java
@Test public void textShouldBeEmptyWhenNoMatchingHeaders() throws Exception { MailboxMessage mailboxMessage = mock(MailboxMessage.class); TestId mailboxId = TestId.of(1);/* w ww.j a v a2 s .com*/ when(mailboxMessage.getMailboxId()).thenReturn(mailboxId); when(mailboxMessage.getFullContent()).thenReturn(new ByteArrayInputStream("".getBytes())); when(mailboxMessage.createFlags()).thenReturn(new Flags()); IndexableMessage indexableMessage = IndexableMessage.from(mailboxMessage, ImmutableList.of(new MockMailboxSession("username").getUser()), new DefaultTextExtractor(), ZoneId.of("Europe/Paris")); assertThat(indexableMessage.getText()).isEmpty(); }
From source file:com.github.ibm.domino.client.DominoRestClient.java
public DominoRestClient since(ZonedDateTime value) { parameters.put("since", getDateParameter(value.withZoneSameInstant(ZoneId.of("GMT")))); return this; }
From source file:ch.digitalfondue.npjt.query.DateTimeQueriesTest.java
@Test public void dateQueriesTest() { QueryFactory qf = new QueryFactory("hsqldb", new JdbcTemplate(dataSource)); qf.addColumnMapperFactory(new ZonedDateTimeMapper.Factory()); qf.addParameterConverters(new ZonedDateTimeMapper.Converter()); qf.addColumnMapperFactory(new LocalDateMapper.Factory()); qf.addParameterConverters(new LocalDateMapper.Converter()); qf.addColumnMapperFactory(new LocalDateTimeMapper.Factory()); qf.addParameterConverters(new LocalDateTimeMapper.Converter()); qf.addColumnMapperFactory(new InstantMapper.Factory()); qf.addParameterConverters(new InstantMapper.Converter()); DateQueries dq = qf.from(DateQueries.class); dq.createTable();/*from w ww . ja v a 2 s . c om*/ ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC")); dq.insertValue("KEY", now); check(dq, "KEY", now); dq.insertValue("KEY2", now.toLocalDate()); check(dq, "KEY2", now.toLocalDate()); dq.insertValue("KEY3", now.toLocalDateTime()); check(dq, "KEY3", now); Instant iNow = Instant.now(); dq.insertValue("KEY4", iNow); Assert.assertEquals(iNow, dq.findInstantByKey("KEY4")); Assert.assertEquals(iNow, dq.findConfInstantByKey("KEY4").value); }