java.time.OffsetDateTime Java Examples

The following examples show how to use java.time.OffsetDateTime. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestOffsetDateTime_instants.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void doTest_factory_ofInstant_all(long minYear, long maxYear) {
    long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7);
    int minOffset = (minYear <= 0 ? 0 : 3);
    int maxOffset = (maxYear <= 0 ? 0 : 3);
    long minDays = (minYear * 365L + ((minYear + minOffset) / 4L - (minYear + minOffset) / 100L + (minYear + minOffset) / 400L)) - days_0000_to_1970;
    long maxDays = (maxYear * 365L + ((maxYear + maxOffset) / 4L - (maxYear + maxOffset) / 100L + (maxYear + maxOffset) / 400L)) + 365L - days_0000_to_1970;

    final LocalDate maxDate = LocalDate.of(Year.MAX_VALUE, 12, 31);
    OffsetDateTime expected = OffsetDateTime.of(LocalDate.of((int) minYear, 1, 1), LocalTime.of(0, 0, 0, 0), ZoneOffset.UTC);
    for (long i = minDays; i < maxDays; i++) {
        Instant instant = Instant.ofEpochSecond(i * 24L * 60L * 60L);
        try {
            OffsetDateTime test = OffsetDateTime.ofInstant(instant, ZoneOffset.UTC);
            assertEquals(test, expected);
            if (expected.toLocalDate().equals(maxDate) == false) {
                expected = expected.plusDays(1);
            }
        } catch (RuntimeException|Error ex) {
            System.out.println("Error: " + i + " " + expected);
            throw ex;
        }
    }
}
 
Example #2
Source File: LanderTaskRunnerTest.java    From data-highway with Apache License 2.0 6 votes vote down vote up
@Test
public void runTypical() throws Exception {
  when(offsetManager.getLatestOffsets(TOPIC_NAME)).thenReturn(ImmutableMap.of(1, 10L, 2, 20L));
  when(offsetManager.getCommittedOffsets(TOPIC_NAME)).thenReturn(ImmutableMap.of(1, 5L, 2, 15L));

  when(landerFactory.newInstance(expectedLanderConfiguration)).thenReturn(lander);
  CompletableFuture<LanderConfiguration> future = new CompletableFuture<>();
  when(lander.run()).thenReturn(future);
  future.complete(expectedLanderConfiguration);
  when(hivePartitionManager.addPartition(eq(ROAD_NAME), any(), any())).thenReturn(Optional.of(partition));

  underTest.run(OffsetDateTime.ofInstant(Instant.ofEpochMilli(runtimeMillis), ZoneOffset.UTC));

  verify(offsetManager).getCommittedOffsets(TOPIC_NAME);
  verify(offsetManager).getLatestOffsets(TOPIC_NAME);
  verify(landerFactory).newInstance(expectedLanderConfiguration);
  verify(hivePartitionManager).addPartition(ROAD_NAME, singletonList(ACQUISITION_INSTANT), S3_PREFIX);
  verify(offsetManager).commitOffsets(TOPIC_NAME, ImmutableMap.of(1, 10L, 2, 20L));
  verify(landingNotifier).handlePartitionCreated(ROAD_NAME, partition, PARTITION_SPEC, 10L);
  verify(emitter)
      .emit(new PatchSet(ROAD_NAME, singletonList(PatchOperation.replace(LAST_RUN_PATH, "2018-05-16T09:17:04Z"))));
  verifyNoMoreInteractions(emitter);
}
 
