@Test public void testAsLocalDateTime() { LocalDateTime dateTime = LocalDateTime.now(); long packed = pack(dateTime.toLocalDate(), dateTime.toLocalTime()); LocalDateTime upacked = asLocalDateTime(packed); assertEquals(dateTime.getDayOfYear(), upacked.getDayOfYear()); assertEquals(dateTime.getHour(), upacked.getHour()); assertEquals(dateTime.getMinute(), upacked.getMinute()); assertEquals(dateTime.getSecond(), upacked.getSecond()); }
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); }
/** * 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()); }
@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()
public String getTimeSincePosted() { // returns difference in minutes between current time & time posted // (could be made much more specific) return LocalDateTime.now().minusMinutes(timePosted.getMinute()).toString(); }
@Test public void testGetMinute() { LocalDateTime now = LocalDateTime.now(); assertEquals(now.getMinute(), getMinute(pack(now))); }