/** * Returns the minute of this date time. * @return the minute (0-59) */ public int getMinute() { int sec = DateUtil.getSecondOfDay(elapsedSeconds); return sec / 60 % 60; }
/** * Returns the hour of this date time. * @return the hour (0-23) */ public int getHour() { int sec = DateUtil.getSecondOfDay(elapsedSeconds); return sec / (60 * 60); }
/** * Returns the second of this date time. * @return the second (0-59) */ public int getSecond() { int sec = DateUtil.getSecondOfDay(elapsedSeconds); return sec % 60; }
/** * Returns the nano time of the julian day. * @param dateTime the date time * @return the nano time of julian day * @since 0.7.2 */ public static long getTimeOfDayNanos(DateTime dateTime) { long julianSeconds = toJulianSecond(dateTime.getElapsedSeconds()); return TimeUnit.SECONDS.toNanos(DateUtil.getSecondOfDay(julianSeconds)); }
/** * Returns the nano time of the julian day. * @param date the day * @return the nano time of julian day * @since 0.7.2 */ public static long getTimeOfDayNanos(Date date) { long julianSeconds = toJulianSecond(TimeUnit.DAYS.toSeconds(date.getElapsedDays())); return TimeUnit.SECONDS.toNanos(DateUtil.getSecondOfDay(julianSeconds)); }
/** * Appends a string representation of {@link DateTime}. * @param elapsedSeconds the number of elapsed seconds from 0001/01/01 00:00:00 * @param dateSegmentSeparator the separator char between each date segment * @param dateTimeSeparator the separator char between date and time * @param timeSegmentSeparator the separator char between each time segment * @param target the target buffer * @since 0.7.0 */ public static void toDateTimeString( long elapsedSeconds, char dateSegmentSeparator, char dateTimeSeparator, char timeSegmentSeparator, StringBuilder target) { appendDateString(target, DateUtil.getDayFromSeconds(elapsedSeconds), dateSegmentSeparator); target.append(dateTimeSeparator); appendTimeString(target, DateUtil.getSecondOfDay(elapsedSeconds), timeSegmentSeparator); }
/** * Converts the number of elapsed seconds from {@code 0001/01/01 (YYYY/MM/DD) 00:00:00} to the corresponded date, * and set it to the target calendar object. * Note that, the millisecond fields will be set to {@code 0}. * @param seconds the number of elapsed seconds * @param calendar the target calendar object * @since 0.2.2 */ public static void setSecondToCalendar(long seconds, Calendar calendar) { int days = getDayFromSeconds(seconds); int year = getYearFromDay(days); int daysInYear = days - getDayFromYear(year); boolean leap = isLeap(year); int month = getMonthOfYear(daysInYear, leap); int day = getDayOfMonth(daysInYear, leap); int rest = getSecondOfDay(seconds); int hour = rest / (60 * 60); int minute = rest / 60 % 60; int second = rest % 60; calendar.set(year, month - 1, day, hour, minute, second); calendar.set(Calendar.MILLISECOND, 0); }
@Override public void emit(DateTimeOption option) throws IOException { startCell(); if (emitNull(option)) { return; } long seconds = option.get().getElapsedSeconds(); int days = DateUtil.getDayFromSeconds(seconds); emitDate(days); lineBuffer.append(DATE_TIME_SEPARATOR); int sec = DateUtil.getSecondOfDay(seconds); emitTime(sec); }
@Override CharSequence format(long elapsedSeconds) { int elapsedDate = DateUtil.getDayFromSeconds(elapsedSeconds); int year = DateUtil.getYearFromDay(elapsedDate); int dayInYear = elapsedDate - DateUtil.getDayFromYear(year); int month = DateUtil.getMonthOfYear(dayInYear, DateUtil.isLeap(year)); int day = DateUtil.getDayOfMonth(dayInYear, DateUtil.isLeap(year)); int secondOfDay = DateUtil.getSecondOfDay(elapsedSeconds); int hour = secondOfDay / (60 * 60); int minute = secondOfDay / 60 % 60; int second = secondOfDay % 60; putStringValue(buffer, year, POS_YEAR, 4); putStringValue(buffer, month, POS_MONTH, 2); putStringValue(buffer, day, POS_DAY, 2); putStringValue(buffer, hour, POS_HOUR, 2); putStringValue(buffer, minute, POS_MINUTE, 2); putStringValue(buffer, second, POS_SECOND, 2); return buffer; }
@Override void emit(long elapsedSeconds, StringBuilder output) { int elapsedDate = DateUtil.getDayFromSeconds(elapsedSeconds); int year = DateUtil.getYearFromDay(elapsedDate); int dayInYear = elapsedDate - DateUtil.getDayFromYear(year); int month = DateUtil.getMonthOfYear(dayInYear, DateUtil.isLeap(year)); int day = DateUtil.getDayOfMonth(dayInYear, DateUtil.isLeap(year)); int secondOfDay = DateUtil.getSecondOfDay(elapsedSeconds); int hour = secondOfDay / (60 * 60); int minute = secondOfDay / 60 % 60; int second = secondOfDay % 60; append(output, year, 4); append(output, month, 2); append(output, day, 2); append(output, hour, 2); append(output, minute, 2); append(output, second, 2); } }
@Override void emit(long elapsedSeconds, StringBuilder output) { int elapsedDate = DateUtil.getDayFromSeconds(elapsedSeconds); int year = DateUtil.getYearFromDay(elapsedDate); int dayInYear = elapsedDate - DateUtil.getDayFromYear(year); int month = DateUtil.getMonthOfYear(dayInYear, DateUtil.isLeap(year)); int day = DateUtil.getDayOfMonth(dayInYear, DateUtil.isLeap(year)); int secondOfDay = DateUtil.getSecondOfDay(elapsedSeconds); int hour = secondOfDay / (60 * 60); int minute = secondOfDay / 60 % 60; int second = secondOfDay % 60; append(output, year, 4); append(output, month, 2); append(output, day, 2); append(output, hour, 2); append(output, minute, 2); append(output, second, 2); } }