@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 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()));
  }
 @Before
 public void createTestData() {
   int index = pvpLeagueIds.size();
   for (String league : pvpLeagueIds) {
     DateTime tim = new DateTime();
     tim.minusWeeks(index);
     index--;
     String userId = userIds.get(index);
     PvpLeagueForUser pvp =
         new PvpLeagueForUser(
             userId,
             league,
             index,
             index,
             tim.getMillis(),
             tim.getMillis(),
             index,
             index,
             index,
             index,
             tim.getMillis());
     repo.save(pvp);
     leagues.add(pvp);
     log.info("Saving: {}", pvp);
   }
 }
Exemple #4
0
  @Test
  public void shouldIncludeBothFromAndToDate_WhenGettingNumberOfDoses() {
    DateTime now = new DateTime(2011, 10, 3, 10, 0, 0, 0);
    final DateTime dosageStartTime = now.minusWeeks(1);
    final DateTime dosageEndTime = now.plusDays(1);
    Dosage dosage =
        new Dosage(
            new DosageResponse(
                "dosage_id",
                new Time(dosageStartTime.getHourOfDay(), dosageStartTime.getMinuteOfHour()),
                dosageStartTime.toLocalDate(),
                dosageEndTime.toLocalDate(),
                null,
                null));

    assertEquals(8, dosage.getDosesBetween(now.minusWeeks(1).toLocalDate(), now));
  }
Exemple #5
0
 public static Date getDateFromDateDesc(String leadTime) {
   DateTime dateTime = new DateTime(0, 12, 31, 0, 0, 0, 0);
   if (!Strings.isEmpty(leadTime)) {
     String time = "0";
     if (leadTime.indexOf(".") > 0) {
       time = leadTime.substring(0, leadTime.indexOf("."));
     } else {
       time = leadTime.substring(0, leadTime.length() - 1);
     }
     int timeVal = Integer.parseInt(time);
     if (leadTime.indexOf(DAY) >= 0) {
       if (timeVal > 0) {
         dateTime = dateTime.plusDays(timeVal);
       } else {
         dateTime = dateTime.minusDays(Math.abs(timeVal));
       }
     } else if (leadTime.indexOf(WEEK) >= 0) {
       if (timeVal > 0) {
         dateTime = dateTime.plusWeeks(timeVal);
       } else {
         dateTime = dateTime.minusWeeks(Math.abs(timeVal));
       }
     } else if (leadTime.indexOf(MONTH) >= 0) {
       if (timeVal > 0) {
         dateTime = dateTime.plusMonths(timeVal);
       } else {
         dateTime = dateTime.minusMonths(Math.abs(timeVal));
       }
     } else if (leadTime.indexOf(QUARTER) >= 0) {
       if (timeVal > 0) {
         dateTime = dateTime.plusMonths(timeVal * 3);
       } else {
         dateTime = dateTime.minusMonths(Math.abs(timeVal * 3));
       }
     } else if (leadTime.indexOf(YEAR) >= 0) {
       if (timeVal > 0) {
         dateTime = dateTime.plusYears(timeVal);
       } else {
         dateTime = dateTime.minusYears(Math.abs(timeVal));
       }
     }
     return dateTime.toDate();
   }
   return dateTime.toDate();
 }
Exemple #6
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;
  }