Example #3
Source File: TasksBase.java    From java-asana with MIT License 6 votes vote down vote up
/**
* Get multiple tasks
* Returns the compact task records for some filtered set of tasks. Use one or more of the parameters provided to filter the tasks returned. You must specify a &#x60;project&#x60; or &#x60;tag&#x60; if you do not specify &#x60;assignee&#x60; and &#x60;workspace&#x60;.  For more complex task retrieval, use [workspaces/{workspace_gid}/tasks/search](#search-tasks-in-a-workspace).
    * @param modifiedSince Only return tasks that have been modified since the given time.  *Note: A task is considered “modified” if any of its properties change, or associations between it and other objects are modified (e.g.  a task being added to a project). A task is not considered modified just because another object it is associated with (e.g. a subtask) is modified. Actions that count as modifying the task include assigning, renaming, completing, and adding stories.* (optional)
    * @param completedSince Only return tasks that are either incomplete or that have been completed since this time. (optional)
    * @param workspace The workspace to filter tasks on. *Note: If you specify &#x60;workspace&#x60;, you must also specify the &#x60;assignee&#x60; to filter on.* (optional)
    * @param section The section to filter tasks on. *Note: Currently, this is only supported in board views.* (optional)
    * @param project The project to filter tasks on. (optional)
    * @param assignee The assignee to filter tasks on. *Note: If you specify &#x60;assignee&#x60;, you must also specify the &#x60;workspace&#x60; to filter on.* (optional)
    * @param offset Offset token. An offset to the next page returned by the API. A pagination request will return an offset token, which can be used as an input parameter to the next request. If an offset is not passed in, the API will return the first page of results. &#x27;Note: You can only pass in an offset that was returned to you via a previously paginated request.&#x27; (optional)
    * @param limit Results per page. The number of objects to return per page. The value must be between 1 and 100. (optional)
    * @param optFields Defines fields to return. Some requests return *compact* representations of objects in order to conserve resources and complete the request more efficiently. Other times requests return more information than you may need. This option allows you to list the exact set of fields that the API should be sure to return for the objects. The field names should be provided as paths, described below. The id of included objects will always be returned, regardless of the field options. (optional)
    * @param optPretty Provides “pretty” output. Provides the response in a “pretty” format. In the case of JSON this means doing proper line breaking and indentation to make it readable. This will take extra time and increase the response size so it is advisable only to use this during debugging. (optional)
* @return CollectionRequest(Task)
* @throws IOException If we fail to call the API, e.g. server error or cannot deserialize the response body
*/
public CollectionRequest<Task> getTasks(OffsetDateTime modifiedSince, OffsetDateTime completedSince, String workspace, String section, String project, String assignee, String offset, Integer limit, List<String> optFields, Boolean optPretty) throws IOException {
    String path = "/tasks";

    CollectionRequest<Task> req = new CollectionRequest<Task>(this, Task.class, path, "GET")
        .query("opt_pretty", optPretty)
        .query("opt_fields", optFields)
        .query("limit", limit)
        .query("offset", offset)
        .query("assignee", assignee)
        .query("project", project)
        .query("section", section)
        .query("workspace", workspace)
        .query("completed_since", completedSince)
        .query("modified_since", modifiedSince);

    return req;
}
 
Example #4
Source File: TCKOffsetTime.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@DataProvider(name="adjustInto")
Object[][] data_adjustInto() {
    return new Object[][]{
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.of(LocalTime.of(1, 1, 1, 100), ZoneOffset.UTC), OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), null},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.MAX, OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), null},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.MIN, OffsetTime.of(LocalTime.of(23 , 5), OFFSET_PONE), null},
            {OffsetTime.MAX, OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.of(OffsetTime.MAX.toLocalTime(), ZoneOffset.ofHours(-18)), null},
            {OffsetTime.MIN, OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.of(OffsetTime.MIN.toLocalTime(), ZoneOffset.ofHours(18)), null},


            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), ZonedDateTime.of(LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), ZONE_GAZA), ZonedDateTime.of(LocalDateTime.of(2012, 3, 4, 23, 5), ZONE_GAZA), null},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetDateTime.of(LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), ZoneOffset.UTC), OffsetDateTime.of(LocalDateTime.of(2012, 3, 4, 23, 5), OFFSET_PONE), null},

            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), null, DateTimeException.class},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), LocalDate.of(2210, 2, 2), null, DateTimeException.class},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), LocalTime.of(22, 3, 0), null, DateTimeException.class},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), null, null, NullPointerException.class},

    };
}
 
