Example usage for java.time ZoneId of

List of usage examples for java.time ZoneId of

Introduction

In this page you can find the example usage for java.time ZoneId of.

Prototype

public static ZoneId of(String zoneId) 

Source Link

Document

Obtains an instance of ZoneId from an ID ensuring that the ID is valid and available for use.

Usage

From source file:alfio.repository.EventRepositoryTest.java

@Test
public void testJavaInsertedDatesRespectTheirTimeZone() throws Exception {
    //these are the values of what we have inserted in the SQL insert script
    ZonedDateTime beginEventDate = ZonedDateTime.of(2015, 4, 18, 0, 0, 0, 0, ZoneId.of("America/New_York"));
    ZonedDateTime endEventDate = ZonedDateTime.of(2015, 4, 19, 23, 59, 59, 0, ZoneId.of("America/New_York"));

    Pair<Integer, Integer> pair = eventRepository.insert("test from unit test", "unittest",
            "http://localhost:8080/", "http://localhost:8080", "http://localhost:8080", "Lugano", "9", "8",
            beginEventDate, endEventDate, NEW_YORK_TZ, 0, "CHF", 4, true, new BigDecimal(1), "", "", 0);
    Event e = eventRepository.findById(pair.getValue());
    assertNotNull("Event not found in DB", e);

    assertEquals("Begin date is not correct", beginEventDate, e.getBegin());
    assertEquals("End date is not correct", endEventDate, e.getEnd());

    //since when debugging the toString method is used .... and it rely on the system TimeZone, we test it too
    System.out.println(e.getBegin().toString());
    System.out.println(e.getEnd().toString());
}

From source file:com.github.ibm.domino.client.DominoRestClient.java

public DominoRestClient before(ZonedDateTime value) {
    parameters.put("before", getDateParameter(value.withZoneSameInstant(ZoneId.of("GMT"))));
    return this;
}

From source file:org.apache.metron.parsers.syslog.BaseSyslogParser.java

@Override
public void configure(Map<String, Object> parserConfig) {
    // we'll pull out the clock stuff ourselves
    String timeZone = (String) parserConfig.get("deviceTimeZone");
    if (timeZone != null)
        deviceClock = Clock.system(ZoneId.of(timeZone));
    else {/*  w  ww. ja va 2s . co m*/
        deviceClock = Clock.systemUTC();
        LOG.warn("[Metron] No device time zone provided; defaulting to UTC");
    }
    syslogParser = buildSyslogParser(parserConfig);
}

From source file:com.yahoo.egads.models.tsmm.TestOlympicModel2.java

