Example usage for java.time OffsetDateTime of

List of usage examples for java.time OffsetDateTime of

Introduction

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

Prototype

public static OffsetDateTime of(int year, int month, int dayOfMonth, int hour, int minute, int second,
        int nanoOfSecond, ZoneOffset offset) 

Source Link

Document

Obtains an instance of OffsetDateTime from a year, month, day, hour, minute, second, nanosecond and offset.

Usage

From source file:Main.java

public static void main(String[] args) {
    OffsetDateTime o = OffsetDateTime.of(2014, 1, 14, 12, 23, 23, 1234, ZoneOffset.UTC);

    System.out.println(o);//from  www .j  a  va2s.c  o m
}

From source file:org.openmhealth.dsu.factory.DataPointFactory.java

public static CaloriesBurned newKcalBurnedBody() {

    TimeInterval effectiveTimeInterval = TimeInterval.ofStartDateTimeAndEndDateTime(
            OffsetDateTime.of(2013, 2, 5, 6, 25, 0, 0, UTC), OffsetDateTime.of(2013, 2, 5, 7, 25, 0, 0, UTC));

    return new CaloriesBurned.Builder(new KcalUnitValue(KILOCALORIE, 160)).setActivityName("walking")
            .setEffectiveTimeFrame(effectiveTimeInterval).build();
}

From source file:org.openmhealth.schema.serializer.Rfc3339OffsetDateTimeSerializerUnitTests.java

@Test
public void serializeShouldNotAppendSecondFieldWhenInstantHasNonZeroSeconds() throws IOException {

    OffsetDateTime instant = OffsetDateTime.of(2013, 2, 5, 7, 35, 12, 0, UTC);

    // since we're testing using ObjectMapper instead of the serializer, the string will get wrapped in quotes
    assertThat(objectMapper.writeValueAsString(instant), equalTo("\"2013-02-05T07:35:12Z\""));
}

From source file:org.openmhealth.schema.serializer.Rfc3339OffsetDateTimeSerializerUnitTests.java

@Test
public void serializeShouldAppendSecondFieldWhenInstantSecondsAreZero() throws IOException {

    OffsetDateTime instant = OffsetDateTime.of(2013, 2, 5, 7, 35, 0, 0, UTC);

    assertThat(objectMapper.writeValueAsString(instant), equalTo("\"2013-02-05T07:35:00Z\""));
}

From source file:org.openmhealth.schema.serializer.Rfc3339OffsetDateTimeSerializerUnitTests.java

@Test
public void serializeShouldNotAppendSecondFieldWhenInstantHasNonZeroNanoseconds() throws IOException {

    OffsetDateTime instant = OffsetDateTime.of(2013, 2, 5, 7, 35, 0, 123_000_000, UTC);

    assertThat(objectMapper.writeValueAsString(instant), equalTo("\"2013-02-05T07:35:00.123Z\""));
}

From source file:com.nike.cerberus.service.AuthenticationServiceTest.java

@Test
public void test_that_getKeyId_only_validates_kms_policy_one_time_within_interval() {

    String principalArn = "principal arn";
    String region = "region";
    String iamRoleId = "iam role id";
    String kmsKeyId = "kms id";
    String cmkId = "key id";

    // ensure that validate interval is passed
    OffsetDateTime dateTime = OffsetDateTime.of(2016, 1, 1, 1, 1, 1, 1, ZoneOffset.UTC);
    OffsetDateTime now = OffsetDateTime.now();

    IamPrincipalCredentials iamPrincipalCredentials = new IamPrincipalCredentials();
    iamPrincipalCredentials.setIamPrincipalArn(principalArn);
    iamPrincipalCredentials.setRegion(region);

    AwsIamRoleRecord awsIamRoleRecord = new AwsIamRoleRecord().setAwsIamRoleArn(principalArn);
    awsIamRoleRecord.setAwsIamRoleArn(principalArn);
    awsIamRoleRecord.setId(iamRoleId);/*w w  w.  j  a va 2  s.  c om*/
    when(awsIamRoleDao.getIamRole(principalArn)).thenReturn(Optional.of(awsIamRoleRecord));

    AwsIamRoleKmsKeyRecord awsIamRoleKmsKeyRecord = new AwsIamRoleKmsKeyRecord();
    awsIamRoleKmsKeyRecord.setId(kmsKeyId);
    awsIamRoleKmsKeyRecord.setAwsKmsKeyId(cmkId);
    awsIamRoleKmsKeyRecord.setLastValidatedTs(dateTime);

    when(awsIamRoleDao.getKmsKey(iamRoleId, region)).thenReturn(Optional.of(awsIamRoleKmsKeyRecord));

    when(dateTimeSupplier.get()).thenReturn(now);

    String result = authenticationService.getKeyId(iamPrincipalCredentials);

    // verify validate is called once interval has passed
    assertEquals(cmkId, result);
    verify(kmsService, times(1)).validatePolicy(awsIamRoleKmsKeyRecord, principalArn);
}

From source file:org.opendatakit.briefcase.export.SubmissionParser.java

/**
 * Returns an sorted {@link List} of {@link Path} instances pointing to all the
 * submissions of a form that belong to the given {@link DateRange}.
 * <p>/*from  w  w w .  j  a  v a 2 s. c o  m*/
 * Each file gets briefly parsed to obtain their submission date and use it as
 * the sorting criteria and for filtering.
 */
static List<Path> getListOfSubmissionFiles(FormDefinition formDef, DateRange dateRange,
        SubmissionExportErrorCallback onParsingError) {
    Path instancesDir = formDef.getFormDir().resolve("instances");
    if (!Files.exists(instancesDir) || !Files.isReadable(instancesDir))
        return Collections.emptyList();
    // TODO Migrate this code to Try<Pair<Path, Option<OffsetDate>>> to be able to filter failed parsing attempts
    List<Pair<Path, OffsetDateTime>> paths = new ArrayList<>();
    list(instancesDir).filter(UncheckedFiles::isInstanceDir).forEach(instanceDir -> {
        Path submissionFile = instanceDir.resolve("submission.xml");
        try {
            Optional<OffsetDateTime> submissionDate = readSubmissionDate(submissionFile, onParsingError);
            paths.add(Pair.of(submissionFile,
                    submissionDate.orElse(OffsetDateTime.of(1970, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC))));
        } catch (Throwable t) {
            log.error("Can't read submission date", t);
            EventBus.publish(ExportEvent.failureSubmission(formDef, instanceDir.getFileName().toString(), t));
        }
    });
    return paths.parallelStream()
            // Filter out submissions outside the given date range
            .filter(pair -> dateRange.contains(pair.getRight())).map(Pair::getLeft).collect(toList());
}

From source file:org.silverpeas.core.calendar.CalendarEventOccurrenceGenerationTest.java

private static OffsetDateTime dateTimeInUTC(int year, int month, int day, int hour, int minute) {
    return OffsetDateTime.of(year, month, day, hour, minute, 0, 0, ZoneOffset.UTC);
}