Example #5
Source File: TCKOffsetDateTime.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_isBeforeIsAfterIsEqual_instantComparison() {
    OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 10, 0, 0, 0, OFFSET_PONE);
    OffsetDateTime b = OffsetDateTime.of(2008, 6, 30, 11, 0, 0, 0, OFFSET_PTWO);  // a is same instant as b
    assertEquals(a.isBefore(b), false);
    assertEquals(a.isEqual(b), true);
    assertEquals(a.isAfter(b), false);

    assertEquals(b.isBefore(a), false);
    assertEquals(b.isEqual(a), true);
    assertEquals(b.isAfter(a), false);

    assertEquals(a.isBefore(a), false);
    assertEquals(b.isBefore(b), false);

    assertEquals(a.isEqual(a), true);
    assertEquals(b.isEqual(b), true);

    assertEquals(a.isAfter(a), false);
    assertEquals(b.isAfter(b), false);
}
 
Example #6
Source File: FitbitSleepDurationDataPointMapperUnitTests.java    From shimmer with Apache License 2.0 6 votes vote down vote up
@Test
public void asDataPointsShouldReturnCorrectDataPoints() {

    SleepDuration2 expectedSleepDuration = new SleepDuration2.Builder(
            new DurationUnitValue(MINUTE, 112),
            ofStartDateTimeAndEndDateTime(
                    OffsetDateTime.parse("2016-12-13T01:16:00.000Z"),
                    OffsetDateTime.parse("2016-12-13T03:14:00.000Z")
            ))
            .build();

    List<DataPoint<SleepDuration2>> dataPoints = mapper.asDataPoints(sleepDateResponseNode);

    DataPoint<SleepDuration2> dataPoint = dataPoints.get(1);

    assertThat(dataPoint.getBody(), equalTo(expectedSleepDuration));
    assertThat(dataPoint.getHeader().getBodySchemaId(), equalTo(SleepDuration2.SCHEMA_ID));
    assertThat(dataPoint.getHeader().getAcquisitionProvenance().getSourceName(),
            equalTo(FitbitDataPointMapper.RESOURCE_API_SOURCE_NAME));
}
 
Example #7
Source File: ResponseType.java    From graphql-java-datetime with Apache License 2.0 5 votes vote down vote up
public ResponseType() {
    date = new Date(1499667166754L);
    localDate = LocalDate.of(2017, 1, 1);
    localTime = LocalTime.MIDNIGHT;
    localDateTime = LocalDateTime.of(localDate, localTime);
    offsetDateTime = OffsetDateTime.of(localDate, localTime, ZoneOffset.UTC);
}
 
Example #8
Source File: AbstractRecordService.java    From mobi with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Generates a new record namespace and adds the properties from the config to that record.
 *
 * @param config A {@link RecordOperationConfig} that contains the record configuration
 * @param issued Time the record was issued
 * @param modified Time the record was modified
 * @return A {@link Record} of the provided config
 */