@Test
public void ctor() throws Exception {
    OlympicModel2 model = new OlympicModel2(config);

    assertEquals(5, model.interval);/*from  w w  w. j a  va  2  s  .com*/
    assertEquals(ChronoUnit.MINUTES, model.intervalUnits);
    assertEquals(1, model.windowDistanceInterval);
    assertEquals(ChronoUnit.WEEKS, model.windowDistanceIntervalUnits);
    assertEquals(4, model.pastWindows);
    assertEquals(start, model.modelStartEpoch);
    assertEquals(ZoneId.of("UTC"), model.zone);
    assertFalse(model.weighting);
    assertEquals(1, model.futureWindows);
    assertEquals(0, model.drop_highest);
    assertEquals(0, model.drop_lowest);
    assertEquals(4, model.windowTimes.length);
    assertEquals(4, model.indices.length);
    assertTrue(model.model.isEmpty());

    // overrides
    config.clear();
    config.put("INTERVAL", "5");
    config.put("INTERVAL_UNITS", "MINUTES");
    config.put("WINDOW_SIZE", "1");
    config.put("WINDOW_SIZE_UNITS", "HOURS");
    config.put("WINDOW_DISTANCE", "1");
    config.put("WINDOW_DISTANCE_UNITS", "WEEKS");
    config.put("HISTORICAL_WINDOWS", "4");
    config.put("MODEL_START", Long.toString(start));
    config.put("TIMEZONE", "Australia/Lord_Howe");
    config.put("ENABLE_WEIGHTING", "true");
    config.put("FUTURE_WINDOWS", "2");
    config.put("NUM_TO_DROP_HIGHEST", "4");
    config.put("NUM_TO_DROP_LOWEST", "8");
    model = new OlympicModel2(config);

    assertEquals(5, model.interval);
    assertEquals(ChronoUnit.MINUTES, model.intervalUnits);
    assertEquals(1, model.windowDistanceInterval);
    assertEquals(ChronoUnit.WEEKS, model.windowDistanceIntervalUnits);
    assertEquals(4, model.pastWindows);
    assertEquals(start, model.modelStartEpoch);
    assertEquals(ZoneId.of("Australia/Lord_Howe"), model.zone);
    assertTrue(model.weighting);
    assertEquals(2, model.futureWindows);
    assertEquals(4, model.drop_highest);
    assertEquals(8, model.drop_lowest);
    assertEquals(4, model.windowTimes.length);
    assertEquals(4, model.indices.length);
    assertTrue(model.model.isEmpty());

    // null config, underlying ctor throws an NPE, should fix it.
    try {
        model = new OlympicModel2(null);
        fail("Expected NullPointerException");
    } catch (NullPointerException e) {
    }

    // Empty config
    config.clear();
    try {
        model = new OlympicModel2(config);
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    }

    // lots of missing required values tests.
    setConfig();
    config.remove("INTERVAL");

    try {
        model = new OlympicModel2(config);
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    }

    setConfig();
    config.remove("INTERVAL_UNITS");

    try {
        model = new OlympicModel2(config);
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    }

    setConfig();
    config.remove("WINDOW_SIZE");

    try {
        model = new OlympicModel2(config);
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    }

    setConfig();
    config.remove("WINDOW_SIZE_UNITS");

    try {
        model = new OlympicModel2(config);
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    }

    setConfig();
    config.remove("WINDOW_DISTANCE");

    try {
        model = new OlympicModel2(config);
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    }

    setConfig();
    config.remove("WINDOW_DISTANCE_UNITS");

    try {
        model = new OlympicModel2(config);
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    }

    setConfig();
    config.remove("MODEL_START");

    try {
        model = new OlympicModel2(config);
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    }

    setConfig();

    model = new OlympicModel2(config);

    assertEquals(1, model.pastWindows);
    assertEquals(ZoneId.of("UTC"), model.zone);

    // invalid params tests
    setConfig();
    config.setProperty("WINDOW_SIZE", "not a number");
    try {
        model = new OlympicModel2(config);
        fail("Expected NumberFormatException");
    } catch (NumberFormatException e) {
    }

    setConfig();
    config.setProperty("WINDOW_SIZE_UNITS", "not a unit");
    try {
        model = new OlympicModel2(config);
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    }

    setConfig();
    config.setProperty("WINDOW_DISTANCE", "not a number");
    try {
        model = new OlympicModel2(config);
        fail("Expected NumberFormatException");
    } catch (NumberFormatException e) {
    }

    setConfig();
    config.setProperty("WINDOW_DISTANCE_UNITS", "not a unit");
    try {
        model = new OlympicModel2(config);
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    }

    setConfig();
    config.setProperty("MODEL_START", "not a number");
    try {
        model = new OlympicModel2(config);
        fail("Expected NumberFormatException");
    } catch (NumberFormatException e) {
    }
}

From source file:de.rkl.tools.tzconv.view.ZoneIdSelectionDialog.java

private void resetFromModel(@SuppressWarnings("UnusedParameters") final DialogEvent dialogEvent) {
    pendingSelectedZoneIds.setValue(observableSet(
            applicationModel.selectedZoneIds.toArray(new ZoneId[applicationModel.selectedZoneIds.size()])));
    zoneIdCheckboxes.stream().forEach(zoneIdCheckBox -> zoneIdCheckBox
            .setSelected(pendingSelectedZoneIds.contains(ZoneId.of(zoneIdCheckBox.getText()))));
}

From source file:io.stallion.jobs.Schedule.java

public ZoneId getZoneId() {
    ZoneId zoneId = null;/* ww w .  j  a  va  2 s. com*/
    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");
    }
    return zoneId;
}

From source file:com.boozallen.cognition.ingest.storm.bolt.logging.LogRecordDateBolt.java

void logDate(LogRecord record) {
    Date date = record.getDate();
    if (date == null) {
        logger.error("Record date is null!");
    } else {//from  w ww  .j  a v a2  s.  co  m
        SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
        sdf.setTimeZone(TimeZone.getTimeZone(ZoneId.of("UTC")));
        super.log(logger, sdf.format(date));
    }
}

