Java 类java.time.OffsetDateTime 实例源码

项目:openjdk-jdk10    文件:TCKOffsetDateTime.java   
@Test
public void now_Clock_allSecsInDay_utc() {
    for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
        Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
        Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
        OffsetDateTime test = OffsetDateTime.now(clock);
        assertEquals(test.getYear(), 1970);
        assertEquals(test.getMonth(), Month.JANUARY);
        assertEquals(test.getDayOfMonth(), (i < 24 * 60 * 60 ? 1 : 2));
        assertEquals(test.getHour(), (i / (60 * 60)) % 24);
        assertEquals(test.getMinute(), (i / 60) % 60);
        assertEquals(test.getSecond(), i % 60);
        assertEquals(test.getNano(), 123456789);
        assertEquals(test.getOffset(), ZoneOffset.UTC);
    }
}
项目:redg    文件:DateConverter.java   
static <T> T convertDateInternal(String string, Class<T> type, ZoneId fallbackZoneId) {
   if (java.util.Date.class.equals(type)) {
      return (T) java.util.Date.from(parseInstant(string, fallbackZoneId));
   } else if (java.sql.Date.class.equals(type)) {
      return (T) java.sql.Date.from(parseInstant(string, fallbackZoneId));
   } else if (Time.class.equals(type)) {
      return (T) Time.from(parseInstant(string, fallbackZoneId));
   } else if (Timestamp.class.equals(type)) {
      return (T) Timestamp.from(parseInstant(string, fallbackZoneId));
   } else if (LocalTime.class.equals(type)) {
      return (T) LocalTime.parse(string);
   } else if (LocalDate.class.equals(type)) {
      return (T) LocalDate.parse(string);
   } else if (LocalDateTime.class.equals(type)) {
      return (T) LocalDateTime.parse(string);
   } else if (ZonedDateTime.class.equals(type)) {
      return (T) ZonedDateTime.parse(string);
   } else if (OffsetDateTime.class.equals(type)) {
      return (T) OffsetDateTime.parse(string);
   } else if (OffsetTime.class.equals(type)) {
      return (T) OffsetTime.parse(string);
   }

   return null;
}
项目:spring-boot-gae    文件:OffsetDateTimeStringTranslatorFactoryTest.java   
@Test
public void testLoad() throws Exception {
    new ExecuteAsTimeZone(TimeZone.getTimeZone(ZoneOffset.UTC))
            .run(() -> assertThat(
                    load("2017-08-28T07:09:36.000000042Z")
                            .isEqual(OffsetDateTime.of(2017, 8, 28, 7, 9, 36, 42, ZoneOffset.UTC)),
                    is(true)
            ));
}
项目:DiscordIPC    文件:RichPresence.java   
public RichPresence(String state, String details, OffsetDateTime startTimestamp, OffsetDateTime endTimestamp, 
        String largeImageKey, String largeImageText, String smallImageKey, String smallImageText, 
        String partyId, int partySize, int partyMax, String matchSecret, String joinSecret, 
        String spectateSecret, boolean instance)
{
    this.state = state;
    this.details = details;
    this.startTimestamp = startTimestamp;
    this.endTimestamp = endTimestamp;
    this.largeImageKey = largeImageKey;
    this.largeImageText = largeImageText;
    this.smallImageKey = smallImageKey;
    this.smallImageText = smallImageText;
    this.partyId = partyId;
    this.partySize = partySize;
    this.partyMax = partyMax;
    this.matchSecret = matchSecret;
    this.joinSecret = joinSecret;
    this.spectateSecret = spectateSecret;
    this.instance = instance;
}
项目:jdk8u-jdk    文件:TestFormatter.java   
private void testZoneId(Locale locale, ChronoZonedDateTime<?> zdt, Calendar cal) {
    String fmtStr = "z:[%tz] z:[%1$Tz] Z:[%1$tZ] Z:[%1$TZ]";
    printFmtStr(locale, fmtStr);
    String expected = toZoneIdStr(test(fmtStr, locale, null, cal));
    test(fmtStr, locale, expected, zdt);
    // get a new cal with fixed tz
    Calendar cal0 = Calendar.getInstance();
    cal0.setTimeInMillis(zdt.toInstant().toEpochMilli());
    cal0.setTimeZone(TimeZone.getTimeZone("GMT" + zdt.getOffset().getId()));
    expected = toZoneOffsetStr(test(fmtStr, locale, null, cal0));
    if (zdt instanceof ZonedDateTime) {
        OffsetDateTime odt = ((ZonedDateTime)zdt).toOffsetDateTime();
        test(fmtStr, locale, expected, odt);
        test(fmtStr, locale, expected, odt.toOffsetTime());
    }

    // datetime + zid
    fmtStr = "c:[%tc] c:[%1$Tc]";
    printFmtStr(locale, fmtStr);
    expected = toZoneIdStr(test(fmtStr, locale, null, cal));
    test(fmtStr, locale, expected, zdt);
}
项目:openjdk-jdk10    文件:TCKOffsetDateTime.java   
@Test
public void test_getLong_TemporalField() {
    OffsetDateTime test = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(12, 30, 40, 987654321), OFFSET_PONE);
    assertEquals(test.getLong(ChronoField.YEAR), 2008);
    assertEquals(test.getLong(ChronoField.MONTH_OF_YEAR), 6);
    assertEquals(test.getLong(ChronoField.DAY_OF_MONTH), 30);
    assertEquals(test.getLong(ChronoField.DAY_OF_WEEK), 1);
    assertEquals(test.getLong(ChronoField.DAY_OF_YEAR), 182);

    assertEquals(test.getLong(ChronoField.HOUR_OF_DAY), 12);
    assertEquals(test.getLong(ChronoField.MINUTE_OF_HOUR), 30);
    assertEquals(test.getLong(ChronoField.SECOND_OF_MINUTE), 40);
    assertEquals(test.getLong(ChronoField.NANO_OF_SECOND), 987654321);
    assertEquals(test.getLong(ChronoField.HOUR_OF_AMPM), 0);
    assertEquals(test.getLong(ChronoField.AMPM_OF_DAY), 1);

    assertEquals(test.getLong(ChronoField.INSTANT_SECONDS), test.toEpochSecond());
    assertEquals(test.getLong(ChronoField.OFFSET_SECONDS), 3600);
}
项目:shoucang    文件:TestUtil.java   
/**
 * Convert an object to JSON byte array.
 *
 * @param object
 *            the object to convert
 * @return the JSON byte array
 * @throws IOException
 */
