@Test
  public void niceTimeDeltaCanBeOutputInAlterativeLangauges() throws Exception {
    final DateTime now = DateTime.now().minusSeconds(1);

    DateTime lessThanOneMinuteAgo = now.minusSeconds(30);
    assertEquals("En este momento", spanishDateFormatter.timeSince(lessThanOneMinuteAgo.toDate()));

    DateTime oneMinuteAgo = now.minusSeconds(70);
    assertEquals("Hace 1 minuto", spanishDateFormatter.timeSince(oneMinuteAgo.toDate()));

    DateTime fiveMinutesBefore = now.minusMinutes(5);
    assertEquals("Hace 5 minutos", spanishDateFormatter.timeSince(fiveMinutesBefore.toDate()));

    DateTime anHourAgo = now.minusHours(1);
    assertEquals("Hace 1 hora", spanishDateFormatter.timeSince(anHourAgo.toDate()));

    DateTime twoHoursAgo = now.minusHours(2);
    assertEquals("Hace 2 horas", spanishDateFormatter.timeSince(twoHoursAgo.toDate()));

    DateTime oneDayAgo = now.minusDays(1);
    assertEquals("Hace 1 día", spanishDateFormatter.timeSince(oneDayAgo.toDate()));

    DateTime oneWeekAgo = now.minusWeeks(1).minusHours(1);
    assertEquals("Hace 1 semana", spanishDateFormatter.timeSince(oneWeekAgo.toDate()));

    DateTime nineMonthsAgo = now.minusMonths(9).minusWeeks(1);
    assertEquals("Hace 9 meses", spanishDateFormatter.timeSince(nineMonthsAgo.toDate()));
  }
 @Test
 public void testLastExecution() throws Exception {
   DateTime now = truncateToSeconds(DateTime.now());
   DateTime expected = truncateToSeconds(now.minusSeconds(1));
   ExecutionTime executionTime = ExecutionTime.forCron(quartzCronParser.parse(EVERY_SECOND));
   assertEquals(expected, executionTime.lastExecution(now));
 }
  @Test
  public void shouldBeAbleToOutputNiceTimeDeltas() throws Exception {
    final DateTime now = DateTime.now().minusSeconds(1);

    DateTime lessThanOneMinuteAgo = now.minusSeconds(30);
    assertEquals("just now", dateFormatter.timeSince(lessThanOneMinuteAgo.toDate()));

    DateTime fiveMinutesBefore = now.minusMinutes(5);
    assertEquals("5 minutes ago", dateFormatter.timeSince(fiveMinutesBefore.toDate()));

    DateTime anHourAgo = now.minusHours(1);
    assertEquals("1 hour ago", dateFormatter.timeSince(anHourAgo.toDate()));

    DateTime twoHoursAgo = now.minusHours(2);
    assertEquals("2 hours ago", dateFormatter.timeSince(twoHoursAgo.toDate()));

    DateTime oneDayAgo = now.minusDays(1);
    assertEquals("1 day ago", dateFormatter.timeSince(oneDayAgo.toDate()));

    DateTime oneWeekAgo = now.minusWeeks(1).minusHours(1);
    assertEquals("1 week ago", dateFormatter.timeSince(oneWeekAgo.toDate()));

    DateTime nineMonthsAgo = now.minusMonths(9).minusWeeks(1);
    assertEquals("9 months ago", dateFormatter.timeSince(nineMonthsAgo.toDate()));
  }
 @Test
 public void testTimeFromLastExecution() throws Exception {
   DateTime now = truncateToSeconds(DateTime.now());
   DateTime expected = truncateToSeconds(now.minusSeconds(1));
   ExecutionTime executionTime = ExecutionTime.forCron(quartzCronParser.parse(EVERY_SECOND));
   assertEquals(
       new Interval(expected, now).toDuration(), executionTime.timeFromLastExecution(now));
 }
Example #5
0
 /**
  * Provide nearest date for last execution.
  *
  * @param date - jodatime DateTime instance. If null, a NullPointerException will be raised.
  * @return DateTime instance, never null. Last execution time.
  */
 public DateTime lastExecution(DateTime date) {
   Validate.notNull(date);
   try {
     DateTime previousMatch = previousClosestMatch(date);
     if (previousMatch.equals(date)) {
       previousMatch = previousClosestMatch(date.minusSeconds(1));
     }
     return previousMatch;
   } catch (NoSuchValueException e) {
     throw new IllegalArgumentException(e);
   }
 }
  protected Pair<TimeSeriesDataItem, TimeSeriesDataItem> getBurndownScopedDataItemForDay(
      IterationHistoryEntry yesterdayEntry, IterationHistoryEntry todayEntry) {
    DateTime timestamp =
        todayEntry
            .getTimestamp()
            .toDateTimeAtCurrentTime()
            .minusMinutes(timeDifferenceMinutes)
            .toDateMidnight()
            .toDateTime()
            .plusSeconds(2);
    Second period = new Second(timestamp.toDate());

    long longValue = yesterdayEntry.getEffortLeftSum() + todayEntry.getDeltaOriginalEstimate();
    ExactEstimate scopedValue = new ExactEstimate(longValue);

    TimeSeriesDataItem nullItem =
        new TimeSeriesDataItem(new Second(timestamp.minusSeconds(1).toDate()), null);
    TimeSeriesDataItem scopedItem =
        new TimeSeriesDataItem(period, ExactEstimateUtils.extractMajorUnits(scopedValue));

    return Pair.create(nullItem, scopedItem);
  }
  public static void main(String[] args) {
    //
    // Creates an instance of current DateTime which represents the
    // current date time.
    //
    DateTime dateTime = new DateTime();
    System.out.println("DateTime = " + dateTime);

    //
    // Plus some hours, minutes, and seconds to the original DateTime.
    //
    System.out.println("Plus 1 hour is " + dateTime.plusHours(1));
    System.out.println("Plus 10 minutes is " + dateTime.plusMinutes(10));
    System.out.println("Plus 60 seconds is " + dateTime.plusSeconds(60));

    //
    // Minus some hours, minutes, and seconds to the original DateTime.
    //
    System.out.println("Minus 1 hour is " + dateTime.minusHours(1));
    System.out.println("Minus 10 minutes is " + dateTime.minusMinutes(10));
    System.out.println("Minus 60 seconds is " + dateTime.minusSeconds(60));
  }