From source file:org.openmhealth.shim.withings.mapper.WithingsDailyStepCountDataPointMapper.java

/**
 * Maps an individual list node from the array in the Withings activity measure endpoint response into a {@link
 * StepCount} data point.//ww w .  j  a  v a  2  s .c o  m
 *
 * @param node activity node from the array "activites" contained in the "body" of the endpoint response
 * @return a {@link DataPoint} object containing a {@link StepCount} measure with the appropriate values from
 * the JSON node parameter, wrapped as an {@link Optional}
 */
@Override
Optional<DataPoint<StepCount>> asDataPoint(JsonNode node) {

    long stepValue = asRequiredLong(node, "steps");
    StepCount.Builder stepCountBuilder = new StepCount.Builder(stepValue);
    Optional<String> dateString = asOptionalString(node, "date");
    Optional<String> timeZoneFullName = asOptionalString(node, "timezone");
    // We assume that timezone is the same for both the startdate and enddate timestamps, even though Withings only
    // provides the enddate timezone as the "timezone" property.
    // TODO: Revisit once Withings can provide start_timezone and end_timezone
    if (dateString.isPresent() && timeZoneFullName.isPresent()) {
        LocalDateTime localStartDateTime = LocalDate.parse(dateString.get()).atStartOfDay();
        ZoneId zoneId = ZoneId.of(timeZoneFullName.get());
        ZonedDateTime zonedDateTime = ZonedDateTime.of(localStartDateTime, zoneId);
        ZoneOffset offset = zonedDateTime.getOffset();
        OffsetDateTime offsetStartDateTime = OffsetDateTime.of(localStartDateTime, offset);
        LocalDateTime localEndDateTime = LocalDate.parse(dateString.get()).atStartOfDay().plusDays(1);
        OffsetDateTime offsetEndDateTime = OffsetDateTime.of(localEndDateTime, offset);
        stepCountBuilder.setEffectiveTimeFrame(
                TimeInterval.ofStartDateTimeAndEndDateTime(offsetStartDateTime, offsetEndDateTime));
    }

    Optional<String> userComment = asOptionalString(node, "comment");
    if (userComment.isPresent()) {
        stepCountBuilder.setUserNotes(userComment.get());
    }

    StepCount stepCount = stepCountBuilder.build();
    DataPoint<StepCount> stepCountDataPoint = newDataPoint(stepCount, null, true, null);

    return Optional.of(stepCountDataPoint);
}

From source file:de.rkl.tools.tzconv.configuration.PreferencesProvider.java

public ZoneId getPreferredReferenceZoneIdIfSet() {
    final String preferredReferenceZoneId = applicationPreferences.get(PREFERENCES_KEY_REFERENCE_ZONE_ID, null);
    return StringUtils.isNotBlank(preferredReferenceZoneId) ? ZoneId.of(preferredReferenceZoneId)
            : ZoneId.systemDefault();
}

From source file:objective.taskboard.followup.FollowUpHelper.java