public static byte[] convertObjectToJsonBytes(Object object)
        throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

    JavaTimeModule module = new JavaTimeModule();
    module.addSerializer(OffsetDateTime.class, JSR310DateTimeSerializer.INSTANCE);
    module.addSerializer(ZonedDateTime.class, JSR310DateTimeSerializer.INSTANCE);
    module.addSerializer(LocalDateTime.class, JSR310DateTimeSerializer.INSTANCE);
    module.addSerializer(Instant.class, JSR310DateTimeSerializer.INSTANCE);
    module.addDeserializer(LocalDate.class, JSR310LocalDateDeserializer.INSTANCE);
    mapper.registerModule(module);

    return mapper.writeValueAsBytes(object);
}
项目:spring-boot-gae    文件:OffsetDateTimeSearchIntegrationTest.java   
@Test
public void findADocumentByGreaterThanOrEqualMatch() {
    searchService.index(Arrays.asList(
            new TestEntity("id1", OffsetDateTime.parse("2017-01-01T01:02:03Z")),
            new TestEntity("id2", OffsetDateTime.parse("2017-01-02T01:02:03Z")),
            new TestEntity("id3", OffsetDateTime.parse("2017-01-02T01:02:04Z")),
            new TestEntity("id4", OffsetDateTime.parse("2017-01-03T01:02:03Z"))
    ));

    Query<TestEntity> query = searchService.createQuery(TestEntity.class)
            .filter("value", GREATER_THAN_OR_EQUAL, OffsetDateTime.parse("2017-01-02T01:02:03Z"))
            .build();

    assertThat(searchService.execute(query))
            .extractingResultOf("getId")
            .containsExactlyInAnyOrder("id2", "id3", "id4");
}
项目:J-Cord    文件:MessageDeleteEventHandler.java   
@Override
public void dispatchEvent(JSONObject json, int sequence) {
    String msg_id = json.getString("id");
    String channel_id = json.getString("channel_id");

    MessageChannel channel = (MessageChannel) identity.getMessageChannel(channel_id);
    if (channel != null) {

        if (channel.isPrivate()) {
            dispatchEvent(new PrivateMessageDeleteEvent(identity, sequence, channel, msg_id, OffsetDateTime.from(Instant.now())));
        } else {
            dispatchEvent(new GuildMessageDeleteEvent(identity, sequence, channel, msg_id, OffsetDateTime.from(Instant.now())));
        }

    } else {
        logger.log(LogLevel.FETAL, "[UNKNOWN CHANNEL][MESSAGE_DELETE_EVENT]");
    }
}
项目:J-Cord    文件:ChannelDeleteEventHandler.java   
@Override
public void dispatchEvent(JSONObject json, int sequence) {
    Channel channel = (Channel) identity.getChannel(json.getString("id"));
    OffsetDateTime timeStamp = OffsetDateTime.now();

    if (channel.isType(IChannel.Type.GROUP_DM)) {
        identity.getClient().removeGroup(channel.getId());
        dispatchEvent(new GroupDeleteEvent(identity, sequence, channel, timeStamp));
    } else if (channel.isType(IChannel.Type.DM)) {
        identity.removePrivateChannel(channel.getId());
        dispatchEvent(new PrivateChannelDeleteEvent(identity, sequence, channel, timeStamp));
    } else {
        Guild guild = (Guild) ((IGuildChannel) channel).getGuild();
        if (channel.isType(IChannel.Type.GUILD_TEXT)) {
            guild.removeTextChannel(channel.getId());
            dispatchEvent(new TextChannelDeleteEvent(identity, sequence, channel, timeStamp, guild));
        } else {
            guild.removeVoiceChannel(channel.getId());
            dispatchEvent(new VoiceChannelDeleteEvent(identity, sequence, channel, timeStamp, guild));
        }
    }
}
项目:mpd-tools    文件:MPD.java   
private MPD(List<ProgramInformation> programInformations, List<BaseURL> baseURLs, List<String> locations, List<Period> periods, List<Metrics> metrics, List<Descriptor> essentialProperties, List<Descriptor> supplementalProperties, List<UTCTiming> utcTimings, String id, Profiles profiles, PresentationType type, OffsetDateTime availabilityStartTime, OffsetDateTime availabilityEndTime, OffsetDateTime publishTime, Duration mediaPresentationDuration, Duration minimumUpdatePeriod, Duration minBufferTime, Duration timeShiftBufferDepth, Duration suggestedPresentationDelay, Duration maxSegmentDuration, Duration maxSubsegmentDuration, String schemaLocation) {
    this.programInformations = programInformations;
    this.baseURLs = baseURLs;
    this.locations = locations;
    this.periods = periods;
    this.metrics = metrics;
    this.essentialProperties = essentialProperties;
    this.supplementalProperties = supplementalProperties;
    this.utcTimings = utcTimings;
    this.id = id;
    this.profiles = profiles;
    this.type = type;
    this.availabilityStartTime = availabilityStartTime;
    this.availabilityEndTime = availabilityEndTime;
    this.publishTime = publishTime;
    this.mediaPresentationDuration = mediaPresentationDuration;
    this.minimumUpdatePeriod = minimumUpdatePeriod;
    this.minBufferTime = minBufferTime;
    this.timeShiftBufferDepth = timeShiftBufferDepth;
    this.suggestedPresentationDelay = suggestedPresentationDelay;
    this.maxSegmentDuration = maxSegmentDuration;
    this.maxSubsegmentDuration = maxSubsegmentDuration;
    this.schemaLocation = schemaLocation;
}
项目:jdk8u-jdk    文件:TCKOffsetTime.java   
@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},

    };
}
项目:jdk8u-jdk    文件:TestOffsetDateTime_instants.java   
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;
        }
    }
}
项目:openjdk-jdk10    文件:TCKOffsetDateTime.java   
@Test
public void now_Clock_allSecsInDay_offset() {
    for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
        Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
        Clock clock = Clock.fixed(instant.minusSeconds(OFFSET_PONE.getTotalSeconds()), OFFSET_PONE);
        OffsetDateTime test = OffsetDateTime.now(clock);
        assertEquals(test.getYear(), 1970);
        assertEquals(test.getMonth(), Month.JANUARY);
        assertEquals(test.getDayOfMonth(), (i < 24 * 60 * 60) ? 1 : 2);
        assertEquals(test.getHour(), (i / (60 * 60)) % 24);
        assertEquals(test.getMinute(), (i / 60) % 60);
        assertEquals(test.getSecond(), i % 60);
        assertEquals(test.getNano(), 123456789);
        assertEquals(test.getOffset(), OFFSET_PONE);
    }
}
项目:timezone    文件:LocalTime.java   
public LocalTime(OffsetDateTime offsetDateTime, Locale locale) {
    offset = offsetDateTime.getOffset().getTotalSeconds();
    year = offsetDateTime.getYear();
    month = offsetDateTime.getMonth().getDisplayName(TextStyle.FULL,locale);
    dayOfMonth = offsetDateTime.getDayOfMonth();
    dayOfWeek = offsetDateTime.getDayOfWeek().getDisplayName(TextStyle.FULL,locale);
    monthValue = offsetDateTime.getMonthValue();
    hour = offsetDateTime.getHour();
    minute = offsetDateTime.getMinute();
    second = offsetDateTime.getSecond();
    nano = offsetDateTime.getNano();
}
项目:bson-codecs-jsr310    文件:OffsetDateTimeCodec.java   
@Override
public OffsetDateTime decode(
        BsonReader reader,
        DecoderContext decoderContext) {

    return parse(reader.readString());
}
项目:banana    文件:UserRepositoryTest.java   
@Test
public void testSpecification() {

    LocalDateTime time = LocalDateTime.of(2017, 11, 7, 16, 58, 3);
    Date date = Date.from(time.toInstant(OffsetDateTime.now().getOffset()));
    List<User> list = userRepository.findAll((Specification<User>) (root, query, cb) -> {
        Predicate p1 = cb.like(root.get("name"), "%Jay%");
        Predicate p2 = cb.lessThan(root.get("birthday"), date);
        //将两个查询条件联合起来之后返回Predicate对象
        return cb.and(p1, p2);
    });

    list.forEach(e -> log.info("testSpecification:{}", e));
}
项目:openjdk-jdk10    文件:TCKOffsetPrinterParser.java   
@Test(dataProvider="print_localized")
public void test_print_localized(TextStyle style, LocalDateTime ldt, ZoneOffset offset, String expected) {
    OffsetDateTime odt = OffsetDateTime.of(ldt, offset);
    ZonedDateTime zdt = ldt.atZone(offset);

    DateTimeFormatter f = new DateTimeFormatterBuilder().appendLocalizedOffset(style)
                                                        .toFormatter();
    assertEquals(f.format(odt), expected);
    assertEquals(f.format(zdt), expected);
    assertEquals(f.parse(expected, ZoneOffset::from), offset);

    if (style == TextStyle.FULL) {
        f = new DateTimeFormatterBuilder().appendPattern("ZZZZ")
                                          .toFormatter();
        assertEquals(f.format(odt), expected);
        assertEquals(f.format(zdt), expected);
        assertEquals(f.parse(expected, ZoneOffset::from), offset);

        f = new DateTimeFormatterBuilder().appendPattern("OOOO")
                                          .toFormatter();
        assertEquals(f.format(odt), expected);
        assertEquals(f.format(zdt), expected);
        assertEquals(f.parse(expected, ZoneOffset::from), offset);
    }

    if (style == TextStyle.SHORT) {
        f = new DateTimeFormatterBuilder().appendPattern("O")
                                          .toFormatter();
        assertEquals(f.format(odt), expected);
        assertEquals(f.format(zdt), expected);
        assertEquals(f.parse(expected, ZoneOffset::from), offset);
    }
}
项目:holon-datastore-jpa    文件:JpaDatastoreUtils.java   
/**
 * Try to obtain the {@link TemporalType} of given <code>expression</code>, if the expression type is a temporal
 * type.
 * @param expression Query expression
 * @param treatDateTypeAsDate <code>true</code> to return {@link TemporalType#DATE} for {@link Date} type if
 *        temporal information is not available
 * @return The expression {@link TemporalType}, empty if not available or applicable
 */
