/** * Returns the year of this date and time. * @return the year (1-) */ public int getYear() { int days = DateUtil.getDayFromSeconds(elapsedSeconds); return DateUtil.getYearFromDay(days); }
@SuppressWarnings("deprecation") @Override void addNanoTime(int julianDay, long nanoTime) { long seconds = TemporalUtil.toElapsedSeconds(julianDay, nanoTime); target.modify(DateUtil.getDayFromSeconds(seconds)); } }
/** * 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); }
/** * Returns the month of this date and time. * @return the month (1-12) */ public int getMonth() { int days = DateUtil.getDayFromSeconds(elapsedSeconds); int year = getYear(); int dayInYear = days - DateUtil.getDayFromYear(year); return DateUtil.getMonthOfYear(dayInYear, DateUtil.isLeap(year)); }
/** * Returns the day of this date and time. * @return the day (1-31) */ public int getDay() { int year = getYear(); int days = DateUtil.getDayFromSeconds(elapsedSeconds); int dayInYear = days - DateUtil.getDayFromYear(year); return DateUtil.getDayOfMonth(dayInYear, DateUtil.isLeap(year)); }
/** * 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 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); } }
@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; }