public static FromJiraDataRow getDefaultFromJiraDataRow(String subtaskStatus, Double taskballpark,
        String tshirtSize, String queryPlan) {
    FromJiraDataRow followUpData = new FromJiraDataRow();
    followUpData.planningType = "Ballpark";
    followUpData.project = "PROJECT TEST";
    followUpData.demandType = "Demand";
    followUpData.demandStatus = "Doing";
    followUpData.demandId = 1L;//w w  w  .j  a v  a 2s. co  m
    followUpData.demandNum = "I-1";
    followUpData.demandSummary = "Summary Demand";
    followUpData.demandDescription = "Description Demand";
    followUpData.demandStatusPriority = 0;
    followUpData.demandPriorityOrder = 0l;
    followUpData.demandStartDateStepMillis = 0L;
    followUpData.demandAssignee = "assignee.demand.test";
    followUpData.demandDueDate = DateTimeUtils.get(DateTimeUtils.parseDateTime("2025-05-25"),
            ZoneId.of(TIMEZONE_ID));
    followUpData.demandCreated = DateTimeUtils.get(DateTimeUtils.parseDateTime("2012-01-01"),
            ZoneId.of(TIMEZONE_ID));
    followUpData.demandLabels = "";
    followUpData.demandComponents = "";
    followUpData.demandReporter = "reporter.demand.test";
    followUpData.demandCoAssignees = "";
    followUpData.demandClassOfService = "Standard";
    followUpData.demandUpdatedDate = DateTimeUtils.get(DateTimeUtils.parseDateTime("2012-02-01"),
            ZoneId.of(TIMEZONE_ID));
    followUpData.demandCycletime = 1.111111;
    followUpData.demandIsBlocked = false;
    followUpData.demandLastBlockReason = "Demand last block reason";
    followUpData.demandExtraFields = null;

    followUpData.taskType = "Feature";
    followUpData.taskStatus = subtaskStatus;
    followUpData.taskId = 2L;
    followUpData.taskNum = "I-2";
    followUpData.taskSummary = "Summary Feature";
    followUpData.taskDescription = "Description Feature";
    followUpData.taskFullDescription = "Full Description Feature";
    followUpData.taskAdditionalEstimatedHours = 80.0;
    followUpData.taskRelease = "Release";
    followUpData.taskStatusPriority = 0;
    followUpData.taskPriorityOrder = 0l;
    followUpData.taskStartDateStepMillis = 0L;
    followUpData.taskAssignee = "assignee.task.test";
    followUpData.taskDueDate = DateTimeUtils.get(DateTimeUtils.parseDateTime("2025-05-24"),
            ZoneId.of(TIMEZONE_ID));
    followUpData.taskCreated = DateTimeUtils.get(DateTimeUtils.parseDateTime("2012-01-02"),
            ZoneId.of(TIMEZONE_ID));
    followUpData.taskLabels = "";
    followUpData.taskComponents = "";
    followUpData.taskReporter = "reporter.demand.test";
    followUpData.taskCoAssignees = "";
    followUpData.taskClassOfService = "Standard";
    followUpData.taskUpdatedDate = DateTimeUtils.get(DateTimeUtils.parseDateTime("2012-02-02"),
            ZoneId.of(TIMEZONE_ID));
    followUpData.taskCycletime = 2.222222;
    followUpData.taskIsBlocked = false;
    followUpData.taskLastBlockReason = "Task last block reason";
    followUpData.taskExtraFields = null;

    followUpData.subtaskType = "Sub-task";
    followUpData.subtaskStatus = subtaskStatus;
    followUpData.subtaskId = 3L;
    followUpData.subtaskNum = "I-3";
    followUpData.subtaskSummary = "Summary Sub-task";
    followUpData.subtaskDescription = "Description Sub-task";
    followUpData.subtaskFullDescription = "Full Description Sub-task";
    followUpData.subtaskStatusPriority = 0;
    followUpData.subtaskPriorityOrder = 0l;
    followUpData.subtaskStartDateStepMillis = 0L;
    followUpData.subtaskAssignee = "assignee.subtask.test";
    followUpData.subtaskDueDate = DateTimeUtils.get(DateTimeUtils.parseDateTime("2025-05-23"),
            ZoneId.of(TIMEZONE_ID));
    followUpData.subtaskCreated = DateTimeUtils.get(DateTimeUtils.parseDateTime("2012-01-03"),
            ZoneId.of(TIMEZONE_ID));
    followUpData.subtaskLabels = "";
    followUpData.subtaskComponents = "";
    followUpData.subtaskReporter = "reporter.subtask.test";
    followUpData.subtaskCoAssignees = "";
    followUpData.subtaskClassOfService = "Standard";
    followUpData.subtaskUpdatedDate = DateTimeUtils.get(DateTimeUtils.parseDateTime("2012-02-03"),
            ZoneId.of(TIMEZONE_ID));
    followUpData.subtaskCycletime = 3.333333;
    followUpData.subtaskIsBlocked = false;
    followUpData.subtaskLastBlockReason = "Subtask last block reason";
    followUpData.subtaskExtraFields = null;

    followUpData.tshirtSize = tshirtSize;
    followUpData.worklog = 1D;
    followUpData.wrongWorklog = 1D;
    followUpData.demandBallpark = 1D;
    followUpData.taskBallpark = taskballpark;
    followUpData.queryType = queryPlan;

    return followUpData;
}