List of usage examples for java.time ZoneOffset of
@SuppressWarnings("fallthrough") public static ZoneOffset of(String offsetId)
From source file:Main.java
public static void main(String[] args) { ZoneOffset offset = ZoneOffset.of("+2:00"); System.out.println(offset); }
From source file:Main.java
public static void main(String[] args) { // using offsets LocalDateTime date = LocalDateTime.of(2013, Month.JULY, 20, 3, 30); ZoneOffset offset = ZoneOffset.of("+05:00"); // 2013-07-20 22:30 +05:00 OffsetDateTime plusFive = OffsetDateTime.of(date, offset); System.out.println(plusFive); // 2013-07-19 20:30 -02:00 OffsetDateTime minusTwo = plusFive.withOffsetSameInstant(ZoneOffset.ofHours(-2)); System.out.println(minusTwo); }
From source file:Main.java
public static void main(String[] argv) { ZoneId INDIA = ZoneId.of("Asia/Kolkata"); LocalDateTime datetime = LocalDateTime.now(); ZoneOffset offset = ZoneOffset.of("+05:30"); OffsetDateTime date = OffsetDateTime.of(datetime, offset); System.out.println("OffsetDateTime.now() = " + OffsetDateTime.now()); System.out.println("OffsetDateTime.now(TimeZone.INDIA) = " + OffsetDateTime.now(INDIA)); System.out.println("Date and Time: " + datetime); System.out.println("Date and Time with timezone offset: " + date); }
From source file:org.openmhealth.shim.ihealth.mapper.IHealthSleepDurationDataPointMapper.java
@Override protected Optional<DataPoint<SleepDuration>> asDataPoint(JsonNode listEntryNode, Integer measureUnitMagicNumber) { SleepDuration.Builder sleepDurationBuilder = new SleepDuration.Builder( new DurationUnitValue(DurationUnit.MINUTE, asRequiredBigDecimal(listEntryNode, "HoursSlept"))); Optional<Long> startTime = asOptionalLong(listEntryNode, "StartTime"); Optional<Long> endTime = asOptionalLong(listEntryNode, "EndTime"); if (startTime.isPresent() && endTime.isPresent()) { Optional<String> timeZone = asOptionalString(listEntryNode, "TimeZone"); if (timeZone.isPresent()) { sleepDurationBuilder.setEffectiveTimeFrame(ofStartDateTimeAndEndDateTime( getDateTimeWithCorrectOffset(startTime.get(), ZoneOffset.of(timeZone.get())), getDateTimeWithCorrectOffset(endTime.get(), ZoneOffset.of(timeZone.get())))); }/*from ww w . j a v a2 s . c om*/ } getUserNoteIfExists(listEntryNode).ifPresent(sleepDurationBuilder::setUserNotes); SleepDuration sleepDuration = sleepDurationBuilder.build(); asOptionalBigDecimal(listEntryNode, "Awaken") .ifPresent(awaken -> sleepDuration.setAdditionalProperty("wakeup_count", awaken)); return Optional.of(new DataPoint<>(createDataPointHeader(listEntryNode, sleepDuration), sleepDuration)); }
From source file:ws.salient.session.SessionModule.java
@Provides public ZoneId provideZoneId() { if (properties.containsKey("zone.offsetId")) { return ZoneOffset.of(properties.getProperty("zone.offsetId")); } else {/*from w w w. j av a 2 s . c o m*/ return ZoneOffset.UTC; } }
From source file:com.epam.ta.reportportal.database.search.FilterRules.java
public static Predicate<String> zoneOffset() { return value -> { if (value == null) return false; try {//from ww w . ja v a2s . com ZoneOffset.of(value); } catch (DateTimeException e) { return false; } return true; }; }
From source file:org.openmhealth.shim.ihealth.mapper.IHealthPhysicalActivityDataPointMapper.java
@Override protected Optional<DataPoint<PhysicalActivity>> asDataPoint(JsonNode listEntryNode, Integer measureUnitMagicNumber) { String activityName = asRequiredString(listEntryNode, "SportName"); if (activityName.isEmpty()) { return Optional.empty(); }/* ww w . j av a2s . c o m*/ PhysicalActivity.Builder physicalActivityBuilder = new PhysicalActivity.Builder(activityName); Optional<Long> startTimeUnixEpochSecs = asOptionalLong(listEntryNode, "SportStartTime"); Optional<Long> endTimeUnixEpochSecs = asOptionalLong(listEntryNode, "SportEndTime"); Optional<Integer> timeZoneOffset = asOptionalInteger(listEntryNode, "TimeZone"); if (startTimeUnixEpochSecs.isPresent() && endTimeUnixEpochSecs.isPresent() && timeZoneOffset.isPresent()) { Integer timeZoneOffsetValue = timeZoneOffset.get(); String timeZoneString = timeZoneOffsetValue.toString(); // Zone offset cannot parse a positive string offset that's missing a '+' sign (i.e., "0200" vs "+0200") if (timeZoneOffsetValue >= 0) { timeZoneString = "+" + timeZoneOffsetValue.toString(); } physicalActivityBuilder.setEffectiveTimeFrame(ofStartDateTimeAndEndDateTime( getDateTimeWithCorrectOffset(startTimeUnixEpochSecs.get(), ZoneOffset.of(timeZoneString)), getDateTimeWithCorrectOffset(endTimeUnixEpochSecs.get(), ZoneOffset.of(timeZoneString)))); } asOptionalDouble(listEntryNode, "Calories").ifPresent( calories -> physicalActivityBuilder.setCaloriesBurned(new KcalUnitValue(KILOCALORIE, calories))); PhysicalActivity physicalActivity = physicalActivityBuilder.build(); return Optional .of(new DataPoint<>(createDataPointHeader(listEntryNode, physicalActivity), physicalActivity)); }
From source file:com.intuit.wasabi.api.pagination.filters.FilterUtil.java
/** * Formats a date as it is shown in the UI to allow for matching searches on date fields. * Needs the requesting user's timezone offset to UTC for correct matches. * * @param date the date//w ww .j a v a 2s.co m * @param timeZoneOffset the timezone offset to UTC * @return a timezone offset adjusted string of the UI pattern {@code MMM d, YYYY HH:mm:ss a}. */ /*test*/ static String formatDateTimeAsUI(OffsetDateTime date, String timeZoneOffset) { try { return date.format(DateTimeFormatter.ofPattern("MMM d, YYYY HH:mm:ss a") .withZone(ZoneId.ofOffset("UTC", ZoneOffset.of(timeZoneOffset)))); } catch (DateTimeException dateTimeException) { throw new PaginationException(ErrorCode.FILTER_KEY_UNPROCESSABLE, "Wrong format: Can not parse timezone '" + timeZoneOffset + "' or date " + date.toString() + " properly.", dateTimeException); } }
From source file:org.openmhealth.shim.ihealth.mapper.IHealthDataPointMapper.java
/** * Get an effective time frame based on the measurement date/time information in the list entry node. The effective * time frame is set as a single point in time using an OffsetDateTime. This method does not get effective time * frame as a time interval.//from w w w . j a v a2 s .c om * * @param listEntryNode A single node from the response result array. */ protected static Optional<TimeFrame> getEffectiveTimeFrameAsDateTime(JsonNode listEntryNode) { Optional<Long> weirdSeconds = asOptionalLong(listEntryNode, "MDate"); if (!weirdSeconds.isPresent()) { return Optional.empty(); } ZoneOffset zoneOffset = null; // if the time zone is a JSON string if (asOptionalString(listEntryNode, "TimeZone").isPresent() && !asOptionalString(listEntryNode, "TimeZone").get().isEmpty()) { zoneOffset = ZoneOffset.of(asOptionalString(listEntryNode, "TimeZone").get()); } // if the time zone is an JSON integer else if (asOptionalLong(listEntryNode, "TimeZone").isPresent()) { Long timeZoneOffsetValue = asOptionalLong(listEntryNode, "TimeZone").get(); String timeZoneString = timeZoneOffsetValue.toString(); // Zone offset cannot parse a positive string offset that's missing a '+' sign (i.e., "0200" vs "+0200") if (timeZoneOffsetValue >= 0) { timeZoneString = "+" + timeZoneString; } zoneOffset = ZoneOffset.of(timeZoneString); } if (zoneOffset == null) { return Optional.empty(); } return Optional.of(new TimeFrame(getDateTimeWithCorrectOffset(weirdSeconds.get(), zoneOffset))); }
From source file:org.openmhealth.shim.ihealth.mapper.IHealthDataPointMapper.java
/** * @param dateTimeInUnixSecondsWithLocalTimeOffset A unix epoch timestamp in local time. * @param timeZoneString The time zone offset as a String (e.g., "+0200","-2"). * @return The date time with the correct offset. *///ww w. j av a 2 s . c o m protected static OffsetDateTime getDateTimeAtStartOfDayWithCorrectOffset( Long dateTimeInUnixSecondsWithLocalTimeOffset, String timeZoneString) { // Since the timestamps are in local time, we can use the local date time provided by rendering the timestamp // in UTC, then translating that local time to the appropriate offset. OffsetDateTime dateTimeFromOffsetInstant = ofInstant( ofEpochSecond(dateTimeInUnixSecondsWithLocalTimeOffset), ZoneId.of("Z")); return dateTimeFromOffsetInstant.toLocalDate().atStartOfDay().atOffset(ZoneOffset.of(timeZoneString)); }