protected T createRecordObject(RecordOperationConfig config, OffsetDateTime issued, OffsetDateTime modified) {
    T record = recordFactory.createNew(valueFactory.createIRI(Catalogs.RECORD_NAMESPACE + UUID.randomUUID()));
    Literal titleLiteral = valueFactory.createLiteral(config.get(RecordCreateSettings.RECORD_TITLE));
    Literal issuedLiteral = valueFactory.createLiteral(issued);
    Literal modifiedLiteral = valueFactory.createLiteral(modified);
    Set<Value> publishers = config.get(RecordCreateSettings.RECORD_PUBLISHERS).stream()
            .map(user -> (Value) user.getResource())
            .collect(Collectors.toSet());
    IRI catalogIdIRI = valueFactory.createIRI(config.get(RecordCreateSettings.CATALOG_ID));
    record.setCatalog(catalogFactory.createNew(catalogIdIRI));

    record.setProperty(titleLiteral, valueFactory.createIRI(_Thing.title_IRI));
    record.setProperty(issuedLiteral, valueFactory.createIRI(_Thing.issued_IRI));
    record.setProperty(modifiedLiteral, valueFactory.createIRI(_Thing.modified_IRI));
    record.setProperties(publishers, valueFactory.createIRI(_Thing.publisher_IRI));
    if (config.get(RecordCreateSettings.RECORD_DESCRIPTION) != null
            && StringUtils.isNotEmpty(config.get(RecordCreateSettings.RECORD_DESCRIPTION))) {
        record.setProperty(valueFactory.createLiteral(config.get(RecordCreateSettings.RECORD_DESCRIPTION)),
                valueFactory.createIRI(_Thing.description_IRI));
    }
    if (config.get(RecordCreateSettings.RECORD_MARKDOWN) != null
            && StringUtils.isNotEmpty(config.get(RecordCreateSettings.RECORD_MARKDOWN))) {
        record.setProperty(valueFactory.createLiteral(config.get(RecordCreateSettings.RECORD_MARKDOWN)),
                valueFactory.createIRI(DCTERMS.ABSTRACT.stringValue()));
    }
    if (config.get(RecordCreateSettings.RECORD_KEYWORDS).size() > 0) {
        record.setKeyword(config.get(RecordCreateSettings.RECORD_KEYWORDS).stream()
                .map(valueFactory::createLiteral).collect(Collectors.toSet()));
    }
    return record;
}
 
Example #9
Source File: TCKOffsetDateTime.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="sampleTimes")
public void test_equals_false_hour_differs(int y, int o, int d, int h, int m, int s, int n, ZoneOffset ignored) {
    h = (h == 23 ? 22 : h);
    OffsetDateTime a = OffsetDateTime.of(y, o, d, h, m, s, n, OFFSET_PONE);
    OffsetDateTime b = OffsetDateTime.of(y, o, d, h + 1, m, s, n, OFFSET_PONE);
    assertEquals(a.equals(b), false);
}
 
Example #10
Source File: OffsetDateTimeConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Object fromString(final String str) {
    try {
        return OffsetDateTime.parse(str);
    } catch (final DateTimeParseException e) {
        final ConversionException exception = new ConversionException("Cannot parse value as offset date time", e);
        exception.add("value", str);
        throw exception;
    }
}
 
Example #11
Source File: IHealthBodyMassIndexDataPointMapperUnitTests.java    From shimmer with Apache License 2.0 5 votes vote down vote up
@Test
public void asDataPointsShouldReturnCorrectSelfReportedDataPoints() {

    BodyMassIndex1 expectedBodyMassIndex = new BodyMassIndex1.Builder(
            new TypedUnitValue<>(KILOGRAMS_PER_SQUARE_METER, 22.56052398681641))
            .setEffectiveTimeFrame(OffsetDateTime.parse("2015-09-17T14:07:57-06:00"))
            .setUserNotes("Weight so good, look at me now")
            .build();

    assertThat(dataPoints.get(1).getBody(), equalTo(expectedBodyMassIndex));

    testDataPointHeader(dataPoints.get(1).getHeader(), SCHEMA_ID, SELF_REPORTED,
            "b702a3a5e998f2fca268df6daaa69871", OffsetDateTime.parse("2015-09-17T20:08:00Z"));
}
 
Example #12
Source File: TCKOffsetDateTime.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_compareTo_timeSecs() {
    OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 29, 2, 0, OFFSET_PONE);
    OffsetDateTime b = OffsetDateTime.of(2008, 6, 30, 11, 29, 3, 0, OFFSET_PONE);  // a is before b due to time
    assertEquals(a.compareTo(b) < 0, true);
    assertEquals(b.compareTo(a) > 0, true);
    assertEquals(a.compareTo(a) == 0, true);
    assertEquals(b.compareTo(b) == 0, true);
    assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true);
    assertEquals(OffsetDateTime.timeLineOrder().compare(a, b) < 0, true);
}
 
