public void testConstructor_RI_RI2() throws Throwable {
   Instant dt1 = new Instant(new DateTime(2004, 6, 9, 0, 0, 0, 0));
   Instant dt2 = new Instant(new DateTime(2005, 7, 10, 1, 1, 1, 1));
   Interval test = new Interval(dt1, dt2);
   assertEquals(dt1.getMillis(), test.getStartMillis());
   assertEquals(dt2.getMillis(), test.getEndMillis());
 }
Ejemplo n.º 2
0
 public String toString(int granularity) throws TemporalException {
   return "("
       + startInstant.toString(granularity)
       + ", "
       + finishInstant.toString(granularity)
       + ")";
 } // toString
 // -----------------------------------------------------------------------
 public void testParse_noFormatter() throws Throwable {
   assertEquals(
       new DateTime(2010, 6, 30, 0, 20, ISOChronology.getInstance(LONDON)).toInstant(),
       Instant.parse("2010-06-30T01:20+02:00"));
   assertEquals(
       new DateTime(2010, 1, 2, 14, 50, ISOChronology.getInstance(LONDON)).toInstant(),
       Instant.parse("2010-002T14:50"));
 }
Ejemplo n.º 4
0
 private void orderCheck() throws TemporalException {
   if (startInstant.after(finishInstant, Temporal.FINEST))
     throw new TemporalException(
         "start must be before or equal to finish in a period: ("
             + startInstant.toString(Temporal.FINEST)
             + ", "
             + finishInstant.toString(Temporal.FINEST)
             + ")");
 } // orderCheck
 /** Test constructor (Object=null) */
 public void testConstructor_badconverterObject() throws Throwable {
   try {
     ConverterManager.getInstance().addInstantConverter(MockZeroNullIntegerConverter.INSTANCE);
     Instant test = new Instant(new Integer(0));
     assertEquals(ISOChronology.getInstanceUTC(), test.getChronology());
     assertEquals(0L, test.getMillis());
   } finally {
     ConverterManager.getInstance().removeInstantConverter(MockZeroNullIntegerConverter.INSTANCE);
   }
 }
  public void testConstructor_RP_RI2() throws Throwable {
    Instant dt = new Instant(new DateTime(TEST_TIME_NOW));
    Period dur = new Period(0, 6, 0, 3, 1, 0, 0, 0);
    long result = TEST_TIME_NOW;
    result = ISOChronology.getInstanceUTC().months().add(result, -6);
    result = ISOChronology.getInstanceUTC().days().add(result, -3);
    result = ISOChronology.getInstanceUTC().hours().add(result, -1);

    Interval test = new Interval(dur, dt);
    assertEquals(result, test.getStartMillis());
    assertEquals(dt.getMillis(), test.getEndMillis());
  }
Ejemplo n.º 7
0
 private boolean eventuallyUseBeginComplete() {
   if (data.containsKey(ItemCaract.BEGIN)
       && data.containsKey(ItemCaract.COMPLETED)
       && data.containsKey(ItemCaract.DURATION) == false) {
     final Instant i1 = (Instant) data.get(ItemCaract.BEGIN);
     final Instant i2 = (Instant) data.get(ItemCaract.COMPLETED);
     if (i2.compareTo(i1) <= 0) {
       throw new IllegalArgumentException();
     }
     data.put(ItemCaract.DURATION, math.diff(i1, i2));
     return true;
   }
   return false;
 }
Ejemplo n.º 8
0
 public DocumentReference copy() {
   DocumentReference dst = new DocumentReference();
   dst.masterIdentifier = masterIdentifier == null ? null : masterIdentifier.copy();
   dst.identifier = new ArrayList<Identifier>();
   for (Identifier i : identifier) dst.identifier.add(i.copy());
   dst.subject = subject == null ? null : subject.copy();
   dst.type = type == null ? null : type.copy();
   dst.subtype = subtype == null ? null : subtype.copy();
   dst.author = new ArrayList<ResourceReference>();
   for (ResourceReference i : author) dst.author.add(i.copy());
   dst.custodian = custodian == null ? null : custodian.copy();
   dst.authenticator = authenticator == null ? null : authenticator.copy();
   dst.created = created == null ? null : created.copy();
   dst.indexed = indexed == null ? null : indexed.copy();
   dst.status = status == null ? null : status.copy();
   dst.docStatus = docStatus == null ? null : docStatus.copy();
   dst.supercedes = supercedes == null ? null : supercedes.copy();
   dst.description = description == null ? null : description.copy();
   dst.confidentiality = confidentiality == null ? null : confidentiality.copy();
   dst.primaryLanguage = primaryLanguage == null ? null : primaryLanguage.copy();
   dst.mimeType = mimeType == null ? null : mimeType.copy();
   dst.format = format == null ? null : format.copy();
   dst.size = size == null ? null : size.copy();
   dst.hash = hash == null ? null : hash.copy();
   dst.location = location == null ? null : location.copy();
   dst.service = service == null ? null : service.copy(dst);
   dst.context = context == null ? null : context.copy(dst);
   return dst;
 }
