// Not generally a good idea to focus on integers for working with date-time, but you asked for it. DateTime someDateTime = new DateTime( 1234567898765L, DateTimeZone.UTC ); System.out.println( "Set Value of 1234567898765L is: " + someDateTime ); System.out.println( "Year is " + someDateTime.year().getAsText( locale ) ); System.out.println( "Month is " + someDateTime.monthOfYear().getAsText( locale ) ); System.out.println( "Day of month is " + someDateTime.dayOfMonth().getAsText( locale ) ); System.out.println( "Day of week is " + someDateTime.dayOfWeek().getAsText( locale ) ); System.out.println( "Day of year is " + someDateTime.dayOfYear().getAsText( locale ) );
/** * Calculates, and returns, a date representing the first day of the year * relative to the current date. */ public Date startOfYear() { return new Date(date.dayOfYear().withMinimumValue()); }
/** * Calculates, and returns, a date representing the first day of the year * relative to the current date. */ public Date startOfYear() { return new Date(date.dayOfYear().withMinimumValue()); }
public int getNDaysInYear() { return value.dayOfYear().withMaximumValue().getDayOfYear(); }
holidaysFrom = holidaysFrom.dayOfYear().withMinimumValue().millisOfDay().withMinimumValue().minusYears(2); final DateTime holidayTo = holidaysFrom.plusYears(6); DateMidnight day = new DateMidnight(holidaysFrom);
public DateTime parseDate(final YDate yDate) throws InvalidDateException { DateTime parsedDate; try { parsedDate = new DateTime(yDate.getYear(), yDate.getMonth() > 0 ? yDate.getMonth() : 1, yDate.getDay() > 0 ? yDate.getDay() : 1, 0, 0, DateTimeZone.UTC); } catch (IllegalFieldValueException e) { throw new InvalidDateException("Incorrect values in YDates.", e); } if (yDate.getDay() == 0) { parsedDate = parsedDate.dayOfMonth().withMinimumValue(); } if (yDate.getMonth() == 0) { parsedDate = parsedDate.dayOfYear().withMinimumValue(); } return parsedDate; }
@Override public DateTime getPreviousAccrualIntervalDate(String earnInterval, DateTime aDate) { DateTime previousAccrualIntervalDate = null; AccrualEarnInterval accrualEarnInterval = AccrualEarnInterval.fromCode(earnInterval); if (AccrualEarnInterval.DAILY.equals(accrualEarnInterval)) { previousAccrualIntervalDate = aDate.minusDays(1); } else if(AccrualEarnInterval.WEEKLY.equals(accrualEarnInterval)) { previousAccrualIntervalDate = aDate.minusWeeks(1).withDayOfWeek(DateTimeConstants.SATURDAY); } else if (AccrualEarnInterval.SEMI_MONTHLY.equals(accrualEarnInterval)) { previousAccrualIntervalDate = aDate.minusDays(15); if (previousAccrualIntervalDate.getDayOfMonth() <= 15) { previousAccrualIntervalDate = previousAccrualIntervalDate.withDayOfMonth(15); } else { previousAccrualIntervalDate = previousAccrualIntervalDate.withDayOfMonth(previousAccrualIntervalDate.dayOfMonth().getMaximumValue()); } } else if (AccrualEarnInterval.MONTHLY.equals(accrualEarnInterval)) { previousAccrualIntervalDate = aDate.minusMonths(1); previousAccrualIntervalDate = previousAccrualIntervalDate.withDayOfMonth(previousAccrualIntervalDate.dayOfMonth().getMaximumValue()); } else if (AccrualEarnInterval.YEARLY.equals(accrualEarnInterval)) { previousAccrualIntervalDate = aDate.minusYears(1); previousAccrualIntervalDate = previousAccrualIntervalDate.withDayOfYear(previousAccrualIntervalDate.dayOfYear().getMaximumValue()); } else if (AccrualEarnInterval.NO_ACCRUAL.equals(accrualEarnInterval)) { previousAccrualIntervalDate = aDate; } return previousAccrualIntervalDate; }
nextAccrualIntervalDate = aDate.withDayOfMonth(aDate.dayOfMonth().getMaximumValue()); } else if (AccrualEarnInterval.YEARLY.equals(accrualEarnInterval)) { nextAccrualIntervalDate = aDate.withDayOfYear(aDate.dayOfYear().getMaximumValue()); } else if (AccrualEarnInterval.NO_ACCRUAL.equals(accrualEarnInterval)) { nextAccrualIntervalDate = aDate;
public DateTime maxDateTime(DateTime dateTime) { switch (this) { case YEAR: return dateTime.dayOfYear().withMaximumValue() .secondOfDay().withMaximumValue(); case QUARTER: // TODO: case MONTH: return dateTime.dayOfMonth().withMaximumValue() .secondOfDay().withMaximumValue(); case DAY: return dateTime.secondOfDay().withMaximumValue(); case HOUR: return dateTime.minuteOfHour().withMaximumValue() .secondOfMinute().withMaximumValue(); case MINUTE: case SECOND: return dateTime.secondOfMinute().withMaximumValue(); } return dateTime; }
@Override public int getWorkDaysInAccrualInterval(String earnInterval, DateTime aDate) { AccrualEarnInterval accrualEarnInterval = AccrualEarnInterval.fromCode(earnInterval); if (accrualEarnInterval != null) { if(AccrualEarnInterval.DAILY.equals(accrualEarnInterval)) { return 1; } else if(AccrualEarnInterval.WEEKLY.equals(accrualEarnInterval)) { return 5; } else if (AccrualEarnInterval.SEMI_MONTHLY.equals(accrualEarnInterval)) { if(aDate.getDayOfMonth() <= 15) { return TKUtils.getWorkDays(aDate.withDayOfMonth(1), aDate.withDayOfMonth(15)); } else { return TKUtils.getWorkDays(aDate.withDayOfMonth(16), aDate.withDayOfMonth(aDate.dayOfMonth().getMaximumValue())); } } else if (AccrualEarnInterval.MONTHLY.equals(accrualEarnInterval)) { return TKUtils.getWorkDays(aDate.withDayOfMonth(1), aDate.withDayOfMonth(aDate.dayOfMonth().getMaximumValue())); } else if (AccrualEarnInterval.YEARLY.equals(accrualEarnInterval)) { return TKUtils.getWorkDays(aDate.withDayOfYear(1), aDate.withDayOfYear(aDate.dayOfYear().getMaximumValue())); } else if (AccrualEarnInterval.NO_ACCRUAL.equals(accrualEarnInterval)) { return 0; } } return 0; }
assertFunction("day(" + TIMESTAMP_LITERAL + ")", BIGINT, TIMESTAMP.getDayOfMonth()); assertFunction("day_of_month(" + TIMESTAMP_LITERAL + ")", BIGINT, TIMESTAMP.getDayOfMonth()); assertFunction("day_of_year(" + TIMESTAMP_LITERAL + ")", BIGINT, TIMESTAMP.dayOfYear().get()); assertFunction("doy(" + TIMESTAMP_LITERAL + ")", BIGINT, TIMESTAMP.dayOfYear().get()); assertFunction("week(" + TIMESTAMP_LITERAL + ")", BIGINT, TIMESTAMP.weekOfWeekyear().get()); assertFunction("week_of_year(" + TIMESTAMP_LITERAL + ")", BIGINT, TIMESTAMP.weekOfWeekyear().get()); assertFunction("day(" + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, WEIRD_TIMESTAMP.getDayOfMonth()); assertFunction("day_of_month(" + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, WEIRD_TIMESTAMP.getDayOfMonth()); assertFunction("day_of_year(" + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, WEIRD_TIMESTAMP.dayOfYear().get()); assertFunction("doy(" + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, WEIRD_TIMESTAMP.dayOfYear().get()); assertFunction("week(" + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, WEIRD_TIMESTAMP.weekOfWeekyear().get()); assertFunction("week_of_year(" + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, WEIRD_TIMESTAMP.weekOfWeekyear().get());
if (periods > 1) time = time.minusYears(time.getYearOfCentury() % periods); time = time.dayOfYear().withMinimumValue(); time = time.withTimeAtStartOfDay();