Example #13
Source File: Order.java    From vertx-swagger with Apache License 2.0 5 votes vote down vote up
public Order (Long id, Long petId, Integer quantity, OffsetDateTime shipDate, StatusEnum status, Boolean complete) {
  this.id = id;
  this.petId = petId;
  this.quantity = quantity;
  this.shipDate = shipDate;
  this.status = status;
  this.complete = complete;
}
 
Example #14
Source File: Jackson2ObjectMapperBuilderTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public OffsetDateTime deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
	final String value = jsonParser.getValueAsString();
	if (StringUtils.isEmpty(value)) {
		return null;
	}
	try {
		return OffsetDateTime.parse(value);

	}
	catch (DateTimeParseException exception) {
		return OffsetDateTime.parse(value + CURRENT_ZONE_OFFSET);
	}
}
 
Example #15
Source File: TCKOffsetDateTime.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_toEpochSecond_afterEpoch() {
    for (int i = 0; i < 100000; i++) {
        OffsetDateTime a = OffsetDateTime.of(1970, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC).plusSeconds(i);
        assertEquals(a.toEpochSecond(), i);
    }
}
 
Example #16
Source File: TomlTable.java    From cava with Apache License 2.0 5 votes vote down vote up
/**
 * Get an offset date time from the TOML document.
 *
 * @param path The key path.
 * @return The value, or {@code null} if no value was set in the TOML document.
 * @throws TomlInvalidTypeException If the value is present but not an {@link OffsetDateTime}, or any element of the
 *         path preceding the final key is not a table.
 */
@Nullable
default OffsetDateTime getOffsetDateTime(List<String> path) {
  Object value = get(path);
  if (value == null) {
    return null;
  }
  if (!(value instanceof OffsetDateTime)) {
    throw new TomlInvalidTypeException("Value of '" + joinKeyPath(path) + "' is a " + typeNameFor(value));
  }
  return (OffsetDateTime) value;
}
 
Example #17
Source File: TestFormatter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void testTime(String fmtStr, Locale locale,
                             ChronoZonedDateTime<?> zdt, Calendar cal) {
    printFmtStr(locale, fmtStr);
    String expected = test(fmtStr, locale, null, cal);
    test(fmtStr, locale, expected, zdt);
    test(fmtStr, locale, expected, zdt.toLocalDateTime());
    test(fmtStr, locale, expected, zdt.toLocalTime());
    if (zdt instanceof ZonedDateTime) {
        OffsetDateTime odt = ((ZonedDateTime)zdt).toOffsetDateTime();
        test(fmtStr, locale, expected, odt);
        test(fmtStr, locale, expected, odt.toOffsetTime());
    }
}
 
Example #18
Source File: TestUmmAlQuraChronology.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_Instant_zonedDateTime() {
    OffsetDateTime offsetDateTime = OffsetDateTime.of(2012, 2, 29, 2, 7, 1, 1, OFFSET_PTWO);
    ZonedDateTime zonedDateTime = ZonedDateTime.of(2012, 2, 29, 2, 7, 1, 1, ZONE_RIYADH);

    ChronoZonedDateTime<HijrahDate> result = HijrahChronology.INSTANCE.zonedDateTime(offsetDateTime.toInstant(), offsetDateTime.getOffset());
    assertEquals(result.toLocalDate(), HijrahChronology.INSTANCE.date(1433, 4, 7));
    assertEquals(result.toLocalTime(), LocalTime.of(2, 7, 1, 1));

    result = HijrahChronology.INSTANCE.zonedDateTime(zonedDateTime.toInstant(), zonedDateTime.getOffset());
    assertEquals(result.toLocalDate(), HijrahChronology.INSTANCE.date(1433, 4, 7));
    assertEquals(result.toLocalTime(), LocalTime.of(2, 7, 1, 1));
}
 