Ejemplo n.º 9
0
  @Test
  public void testBasic() {
    System.out.println(Year.now());
    System.out.println(Year.of(2015));
    System.out.println(Year.isLeap(2016));

    Locale locale = Locale.getDefault();
    System.out.println(Month.DECEMBER.getDisplayName(TextStyle.FULL, locale));
    System.out.println(Month.DECEMBER.getDisplayName(TextStyle.SHORT, locale));
    System.out.println(Month.DECEMBER.getDisplayName(TextStyle.NARROW, locale));
    System.out.println(Month.DECEMBER.getDisplayName(TextStyle.FULL_STANDALONE, locale));
    System.out.println(Month.of(8).ordinal());
    System.out.println(Month.AUGUST.minus(2));

    System.out.println(YearMonth.now());
    System.out.println(MonthDay.now());

    System.out.println(DayOfWeek.FRIDAY.plus(2));
    System.out.println(DayOfWeek.of(1));
    System.out.println(
        DayOfWeek.from(LocalDateTime.ofInstant(Instant.now(), ZoneId.systemDefault())));

    System.out.println(Period.between(Year.now().atDay(1), LocalDate.now()));
    System.out.println(ChronoUnit.DAYS.between(Year.now().atDay(1), LocalDate.now()));
  }
Ejemplo n.º 10
0
  public Period(Temporal temporal, Instant startInstant, Instant finishInstant)
      throws TemporalException {
    int granularity;

    this.startInstant = new Instant(temporal, startInstant);
    this.finishInstant = new Instant(temporal, finishInstant);

    // Set granularity to finest of both.
    if (startInstant.getGranularity() > finishInstant.getGranularity())
      granularity = startInstant.getGranularity();
    else granularity = finishInstant.getGranularity();

    this.startInstant.setGranularity(granularity);
    this.finishInstant.setGranularity(granularity);

    orderCheck();
  } // Period
 public void testParse_formatter() throws Throwable {
   DateTimeFormatter f =
       DateTimeFormat.forPattern("yyyy--dd MM HH")
           .withChronology(ISOChronology.getInstance(PARIS));
   assertEquals(
       new DateTime(2010, 6, 30, 13, 0, ISOChronology.getInstance(PARIS)).toInstant(),
       Instant.parse("2010--30 06 13", f));
 }
Ejemplo n.º 12
0
 public SecurityEventEventComponent copy(SecurityEvent e) {
   SecurityEventEventComponent dst = e.new SecurityEventEventComponent();
   dst.type = type == null ? null : type.copy();
   dst.subtype = new ArrayList<CodeableConcept>();
   for (CodeableConcept i : subtype) dst.subtype.add(i.copy());
   dst.action = action == null ? null : action.copy();
   dst.dateTime = dateTime == null ? null : dateTime.copy();
   dst.outcome = outcome == null ? null : outcome.copy();
   dst.outcomeDesc = outcomeDesc == null ? null : outcomeDesc.copy();
   return dst;
 }
Ejemplo n.º 13
0
  public Period intersection(Period p2, int granularity) throws TemporalException {
    Period result;

    if (startInstant.equals(p2.getStartInstant(), granularity)) { // They must intersect
      if (finishInstant.after(p2.getFinishInstant(), granularity)) {
        result = new Period(temporal, startInstant, p2.getFinishInstant(), granularity);
      } else {
        result = new Period(temporal, startInstant, finishInstant, granularity);
      } // if
    } else if (startInstant.before(
        p2.getStartInstant(), granularity)) { // p2 starts after this Period
      if (finishInstant.after(p2.getStartInstant(), granularity)) { // They intersect
        if (finishInstant.before(p2.getFinishInstant(), granularity)) {
          result = new Period(temporal, p2.getStartInstant(), finishInstant, granularity);
        } else {
          result = new Period(temporal, p2.getStartInstant(), p2.getFinishInstant(), granularity);
        } // if
      } else {
        result = null;
      } // if
    } else { // p2 start before this Period
      if (p2.getFinishInstant().after(startInstant, granularity)) { // They intersect
        if (finishInstant.before(p2.getFinishInstant(), granularity)) {
          result = new Period(temporal, startInstant, finishInstant, granularity);
        } else {
          result = new Period(temporal, startInstant, p2.getFinishInstant(), granularity);
        } // if
      } else {
        result = null;
      } // if
    } // if

    return result;
  } // intersection
