@Test
 public void testDateTimeSerialization() throws Exception {
   final String date =
       CharMatcher.anyOf("\"").removeFrom(mapper.writeValueAsString(expectedDateTime));
   assertEquals(TIME1, date);
   final DateTime dt2 = mapper.readValue(quoted(date), DateTime.class);
   assertEquals(expectedDateTime.toInstant(), dt2.toInstant());
 }
 @Test
 public void testTransitive_instantApiJoda() {
   assertEquals(
       jodaDateTime1,
       DateTimes.toDateTime(DateTimes.toDateTime(jodaDateTime1.toInstant(), TIME_ZONE_ID1)));
   assertEquals(
       jodaDateTime2,
       DateTimes.toDateTime(DateTimes.toDateTime(jodaDateTime2.toInstant(), TIME_ZONE_ID2)));
   assertEquals(
       jodaDateTime3,
       DateTimes.toDateTime(DateTimes.toDateTime(jodaDateTime3.toInstant(), TIME_ZONE_ID3)));
 }
  public SortedMap<User, Time> getWorkReport(DateTime from, DateTime to, Project project) {
    SortedMap<User, Time> out = new TreeMap<User, Time>();

    for (User user : project.getUsers()) {
      Time totalTime = new Time(0);

      for (Work work : getWorks(user)) {
        if (work.getIssue().getProject().equals(project)
            && work.getDate().isAfter(from.toInstant())
            && work.getDate().isBefore(to.toInstant())) totalTime.add(work.getDedicatedTime());
      }

      if (totalTime.getMinutes() > 0) out.put(user, totalTime);
    }

    return out;
  }
Exemplo n.º 4
0
 /** Get the date of the last modification of posts in the current topic. */
 public DateTime getLastModificationPostDate() {
   DateTime newTopicModificationDate = getFirstPost().getLastTouchedDate();
   for (Post post : posts) {
     if (post.getLastTouchedDate().isAfter(newTopicModificationDate.toInstant())) {
       newTopicModificationDate = post.getLastTouchedDate();
     }
   }
   return newTopicModificationDate;
 }
Exemplo n.º 5
0
 /**
  * Calculates modification date of topic taking it as last post in topic creation date. Used after
  * deletion of the post. It is necessary to save the sort order of topics in the future.
  */
 public void recalculateModificationDate() {
   DateTime newTopicModificationDate = getFirstPost().getCreationDate();
   for (Post post : posts) {
     if (post.getCreationDate().isAfter(newTopicModificationDate.toInstant())) {
       newTopicModificationDate = post.getCreationDate();
     }
   }
   modificationDate = newTopicModificationDate;
 }
Exemplo n.º 6
0
  public void testFactory_Zone_RI() {
    GJChronology chrono = GJChronology.getInstance(TOKYO, new Instant(0L));
    assertEquals(TOKYO, chrono.getZone());
    assertEquals(new Instant(0L), chrono.getGregorianCutover());
    assertSame(GJChronology.class, GJChronology.getInstance(TOKYO, new Instant(0L)).getClass());

    DateTime cutover = new DateTime(1582, 10, 15, 0, 0, 0, 0, DateTimeZone.UTC);
    chrono = GJChronology.getInstance(TOKYO, null);
    assertEquals(TOKYO, chrono.getZone());
    assertEquals(cutover.toInstant(), chrono.getGregorianCutover());
  }
Exemplo n.º 7
0
 public User completePasswordReset(String newPassword, String key) {
   log.debug("Reset user password for reset key {}", key);
   User user = userRepository.findOneByResetKey(key);
   DateTime oneDayAgo = DateTime.now().minusHours(24);
   if (user != null && user.getActivated()) {
     if (user.getResetDate().isAfter(oneDayAgo.toInstant().getMillis())) {
       user.setPassword(passwordEncoder.encode(newPassword));
       user.setResetKey(null);
       user.setResetDate(null);
       userRepository.save(user);
       return user;
     } else {
       return null;
     }
   }
   return null;
 }
Exemplo n.º 8
0
  public Optional<User> completePasswordReset(String newPassword, String key) {
    log.debug("Reset user password for reset key {}", key);

    return userRepository
        .findOneByResetKey(key)
        .filter(
            user -> {
              DateTime oneDayAgo = DateTime.now().minusHours(24);
              return user.getResetDate().isAfter(oneDayAgo.toInstant().getMillis());
            })
        .map(
            user -> {
              user.setPassword(passwordEncoder.encode(newPassword));
              user.setResetKey(null);
              user.setResetDate(null);
              userRepository.save(user);
              return user;
            });
  }
Exemplo n.º 9
0
  public void testFactory_Zone_RI_int() {
    GJChronology chrono = GJChronology.getInstance(TOKYO, new Instant(0L), 2);
    assertEquals(TOKYO, chrono.getZone());
    assertEquals(new Instant(0L), chrono.getGregorianCutover());
    assertEquals(2, chrono.getMinimumDaysInFirstWeek());
    assertSame(GJChronology.class, GJChronology.getInstance(TOKYO, new Instant(0L), 2).getClass());

    DateTime cutover = new DateTime(1582, 10, 15, 0, 0, 0, 0, DateTimeZone.UTC);
    chrono = GJChronology.getInstance(TOKYO, null, 2);
    assertEquals(TOKYO, chrono.getZone());
    assertEquals(cutover.toInstant(), chrono.getGregorianCutover());
    assertEquals(2, chrono.getMinimumDaysInFirstWeek());

    try {
      GJChronology.getInstance(TOKYO, new Instant(0L), 0);
      fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
      GJChronology.getInstance(TOKYO, new Instant(0L), 8);
      fail();
    } catch (IllegalArgumentException ex) {
    }
  }
 @Test
 public void testToDateTime_fromInstantToApiDateTime() {
   assertEquals(apiDateTime1, DateTimes.toDateTime(jodaDateTime1.toInstant(), TIME_ZONE_ID1));
   assertEquals(apiDateTime2, DateTimes.toDateTime(jodaDateTime2.toInstant(), TIME_ZONE_ID2));
   assertEquals(apiDateTime3, DateTimes.toDateTime(jodaDateTime3.toInstant(), TIME_ZONE_ID3));
 }
Exemplo n.º 11
0
 @Override
 public Instant convert(DateTime source) {
   return source.toInstant();
 }
Exemplo n.º 12
0
 public <R extends AbstractResource<?>> void isSameTime(Collection<R> newResources, DateTime dt) {
   Validate.noNullElements(new Object[] {newResources, dt});
   for (R resource : newResources) {
     Validate.isTrue(dt.toInstant().getMillis() == resource.getTimeDetected().getTime());
   }
 }