Example #19
Source File: JsonNodeMappingSupportUnitTests.java    From shimmer with Apache License 2.0 5 votes vote down vote up
@Test
public void asOptionalOffsetDateTimeShouldReturnEmptyOnMissingNode() {

    Optional<OffsetDateTime> value = asOptionalOffsetDateTime(testNode, "foo");

    assertThat(value, notNullValue());
    assertThat(value.isPresent(), equalTo(false));
}
 
Example #20
Source File: TCKOffsetDateTime.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void test_compareTo_hourDifference() {
    OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 10, 0, 0, 0, OFFSET_PONE);
    OffsetDateTime b = OffsetDateTime.of(2008, 6, 30, 11, 0, 0, 0, OFFSET_PTWO);  // a is before b despite being same time-line time
    assertEquals(a.compareTo(b) < 0, true);
    assertEquals(b.compareTo(a) > 0, true);
    assertEquals(a.compareTo(a) == 0, true);
    assertEquals(b.compareTo(b) == 0, true);
    assertEquals(a.toInstant().compareTo(b.toInstant()) == 0, true);
}
 
Example #21
Source File: TestOffsetDateTime_instants.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void factory_ofInstant_minWithMinOffset() {
    long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7);
    int year = Year.MIN_VALUE;
    long days = (year * 365L + (year / 4 - year / 100 + year / 400)) - days_0000_to_1970;
    Instant instant = Instant.ofEpochSecond(days * 24L * 60L * 60L - OFFSET_MIN.getTotalSeconds());
    OffsetDateTime test = OffsetDateTime.ofInstant(instant, OFFSET_MIN);
    assertEquals(test.getYear(), Year.MIN_VALUE);
    assertEquals(test.getMonth().getValue(), 1);
    assertEquals(test.getDayOfMonth(), 1);
    assertEquals(test.getOffset(), OFFSET_MIN);
    assertEquals(test.getHour(), 0);
    assertEquals(test.getMinute(), 0);
    assertEquals(test.getSecond(), 0);
    assertEquals(test.getNano(), 0);
}
 
Example #22
Source File: TCKOffsetDateTime.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_with_adjustment() {
    final OffsetDateTime sample = OffsetDateTime.of(LocalDate.of(2012, 3, 4), LocalTime.of(23, 5), OFFSET_PONE);
    TemporalAdjuster adjuster = new TemporalAdjuster() {
        @Override
        public Temporal adjustInto(Temporal dateTime) {
            return sample;
        }
    };
    assertEquals(TEST_2008_6_30_11_30_59_000000500.with(adjuster), sample);
}
 
Example #23
Source File: PgExpressionHandler.java    From FROST-Server with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public FieldWrapper visit(Path path) {
    PathState<J> state = new PathState<>();
    state.pathTableRef = tableRef;
    state.elements = path.getElements();
    for (state.curIndex = 0; state.curIndex < state.elements.size() && !state.finished; state.curIndex++) {
        Property element = state.elements.get(state.curIndex);
        if (element instanceof CustomProperty) {
            handleCustomProperty(state, path);

        } else if (element instanceof CustomPropertyLink) {
            handleCustomProperty(state, path);

        } else if (element instanceof EntityProperty) {
            handleEntityProperty(state, path, element);

        } else if (element instanceof NavigationPropertyMain) {
            handleNavigationProperty(state, path, element);
        }
    }
    if (state.finalExpression == null) {
        throw new IllegalArgumentException("Path does not end in an EntityProperty: " + path);
    }
    if (state.finalExpression instanceof Field) {
        Field field = (Field) state.finalExpression;
        if (OffsetDateTime.class.isAssignableFrom(field.getType())) {
            Field<OffsetDateTime> dateTimePath = (Field<OffsetDateTime>) state.finalExpression;
            state.finalExpression = new StaDateTimeWrapper(dateTimePath);
        }
    }
    return state.finalExpression;
}
 