Ejemplo n.º 14
0
  @Test
  public void testLocalDateTime() {
    System.out.println(LocalDateTime.now());
    System.out.println(LocalDateTime.of(1994, Month.MAY, 15, 11, 30));
    System.out.println(LocalDateTime.ofInstant(Instant.now(), ZoneId.systemDefault()));
    System.out.println(LocalDateTime.ofEpochSecond(1450749600, 0, ZoneOffset.ofHours(8)));

    System.out.printf("6 months from now: %s%n", LocalDateTime.now().plusMonths(6));
    System.out.printf("6 days ago: %s%n", LocalDateTime.now().minusDays(6));

    System.out.println(DateTimeFormatter.ISO_DATE_TIME.format(LocalDateTime.now()));
    System.out.println(DateTimeFormatter.ofPattern("MM-dd HH:mm").format(LocalDateTime.now()));
  }
Ejemplo n.º 15
0
  public static void main(String[] args) {
    ZonedDateTime apollo11launch =
        ZonedDateTime.of(1969, 7, 16, 9, 32, 0, 0, ZoneId.of("America/New_York"));
    // 1969-07-16T09:32-04:00[America/New_York]
    System.out.println("apollo11launch: " + apollo11launch);

    Instant instant = apollo11launch.toInstant();
    System.out.println("instant: " + instant);

    ZonedDateTime zonedDateTime = instant.atZone(ZoneId.of("UTC"));
    System.out.println("zonedDateTime: " + zonedDateTime);

    ZonedDateTime skipped =
        ZonedDateTime.of(
            LocalDate.of(2013, 3, 31), LocalTime.of(2, 30), ZoneId.of("Europe/Berlin"));
    // Constructs March 31 3:30
    System.out.println("skipped: " + skipped);

    ZonedDateTime ambiguous =
        ZonedDateTime.of(
            LocalDate.of(2013, 10, 27), // End of daylight savings time
            LocalTime.of(2, 30),
            ZoneId.of("Europe/Berlin"));
    // 2013-10-27T02:30+02:00[Europe/Berlin]
    ZonedDateTime anHourLater = ambiguous.plusHours(1);
    // 2013-10-27T02:30+01:00[Europe/Berlin]
    System.out.println("ambiguous: " + ambiguous);
    System.out.println("anHourLater: " + anHourLater);

    ZonedDateTime meeting =
        ZonedDateTime.of(
            LocalDate.of(2013, 10, 31), LocalTime.of(14, 30), ZoneId.of("America/Los_Angeles"));
    System.out.println("meeting: " + meeting);
    ZonedDateTime nextMeeting = meeting.plus(Duration.ofDays(7));
    // Caution! Won’t work with daylight savings time
    System.out.println("nextMeeting: " + nextMeeting);
    nextMeeting = meeting.plus(Period.ofDays(7)); // OK
    System.out.println("nextMeeting: " + nextMeeting);
  }
Ejemplo n.º 16
0
  public static void main(String[] args) {
    DecimalFormat decimalFormat = new DecimalFormat("00");
    System.out.println(decimalFormat.format(7));

    //        f3();

    Instant timestamp = Instant.ofEpochMilli(System.currentTimeMillis());
    System.out.println(timestamp);

    Instant current = Clock.system(ZoneId.of("Asia/Shanghai")).instant();
    System.out.println(ZoneId.of("Asia/Shanghai").getRules());
    System.out.println(current);
    //        System.out.println(System.currentTimeMillis());
    //        System.out.println(Instant.now().getEpochSecond());
  }
  public static ZonedDateTime getNextSchedule() {
    ZonedDateTime next_schedule;

    // Determine type of schedule
    if (ConfigHandler.backupInterval > 0) // Interval
    {
      next_schedule =
          ZonedDateTime.ofInstant(
              Instant.ofEpochMilli(
                  System.currentTimeMillis() + (ConfigHandler.backupInterval * 60 * 1000)),
              ZoneId.systemDefault());
    } else // Schedule
    {
      if (ConfigHandler.backupSchedule.length == 0) {
        return null;
      }

      LocalTime now = LocalTime.now();
      LocalTime next_time = null;
      LocalDate day = LocalDate.now();
      TreeSet<LocalTime> times = new TreeSet<>();

      for (String s : ConfigHandler.backupSchedule) {
        times.add(LocalTime.parse(s, DateTimeFormatter.ofPattern("H:mm")));
      }

      for (LocalTime t : times) // try to find next scheduled time for today
      {
        if (t.compareTo(now) == 1) {
          next_time = t;
          break;
        }
      }

      if (next_time
          == null) // if we couldn't find one for today take the first schedule time for tomorrow
      {
        day = day.plusDays(1);
        next_time = times.first();
      }

      next_schedule = ZonedDateTime.of(day, next_time, ZoneId.systemDefault());
    }

    return next_schedule;
  }