public static Optional<TemporalType> getTemporalType(Expression expression, boolean treatDateTypeAsDate) {
    if (expression != null) {
        Class<?> type = null;
        if (Path.class.isAssignableFrom(expression.getClass())) {
            type = ((Path<?>) expression).getType();
        } else if (QueryExpression.class.isAssignableFrom(expression.getClass())) {
            type = ((QueryExpression<?>) expression).getType();
        }

        if (type != null) {
            if (LocalDate.class.isAssignableFrom(type) || ChronoLocalDate.class.isAssignableFrom(type)) {
                return Optional.of(TemporalType.DATE);
            }
            if (LocalTime.class.isAssignableFrom(type) || OffsetTime.class.isAssignableFrom(type)) {
                return Optional.of(TemporalType.TIME);
            }
            if (LocalDateTime.class.isAssignableFrom(type) || OffsetDateTime.class.isAssignableFrom(type)
                    || ZonedDateTime.class.isAssignableFrom(type)
                    || ChronoLocalDateTime.class.isAssignableFrom(type)) {
                return Optional.of(TemporalType.DATE);
            }

            if (Date.class.isAssignableFrom(type) || Calendar.class.isAssignableFrom(type)) {
                if (Property.class.isAssignableFrom(expression.getClass())) {
                    Optional<TemporalType> tt = ((Property<?>) expression).getConfiguration().getTemporalType();
                    return treatDateTypeAsDate ? Optional.of(tt.orElse(TemporalType.DATE)) : tt;
                } else {
                    return treatDateTypeAsDate ? Optional.of(TemporalType.DATE) : Optional.empty();
                }
            }

        }
    }
    return Optional.empty();
}
项目:openjdk-jdk10    文件:TCKOffsetDateTime.java   
@Test(dataProvider="sampleToString")
public void test_parse(int y, int month, int d, int h, int m, int s, int n, String offsetId, String text) {
    OffsetDateTime t = OffsetDateTime.parse(text);
    assertEquals(t.getYear(), y);
    assertEquals(t.getMonth().getValue(), month);
    assertEquals(t.getDayOfMonth(), d);
    assertEquals(t.getHour(), h);
    assertEquals(t.getMinute(), m);
    assertEquals(t.getSecond(), s);
    assertEquals(t.getNano(), n);
    assertEquals(t.getOffset().getId(), offsetId);
}
项目:jdk8u-jdk    文件:TestFormatter.java   
private void testInstant(Locale locale, Instant instant,
                         ChronoZonedDateTime<?> zdt, Calendar cal) {
    String fmtStr = "s:[%ts] s:[%1$Ts] Q:[%1$tQ] Q:[%1$TQ]";
    printFmtStr(locale, fmtStr);
    String expected = test(fmtStr, locale, null, cal);
    test(fmtStr, locale, expected, instant);
    test(fmtStr, locale, expected, zdt);
    if (zdt instanceof ZonedDateTime) {
        OffsetDateTime odt = ((ZonedDateTime)zdt).toOffsetDateTime();
        test(fmtStr, locale, expected, odt);
    }
}
项目:generator-thundr-gae-react    文件:OffsetDateTimeDateTranslatorFactoryTest.java   
@Test
public void load_willReturnZonedDate_whenSystemDateTimeIsNotUTC() throws Exception {
    new ExecuteAsTimeZone(TimeZone.getTimeZone(ZoneOffset.ofHours(10)))
            .run(() -> assertThat(
                    load(date("2017-08-28T07:09:36Z"))
                            .isEqual(OffsetDateTime.of(2017, 8, 28, 17, 9, 36, 0, ZoneOffset.ofHours(10))),
                    is(true)
            ));
}
项目:openjdk-jdk10    文件:TCKChronology.java   
@Test(dataProvider = "epochSecond_dataProvider")
public void test_epochSecond(Chronology chrono, int y, int m, int d, int h, int min, int s, ZoneOffset offset) {
    ChronoLocalDate chronoLd = chrono.date(y, m, d);
    assertEquals(chrono.epochSecond(y, m, d, h, min, s, offset),
                 OffsetDateTime.of(LocalDate.from(chronoLd), LocalTime.of(h, min, s), offset)
                               .toEpochSecond());
}
项目:trading4j    文件:M1.java   
@Override
public boolean areInSameTimeFrame(final Instant instant1, final Instant instant2) {
    final OffsetDateTime localStart = instant1.atOffset(UTC).withSecond(0).withNano(0);
    final Instant start = localStart.toInstant();
    final Instant startOfNext = localStart.plusMinutes(1).toInstant();
    return instant2.equals(start) || (instant2.isAfter(start) && instant2.isBefore(startOfNext));
}
项目:nges    文件:EventStoreITest.java   
static private Matcher<OffsetDateTime> after(final OffsetDateTime border) {
    return new TypeSafeMatcher<OffsetDateTime>() {
        @Override
        public void describeTo(Description description) {
            description.appendText("Timestamp after " + border);
        }

        @Override
        protected boolean matchesSafely(OffsetDateTime item) {
            return item.isAfter(border);
        }
    };
}
项目:jdk8u-jdk    文件:TCKOffsetDateTime.java   
@Test
public void test_compareTo_offsetNanos() {
    OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 30, 40, 6, OFFSET_PTWO);
    OffsetDateTime b = OffsetDateTime.of(2008, 6, 30, 11, 30, 40, 5, OFFSET_PONE);  // a is before b due to offset
    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);
}
项目:xitk    文件:ASN1Type.java   
public static int writeGeneralizedTime(Date time, byte[] out, int offset) {
    OffsetDateTime offsetTime = time.toInstant().atOffset(ZoneOffset.UTC);
    int idx = offset;
    out[idx++] = 0x18;
    out[idx++] = 15;
    // yyyyMMddhhmmssZ
    // year
    int year = offsetTime.getYear();
    out[idx++] = (byte) (0x30 + year / 1000);
    out[idx++] = (byte) (0x30 + year / 100 % 10);
    out[idx++] = (byte) (0x30 + year / 10 % 10);
    out[idx++] = (byte) (0x30 + year % 10);
    // month
    int month = offsetTime.getMonthValue();
    out[idx++] = (byte) (0x30 + month / 10);
    out[idx++] = (byte) (0x30 + month % 10);
    // day
    int day = offsetTime.getDayOfMonth();
    out[idx++] = (byte) (0x30 + day / 10);
    out[idx++] = (byte) (0x30 + day % 10);
    // hour
    int hour = offsetTime.getHour();
    out[idx++] = (byte) (0x30 + hour / 10);
    out[idx++] = (byte) (0x30 + hour % 10);
    // minute
    int minute = offsetTime.getMinute();
    out[idx++] = (byte) (0x30 + minute / 10);
    out[idx++] = (byte) (0x30 + minute % 10);
    // second
    int second = offsetTime.getSecond();
    out[idx++] = (byte) (0x30 + second / 10);
    out[idx++] = (byte) (0x30 + second % 10);
    out[idx++] = 'Z';
    return idx - offset;
}
项目:openjdk-jdk10    文件:TCKOffsetDateTime.java   
@Test
public void test_compareTo_min() {
    OffsetDateTime a = OffsetDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0, 0, 0, OFFSET_PTWO);
    OffsetDateTime b = OffsetDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0, 0, 0, OFFSET_PONE);  // a is before b due to offset
    assertEquals(a.compareTo(b) < 0, true);
    assertEquals(b.compareTo(a) > 0, true);
    assertEquals(a.compareTo(a) == 0, true);
    assertEquals(b.compareTo(b) == 0, true);
}
项目:openjdk-jdk10    文件:TCKOffsetDateTime.java   
@Test(dataProvider="sampleTimes")
public void test_equals_true(int y, int o, int d, int h, int m, int s, int n, ZoneOffset ignored) {
    OffsetDateTime a = OffsetDateTime.of(y, o, d, h, m, s, n, OFFSET_PONE);
    OffsetDateTime b = OffsetDateTime.of(y, o, d, h, m, s, n, OFFSET_PONE);
    assertEquals(a.equals(b), true);
    assertEquals(a.hashCode() == b.hashCode(), true);
}
项目:iextrading4j    文件:NewsServiceTest.java   
@Test
public void newsServiceTest() {
    stubFor(get(urlEqualTo("/stock/aapl/news/last/10"))
            .withHeader("Accept", equalTo("application/json"))
            .willReturn(aResponse()
                    .withStatus(200)
                    .withHeader("Accept", "application/json")
                    .withHeader("Content-Type", "application/json")
                    .withBodyFile("/rest/stock/NewsResponse.json")));

    final List<News> newsList = iexTradingClient.executeRequest(new NewsRequestBuilder()
            .withSymbol("aapl")
            .build());

    final News firstNews = newsList.get(0);
    assertThat(firstNews.getDatetime()).isEqualTo(OffsetDateTime.of(
            LocalDateTime.of(2017,11,10,21,6, 0),
            ZoneOffset.of("Z")));
    assertThat(firstNews.getHeadline()).isEqualTo("Netflix dropped 5 percent this week, after rallying all year");
    assertThat(firstNews.getSource()).isEqualTo("CNBC");
    assertThat(firstNews.getUrl()).isEqualTo("https://api.iextrading.com/1.0/stock/aapl/article/8464142968106298");
    assertThat(firstNews.getSummary()).isEqualTo("No summary available.");
    assertThat(firstNews.getRelated()).isEqualTo("AAPL,AMZN,FB,GOOGL,NFLX");

    final News secondNews = newsList.get(1);
    assertThat(secondNews.getDatetime()).isEqualTo(OffsetDateTime.of(
            LocalDateTime.of(2017,11,10,19,16, 0),
            ZoneOffset.of("Z")));
    assertThat(secondNews.getHeadline()).isEqualTo("Apple will issue a fix for iPhone X devices that seize up in the cold");
    assertThat(secondNews.getSource()).isEqualTo("CNBC");
    assertThat(secondNews.getUrl()).isEqualTo("https://api.iextrading.com/1.0/stock/aapl/article/5121696418454999");
    assertThat(secondNews.getSummary()).isEqualTo("No summary available.");
    assertThat(secondNews.getRelated()).isEqualTo("AAPL");
}
项目:J-Cord    文件:Invite.java   
public Invite setMetaData(User inviter, int uses, int maxUses, long maxAge, boolean isTemporary, boolean isRevoked, String timeStamp) {
    this.inviter = inviter;
    this.uses = uses;
    this.maxUses = maxUses;
    this.maxAge = maxAge;
    this.isTemporary = isTemporary;
    this.isRevoked = isRevoked;
    this.timeStamp = OffsetDateTime.parse(timeStamp);
    return this;
}
项目:openjdk-jdk10    文件:TCKOffsetDateTime.java   
@Test
public void test_compareTo_timeNanos() {
    OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 29, 40, 4, OFFSET_PONE);
    OffsetDateTime b = OffsetDateTime.of(2008, 6, 30, 11, 29, 40, 5, 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);
}
项目:jdk8u-jdk    文件:TCKOffsetDateTime.java   
@Test(dataProvider="sampleTimes")
public void test_equals_false_minute_differs(int y, int o, int d, int h, int m, int s, int n, ZoneOffset ignored) {
    m = (m == 59 ? 58 : m);
    OffsetDateTime a = OffsetDateTime.of(y, o, d, h, m, s, n, OFFSET_PONE);
    OffsetDateTime b = OffsetDateTime.of(y, o, d, h, m + 1, s, n, OFFSET_PONE);
    assertEquals(a.equals(b), false);
}
项目:outland    文件:DefaultGroupService.java   
private Optional<Group> processRegistration(Group group) {
  OffsetDateTime now = OffsetDateTime.now();
  String created = GroupService.asString(now);
  final Group.Builder builder = newNamespaceBuilder(group);
  builder.setId(Names.group(now));
  builder.setCreated(created);
  builder.setUpdated(created);

  List<Owner> ownersReady = Lists.newArrayList();
  group.getOwners().getItemsList().forEach(owner -> ownersReady.add(prepareOwner(owner)));
  OwnerCollection.Builder oc = OwnerCollection.newBuilder()
      .addAllItems(ownersReady);
  builder.setOwners(oc);

  AccessCollection.Builder accessCollectionBuilder = newGrantCollectionBuilder();

  List<ServiceAccess> servicesReady = Lists.newArrayList();
  group.getGranted()
      .getServicesList()
      .forEach(service -> servicesReady.add(prepareService(service)));
  accessCollectionBuilder.addAllServices(servicesReady);

  List<MemberAccess> memberReady = Lists.newArrayList();
  group.getGranted().getMembersList().forEach(access -> memberReady.add(prepareMember(access)));
  accessCollectionBuilder.addAllMembers(memberReady);

  builder.clearGranted();
  builder.setGranted(accessCollectionBuilder.buildPartial());

  final Group registered = builder.build();

  // todo: the usual compensating write failure stuff
  registerNamespaceInner(registered);
  registerOwners(registered);
  registerServices(registered);
  registerMembers(registered);

  return Optional.of(registered);
}
项目:jdk8u-jdk    文件:TestOffsetDateTime_instants.java   
public void factory_ofInstant_allSecsInDay() {
    for (int i = 0; i < (24 * 60 * 60); i++) {
        Instant instant = Instant.ofEpochSecond(i);
        OffsetDateTime test = OffsetDateTime.ofInstant(instant, OFFSET_PONE);
        assertEquals(test.getYear(), 1970);
        assertEquals(test.getMonth(), Month.JANUARY);
        assertEquals(test.getDayOfMonth(), 1 + (i >= 23 * 60 * 60 ? 1 : 0));
        assertEquals(test.getHour(), ((i / (60 * 60)) + 1) % 24);
        assertEquals(test.getMinute(), (i / 60) % 60);
        assertEquals(test.getSecond(), i % 60);
    }
}
项目:openjdk-jdk10    文件:TCKYear.java   
@Test
public void now_Clock() {
    Instant instant = OffsetDateTime.of(LocalDate.of(2010, 12, 31), LocalTime.of(0, 0), ZoneOffset.UTC).toInstant();
    Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
    Year test = Year.now(clock);
    assertEquals(test.getValue(), 2010);
}
项目:jdk8u-jdk    文件:TestOffsetDateTime.java   
@Test(dataProvider="sampleTimes")
public void test_get_same(int y, int o, int d, int h, int m, int s, int n, ZoneOffset offset) {
    LocalDate localDate = LocalDate.of(y, o, d);
    LocalTime localTime = LocalTime.of(h, m, s, n);
    LocalDateTime localDateTime = LocalDateTime.of(localDate, localTime);
    OffsetDateTime a = OffsetDateTime.of(localDateTime, offset);

    assertSame(a.getOffset(), offset);
    assertSame(a.toLocalDate(), localDate);
    assertSame(a.toLocalTime(), localTime);
    assertSame(a.toLocalDateTime(), localDateTime);
}
项目:openjdk-jdk10    文件:TCKOffsetDateTime.java   
@Test
public void test_atZone_dstOverlapSummer() {
    OffsetDateTime t = OffsetDateTime.of(2007, 10, 28, 2, 30, 0, 0, OFFSET_PTWO);
    assertEquals(t.atZoneSimilarLocal(ZONE_PARIS).toLocalDateTime(), t.toLocalDateTime());
    assertEquals(t.atZoneSimilarLocal(ZONE_PARIS).getOffset(), OFFSET_PTWO);
    assertEquals(t.atZoneSimilarLocal(ZONE_PARIS).getZone(), ZONE_PARIS);
}
项目:openjdk-jdk10    文件:TCKInstant.java   
@Test
public void test_atOffset() {
    for (int i = 0; i < (24 * 60 * 60); i++) {
        Instant instant = Instant.ofEpochSecond(i);
        OffsetDateTime test = instant.atOffset(ZoneOffset.ofHours(1));
        assertEquals(test.getYear(), 1970);
        assertEquals(test.getMonthValue(), 1);
        assertEquals(test.getDayOfMonth(), 1 + (i >= 23 * 60 * 60 ? 1 : 0));
        assertEquals(test.getHour(), ((i / (60 * 60)) + 1) % 24);
        assertEquals(test.getMinute(), (i / 60) % 60);
        assertEquals(test.getSecond(), i % 60);
    }
}
项目:outland    文件:DefaultGroupService.java   
private Group processUpdate(Group group, Consumer<Group.Builder> updateExtra) {
  final Group.Builder builder = newNamespaceBuilder(group);
  builder.setUpdated(GroupService.asString(OffsetDateTime.now()));
  updateExtra.accept(builder);
  final Group updated = builder.build();
  updateNamespaceInner(updated);
  updateOwners(updated);
  updateMembers(updated);
  updateServices(updated);
  return updated;
}