Package org.threeten.bp

Examples of org.threeten.bp.Instant


    //-----------------------------------------------------------------------
    // now(Clock)
    //-----------------------------------------------------------------------
    @Test
    public void now_Clock() {
        Instant instant = LocalDateTime.of(2010, 12, 31, 0, 0).toInstant(ZoneOffset.UTC);
        Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
        Year test = Year.now(clock);
        assertEquals(test.getValue(), 2010);
    }
View Full Code Here


    //-----------------------------------------------------------------------
    // now(Clock)
    //-----------------------------------------------------------------------
    @Test
    public void now_Clock() {
        Instant instant = LocalDateTime.of(2010, 12, 31, 0, 0).toInstant(ZoneOffset.UTC);
        Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
        YearMonth test = YearMonth.now(clock);
        assertEquals(test.getYear(), 2010);
        assertEquals(test.getMonth(), Month.DECEMBER);
    }
View Full Code Here

            if (zone.normalized() instanceof ZoneOffset) {
                buf.append(zone.getId());
                return true;
            }
            Long epochSec = context.getTemporal().getLong(INSTANT_SECONDS);
            Instant instant;
            if (epochSec != null) {
                instant = Instant.ofEpochSecond(epochSec);
            } else {
                instant = Instant.ofEpochSecond(-200L * 365 * 86400)// about 1770
            }
View Full Code Here

    @SuppressWarnings({ "rawtypes", "unchecked" })
    public ChronoZonedDateTime<?> zonedDateTime(TemporalAccessor temporal) {
        try {
            ZoneId zone = ZoneId.from(temporal);
            try {
                Instant instant = Instant.from(temporal);
                return zonedDateTime(instant, zone);

            } catch (DateTimeException ex1) {
                ChronoLocalDateTime cldt = localDateTime(temporal);
                ChronoLocalDateTimeImpl cldtImpl = ensureChronoLocalDateTime(cldt);
View Full Code Here

      Map<String, Object> result2 = getDbConnector().getJdbcOperations().queryForMap(select1, 2);
      Map<String, Object> result3 = getDbConnector().getJdbcOperations().queryForMap(select1, 3);
      Timestamp tsIn1 = (Timestamp) result1.get("ver");
      Timestamp tsIn2 = (Timestamp) result2.get("ver");
      Timestamp tsIn3 = (Timestamp) result3.get("ver");
      Instant retrieved1 = DbDateUtils.fromSqlTimestamp(tsIn1);
      Instant retrieved2 = DbDateUtils.fromSqlTimestamp(tsIn2);
      Instant retrieved3 = DbDateUtils.fromSqlTimestamp(tsIn3);
      assertEquals(super.toString() + " Instant " + retrieved1, INSTANT1, retrieved1);
      assertEquals(super.toString() + " Instant " + retrieved2, INSTANT2, retrieved2);
      assertEquals(super.toString() + " Instant " + retrieved3, INSTANT3, retrieved3);
     
      // pull back the raw DB string form to ensure it actually stored UTC field values
View Full Code Here

  @Test(expectedExceptions = IllegalArgumentException.class)
  public void test_ReplaceVersion_noUid() {
    Clock origClock = _exgMaster.getClock();
    try {
      Instant now = Instant.now();

      ObjectId baseOid = setupTestData(now);
      _exgMaster.setClock(Clock.fixed(now.plus(2, HOURS), ZoneOffset.UTC));

      final ExternalIdBundle bundle = ExternalIdBundle.of("B", "B0");
      final ExternalIdBundle region = ExternalIdBundle.of("R", "R0");
      List<ExchangeDocument> replacement = newArrayList();
      for (int i = 0; i <= 2; i++) {
        ManageableExchange ex = new ManageableExchange(bundle, "replace_" + i, region, null);
        ExchangeDocument doc = new ExchangeDocument(ex);
        doc.setVersionFromInstant(now.plus(1, MINUTES).plus(i * 20, SECONDS));
        replacement.add(doc);
      }

      _exgMaster.replaceVersion(baseOid.atVersion("no such uid"), replacement);
    } finally {
View Full Code Here

 
  private ClasspathScanner _scanner = new ClasspathScanner();
 
  public void testTimestamp() {
    final ClasspathScanner scanner = new ClasspathScanner();
    final Instant instant = scanner.getTimestamp();
    assertNotNull(instant);
    assertTrue(instant.isAfter(Instant.EPOCH));
    assertFalse(Instant.now().isBefore(instant));
  }
View Full Code Here

  public void testSaveAndLoad() {
    final File temp = createTempFolder();
    try {
      System.setProperty(AnnotationCache.CACHE_PATH_PROPERTY, temp.toString());
      final Instant ts = Instant.now();
      AnnotationCache cache = AnnotationCache.create(ts, MockType.class, Arrays.asList(AnnotationCacheTest.class.getName()));
      cache.save();
      try {
        assertTrue(new File(temp, CACHE_FILE_NAME).exists());
        cache = AnnotationCache.load(MockType.class);
View Full Code Here

    if (str.charAt(0) != 'V' || posC < 0) {
      throw new IllegalArgumentException("Invalid identifier format: " + str);
    }
    String verStr = str.substring(1, posC);
    String corrStr = str.substring(posC + 2);
    Instant versionAsOf = parseInstantString(verStr);
    Instant correctedTo = parseInstantString(corrStr);
    return of(versionAsOf, correctedTo);
  }
View Full Code Here

   * @param correctedToString the corrected to string, null treated as latest
   * @return the version-correction combination, not null
   * @throws IllegalArgumentException if the version-correction cannot be parsed
   */
  public static VersionCorrection parse(String versionAsOfString, String correctedToString) {
    Instant versionAsOf = parseInstantString(versionAsOfString);
    Instant correctedTo = parseInstantString(correctedToString);
    return of(versionAsOf, correctedTo);
  }
View Full Code Here

TOP

Related Classes of org.threeten.bp.Instant

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.