Ejemplo n.º 18
0
  public Period merge(Period p2, int granularity) throws TemporalException {
    Instant resultStartInstant, resultFinishInstant;
    Period result;

    if ((intersection(p2, granularity) == null) && (!adjacent(p2, granularity)))
      throw new TemporalException(
          "start must be before or equal to the finish in a period: ('"
              + toString(granularity)
              + "'), ('"
              + p2.toString(granularity)
              + "')");

    if (startInstant.before(p2.getStartInstant(), granularity)) resultStartInstant = startInstant;
    else resultStartInstant = p2.getStartInstant();

    if (getFinishInstant().before(p2.getFinishInstant(), granularity))
      resultFinishInstant = p2.getFinishInstant();
    else resultFinishInstant = finishInstant;

    result = new Period(temporal, resultStartInstant, resultFinishInstant, granularity);

    return result;
  } // merge
Ejemplo n.º 19
0
 public String getFinishDatetime(int granularity) throws TemporalException {
   return finishInstant.getDatetimeString(granularity);
 } // getFinishDatetime
Ejemplo n.º 20
0
 public java.util.Date getFinishDate(int granularity) throws TemporalException {
   return finishInstant.getUtilDate(granularity);
 } // getFinishDate
 /** Test now () */
 public void test_now() throws Throwable {
   Instant test = Instant.now();
   assertEquals(ISOChronology.getInstanceUTC(), test.getChronology());
   assertEquals(TEST_TIME_NOW, test.getMillis());
 }
Ejemplo n.º 22
0
 public long getStartGranuleCount(int granularity) throws TemporalException {
   return startInstant.getGranuleCount(granularity);
 } // getStartGranuleCount
 /** Test constructor (Object=null) */
 public void testConstructor_nullObject() throws Throwable {
   Instant test = new Instant((Object) null);
   assertEquals(ISOChronology.getInstanceUTC(), test.getChronology());
   assertEquals(TEST_TIME_NOW, test.getMillis());
 }
 /** Test constructor (Object) */
 public void testConstructor_Object() throws Throwable {
   Date date = new Date(TEST_TIME1);
   Instant test = new Instant(date);
   assertEquals(ISOChronology.getInstanceUTC(), test.getChronology());
   assertEquals(TEST_TIME1, test.getMillis());
 }
 /** Test constructor (long) */
 public void testConstructor_long2() throws Throwable {
   Instant test = new Instant(TEST_TIME2);
   assertEquals(ISOChronology.getInstanceUTC(), test.getChronology());
   assertEquals(TEST_TIME2, test.getMillis());
 }
Ejemplo n.º 26
0
 public long getFinishGranuleCount(int granularity) throws TemporalException {
   return finishInstant.getGranuleCount(granularity);
 } // getFinishGranuleCount
Ejemplo n.º 27
0
 public boolean couldBeInstant() throws TemporalException {
   return startInstant.equals(finishInstant, Temporal.FINEST);
 } // couldBeInstant
Ejemplo n.º 28
0
 public int getGranularity() {
   return startInstant.getGranularity(); // start and finish instant have same granularity.
 } // getGranularity
Ejemplo n.º 29
0
 public Period(Temporal temporal, Instant instant) throws TemporalException {
   this(temporal, instant, instant, instant.getGranularity());
 } // Period
Ejemplo n.º 30
0
 @Test
 public void testInstant() {
   LOG.info("now = {}", Instant.now());
   LOG.info("4 minutes later = {}", Instant.now().plus(4, ChronoUnit.MINUTES));
   LOG.info("millis = {}", Instant.now().toEpochMilli());
 }