예제 #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;
  }
예제 #2
0
 private static int timestamp(final LocalDateTime time) {
   return ((((((((((time.getYear() - 2015) & 3)) << 4) | time.getMonthValue()) << 5)
                       | time.getDayOfMonth())
                   << 5)
               | time.getHour())
           << 4)
       | (time.getMinute() / 4);
 }
예제 #3
0
 public static void main(String args[]) {
   LocalDateTime dt = LocalDateTime.of(1901, 1, 1, 0, 0);
   LocalDateTime stop = LocalDateTime.of(2000, 12, 31, 0, 0);
   int count = 0;
   while (dt.compareTo(stop) != 0) {
     if (dt.getDayOfMonth() == 1 && dt.getDayOfWeek() == DayOfWeek.SUNDAY) count++;
     dt = dt.plusDays(1);
   }
   System.out.println(count);
 }
 /**
  * Returns the actual delivered date in a nice string format
  *
  * @return the actual delivered date in a nice string format
  */
 public String actualDeliveryDateTimeToString() {
   LocalDateTime ldt = actualDeliveryDateTime.get();
   return "Date "
       + ldt.getYear()
       + "/"
       + ldt.getMonthValue()
       + "/"
       + ldt.getDayOfMonth()
       + "\nTime: "
       + String.format("%02d", ldt.getHour())
       + ":"
       + String.format("%02d", ldt.getMinute());
 }
예제 #5
0
 @Override
 public boolean solve(final Object solver, long res) {
   if ((res < (1L << 52)) && (solver != null)) {
     {
       final IDMap<Object> solvers = MappedDatabase.this.solvers;
       final int sid;
       synchronized (solvers) {
         if (solvers.containsKey(solver)) sid = solvers.get(solver);
         else {
           sid = solvers.map(solver);
           final LocalDateTime now = LocalDateTime.now();
           solverLog.printf(
               "%04d-%02d-%02d %02d:%02d SOLVER #%4d: %s\n",
               now.getYear(),
               now.getMonthValue(),
               now.getDayOfMonth(),
               now.getHour(),
               now.getMinute(),
               sid,
               solver);
         }
       }
       res |= (long) sid << 52;
     }
     final long spec = (getSpec() << 20) | timestamp(LocalDateTime.now());
     final LongBuffer db = MappedDatabase.this.db;
     final int idx = this.idx;
     synchronized (db) {
       if (((db.get(idx) ^ spec) >> 20) == 0L) {
         if (db.get(idx + 1) == 0L) {
           db.put(idx, spec);
           db.put(idx + 1, res);
         } else {
           final DataOutput dupStream = MappedDatabase.this.dupStream;
           if (dupStream != null) {
             try {
               dupStream.writeLong(spec);
               dupStream.writeLong(res);
             } catch (final Exception e) {
               System.err.printf(
                   "Duplicate result: %010X: %013X by %s\n", spec >>> 25, res, solver);
             }
           }
         }
         return true;
       }
     }
   }
   System.err.printf("Result report error: %010X: %013X by %s\n", getSpec() >>> 5, res, solver);
   return false;
 } // solve()
예제 #6
0
 @Test
 public void testGetDayOfMonth() {
   LocalDateTime today = LocalDateTime.now();
   assertEquals(today.getDayOfMonth(), getDayOfMonth(pack(today)));
 }
예제 #7
0
 private String getDay(LocalDateTime dt) {
   return dt.getDayOfMonth() + Constants.EMPTY;
 }