예제 #1
0
  public static String getTimeUntilNow(String time) {
    LocalDateTime now = LocalDateTime.now();
    now = now.plusMinutes(1);

    int hours = Integer.parseInt(time.split(":")[0]);
    int minutes = Integer.parseInt(time.split(":")[1]);

    LocalDateTime tocheck =
        LocalDateTime.of(
            now.getYear(),
            now.getMonth(),
            now.getDayOfMonth(),
            hours,
            minutes,
            now.getSecond(),
            now.getNano());

    if (tocheck.isBefore(now)) {
      tocheck = tocheck.plusDays(1);
    }

    Duration remaining = Duration.between(now, tocheck);

    int rh = (int) remaining.toHours();
    int rm = (int) remaining.toMinutes();
    rm %= 60;

    int ht = rh / 10;
    int hs = rh % 10;
    int mt = rm / 10;
    int ms = rm % 10;

    return ht + "" + hs + ":" + mt + "" + ms;
  }
 @Test
 public void should_fail_if_actual_is_not_equal_to_given_localdatetime_with_second_ignored() {
   try {
     assertThat(refLocalDateTime).isEqualToIgnoringSeconds(refLocalDateTime.plusMinutes(1));
   } catch (AssertionError e) {
     assertThat(e.getMessage())
         .isEqualTo(
             format(
                 "%nExpecting:%n  <2000-01-01T23:51>%nto have same year, month, day, hour and minute as:%n  <2000-01-01T23:52>%nbut had not."));
     return;
   }
   failBecauseExpectedAssertionErrorWasNotThrown();
 }
예제 #3
0
 /*
 ---
    ----
 */
 @Test
 public void testAbuts_false2() {
   TimeInterval arg = TimeInterval.between(baseEnd, baseEnd.plusMinutes(10));
   assertFalse(baseInterval.abuts(arg));
 }
예제 #4
0
 // baseInterval始点と終点に、引数のminutes分それぞれ加算したインスタンスを返す
 private TimeInterval createArg(int start, int end) {
   return TimeInterval.between(baseStart.plusMinutes(start), baseEnd.plusMinutes(end));
 }
예제 #5
0
 /*
     ---
 ----
 */
 @Test
 public void testAbuts_false4() {
   TimeInterval arg = TimeInterval.between(baseStart.plusMinutes(-10), baseStart);
   assertFalse(baseInterval.abuts(arg));
 }
예제 #6
0
 public static String calcDate(int time) {
   LocalDateTime ldt = EPOCH.plusMinutes((long) time);
   return ldt.toString();
 }