Example #8
0
  /**
   * 计算指定时间之前的日期
   *
   * @param date 待计算时间
   * @param random 待计算数
   * @param timeType 时间类型枚举
   * @see org.codingsills.modules.utils.DateKit.TimeType
   * @return Date
   */
  public static Date preDate(Date date, int random, TimeType timeType) {
    Date preDate = null;
    if (date == null) {
      return preDate;
    }
    DateTime dateTime = fromDate(date);
    random = Math.abs(random);
    switch (timeType.getCode()) {
      case "Y":
        preDate = dateTime.minusYears(random).toDate();
        break;
      case "M":
        preDate = dateTime.minusMonths(random).toDate();
        break;
      case "W":
        preDate = dateTime.minusWeeks(random).toDate();
        break;
      case "D":
        preDate = dateTime.minusDays(random).toDate();
        break;
      case "H":
        preDate = dateTime.minusHours(random).toDate();
        break;
      case "MIN":
        preDate = dateTime.minusMinutes(random).toDate();
        break;
      case "S":
        preDate = dateTime.minusSeconds(random).toDate();
        break;
      case "MS":
        preDate = dateTime.minusMillis(random).toDate();
        break;
      default:
        break;
    }

    return preDate;
  }
Example #9
0
 public static Date minusSeconds(Date date, int numberOfSeconds) {
   if (date == null) date = new Date();
   DateTime dt = new DateTime(date);
   return dt.minusSeconds(numberOfSeconds).toDate();
 }
Example #10
0
 public static String computeTime(String dateString, String val, String timeUnit) {
   DateTime date = new DateTime();
   int value = 0;
   boolean isLong = false;
   if (!Strings.isEmpty(val) && !Strings.isEmpty(dateString) && !Strings.isEmpty(timeUnit)) {
     if (dateString.substring(dateString.indexOf("T") + 1, dateString.length()).length() == 0) {
       dateString = dateString + DEFAULT_TIME_FORMAT;
     }
     date = new DateTime(dateString);
     if (val.indexOf(".") > 0) {
       val = val.substring(0, val.indexOf("."));
     }
     Long l = new Long(val);
     if ((l.longValue() < 0 && -l.longValue() > 32768)
         || (l.longValue() > 0 && l.longValue() > 32768)) {
       isLong = true;
     }
     if (!isLong) {
       value = Integer.parseInt(val);
     }
     if (!Strings.isEmpty(timeUnit)) {
       if (timeUnit.equals("d")) {
         if (!isLong) {
           if (value > 0) {
             date = date.plusDays(value);
           } else {
             date = date.minusDays(-value);
           }
         } else {
           if (l.longValue() < 0) {
             date = date.minus(-l.longValue() * 24 * 60 * 60 * 1000);
           } else {
             date = date.plus(l.longValue() * 24 * 60 * 60 * 1000);
           }
         }
       } else if (timeUnit.equals(HOUR)) {
         if (!isLong) {
           if (value > 0) {
             date = date.plusHours(value);
           } else {
             date = date.minusHours(-value);
           }
         } else {
           if (l.longValue() < 0) {
             date = date.minus(-l.longValue() * 60 * 60 * 1000);
           } else {
             date = date.plus(l.longValue() * 60 * 60 * 1000);
           }
         }
       } else if (timeUnit.equals(MIN)) {
         if (!isLong) {
           if (value > 0) {
             date = date.plusMinutes(value);
           } else {
             date = date.minusMinutes(-value);
           }
         } else {
           if (l.longValue() < 0) {
             date = date.minus(-l.longValue() * 60 * 1000);
           } else {
             date = date.plus(l.longValue() * 60 * 1000);
           }
         }
       } else if (timeUnit.equals(SEC)) {
         if (!isLong) {
           if (value > 0) {
             date = date.plusSeconds(value);
           } else {
             date = date.minusSeconds(-value);
           }
         } else {
           if (l.longValue() < 0) {
             date = date.minus(-l.longValue() * 1000);
           } else {
             date = date.plus(l.longValue() * 1000);
           }
         }
       }
     }
   }
   return FormatUtils.formatDateTimeToISO(date.toDate());
 }