Example #24
Source File: MixedPropertiesAndAdditionalPropertiesClass.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Get dateTime
 * @return dateTime
*/
@ApiModelProperty(value = "")

@Valid

public OffsetDateTime getDateTime() {
  return dateTime;
}
 
Example #25
Source File: DateParserUtilsTest.java    From dateparser with MIT License 5 votes vote down vote up
@Test
public void demo() {
    Date date = DateParserUtils.parseDate("12-Dec-05");
    System.out.println(date);
    Calendar calendar = DateParserUtils.parseCalendar("Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)");
    System.out.println(calendar.toInstant());
    LocalDateTime dateTime = DateParserUtils.parseDateTime("2019-09-20 10:20:30.12345678 +0200");
    System.out.println(dateTime);
    OffsetDateTime offsetDateTime = DateParserUtils.parseOffsetDateTime("2015-09-30 18:48:56.35272715 +0000 UTC");
    System.out.println(offsetDateTime);
}
 
Example #26
Source File: RPCUpdater.java    From Hyperium with GNU Lesser General Public License v3.0 5 votes vote down vote up
@InvokeEvent
public void joinSingleplayer(SingleplayerJoinEvent event) {
    RichPresence.Builder builder = new RichPresence.Builder();

    client.sendRichPresence(builder
        .setSmallImage("compass")
        .setLargeImage("hyperium", "Hyperium Client")
        .setState("IGN: " + Minecraft.getMinecraft().getSession().getUsername())
        .setDetails("Playing Singleplayer")
        .setStartTimestamp(OffsetDateTime.now())
        .build());
}
 
Example #27
Source File: TCKZonedDateTime.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "withFieldLong")
public void test_with_adjuster_ensureOffsetDateTimeConsistent(ZonedDateTime base, TemporalField setField, int setValue, ZonedDateTime expected) {
    if (setField == OFFSET_SECONDS) {
        OffsetDateTime odt = base.toOffsetDateTime().with(setField, setValue);
        assertEquals(base.with(odt), expected);
    }
}
 
Example #28
Source File: TCKOffsetDateTime.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_compareTo_bothNanos() {
    OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 20, 40, 4, OFFSET_PTWO);
    OffsetDateTime b = OffsetDateTime.of(2008, 6, 30, 10, 20, 40, 5, OFFSET_PONE);  // a is before b on instant scale
    assertEquals(a.compareTo(b) < 0, true);
    assertEquals(b.compareTo(a) > 0, true);
    assertEquals(a.compareTo(a) == 0, true);
    assertEquals(b.compareTo(b) == 0, true);
    assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true);
    assertEquals(OffsetDateTime.timeLineOrder().compare(a, b) < 0, true);
}
 
Example #29
Source File: ISOOffsetDateTimeEncoder.java    From agrest with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean encodeNonNullObject(Object object, JsonGenerator out) throws IOException {
    OffsetDateTime dateTime = (OffsetDateTime) object;
    String formatted = DateTimeFormatters.isoOffsetDateTime().format(dateTime);
    out.writeObject(formatted);
    return true;
}
 
Example #30
Source File: TCKOffsetDateTime.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_compareTo_both() {
    OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 50, 0, 0, OFFSET_PTWO);
    OffsetDateTime b = OffsetDateTime.of(2008, 6, 30, 11, 20, 0, 0, OFFSET_PONE);  // a is before b on instant scale
    assertEquals(a.compareTo(b) < 0, true);
    assertEquals(b.compareTo(a) > 0, true);
    assertEquals(a.compareTo(a) == 0, true);
    assertEquals(b.compareTo(b) == 0, true);
    assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true);
    assertEquals(OffsetDateTime.timeLineOrder().compare(a, b) < 0, true);
}