List of usage examples for org.joda.time DateTime withDayOfMonth
public DateTime withDayOfMonth(int dayOfMonth)
From source file:org.jruby.CompatVersion.java
License:LGPL
protected static RubyTime s_mload(IRubyObject recv, RubyTime time, IRubyObject from) { Ruby runtime = recv.getRuntime(); DateTime dt = new DateTime(DateTimeZone.UTC); byte[] fromAsBytes = null; fromAsBytes = from.convertToString().getBytes(); if (fromAsBytes.length != 8) { throw runtime.newTypeError("marshaled time format differ"); }/* www.j a v a 2s .com*/ int p = 0; int s = 0; for (int i = 0; i < 4; i++) { p |= ((int) fromAsBytes[i] & 0xFF) << (8 * i); } for (int i = 4; i < 8; i++) { s |= ((int) fromAsBytes[i] & 0xFF) << (8 * (i - 4)); } if ((p & (1 << 31)) == 0) { dt = dt.withMillis(p * 1000L + s); } else { p &= ~(1 << 31); dt = dt.withYear(((p >>> 14) & 0xFFFF) + 1900); dt = dt.withMonthOfYear(((p >>> 10) & 0xF) + 1); dt = dt.withDayOfMonth(((p >>> 5) & 0x1F)); dt = dt.withHourOfDay((p & 0x1F)); dt = dt.withMinuteOfHour(((s >>> 26) & 0x3F)); dt = dt.withSecondOfMinute(((s >>> 20) & 0x3F)); // marsaling dumps usec, not msec dt = dt.withMillisOfSecond((s & 0xFFFFF) / 1000); dt = dt.withZone(getLocalTimeZone(runtime)); time.setUSec((s & 0xFFFFF) % 1000); } time.setDateTime(dt); return time; }
From source file:org.jruby.RubyTime.java
License:LGPL
protected static RubyTime s_mload(IRubyObject recv, RubyTime time, IRubyObject from) { Ruby runtime = recv.getRuntime();// ww w. j a va 2 s . c o m DateTime dt = new DateTime(DateTimeZone.UTC); byte[] fromAsBytes; fromAsBytes = from.convertToString().getBytes(); if (fromAsBytes.length != 8) { throw runtime.newTypeError("marshaled time format differ"); } int p = 0; int s = 0; for (int i = 0; i < 4; i++) { p |= ((int) fromAsBytes[i] & 0xFF) << (8 * i); } for (int i = 4; i < 8; i++) { s |= ((int) fromAsBytes[i] & 0xFF) << (8 * (i - 4)); } boolean utc = false; if ((p & (1 << 31)) == 0) { dt = dt.withMillis(p * 1000L); time.setUSec((s & 0xFFFFF) % 1000); } else { p &= ~(1 << 31); utc = ((p >>> 30 & 0x1) == 0x1); dt = dt.withYear(((p >>> 14) & 0xFFFF) + 1900); dt = dt.withMonthOfYear(((p >>> 10) & 0xF) + 1); dt = dt.withDayOfMonth(((p >>> 5) & 0x1F)); dt = dt.withHourOfDay((p & 0x1F)); dt = dt.withMinuteOfHour(((s >>> 26) & 0x3F)); dt = dt.withSecondOfMinute(((s >>> 20) & 0x3F)); // marsaling dumps usec, not msec dt = dt.withMillisOfSecond((s & 0xFFFFF) / 1000); time.setUSec((s & 0xFFFFF) % 1000); } time.setDateTime(dt); if (!utc) time.localtime(); from.getInstanceVariables().copyInstanceVariablesInto(time); // pull out nanos, offset, zone IRubyObject nano_num = (IRubyObject) from.getInternalVariables().getInternalVariable("nano_num"); IRubyObject nano_den = (IRubyObject) from.getInternalVariables().getInternalVariable("nano_den"); IRubyObject offsetVar = (IRubyObject) from.getInternalVariables().getInternalVariable("offset"); IRubyObject zoneVar = (IRubyObject) from.getInternalVariables().getInternalVariable("zone"); if (nano_num != null && nano_den != null) { long nanos = nano_num.convertToInteger().getLongValue() / nano_den.convertToInteger().getLongValue(); time.nsec += nanos; } int offset = 0; if (offsetVar != null && offsetVar.respondsTo("to_int")) { IRubyObject oldExc = runtime.getGlobalVariables().get("$!"); // Save $! try { offset = offsetVar.convertToInteger().getIntValue() * 1000; } catch (RaiseException typeError) { runtime.getGlobalVariables().set("$!", oldExc); // Restore $! } } String zone = ""; if (zoneVar != null && zoneVar.respondsTo("to_str")) { IRubyObject oldExc = runtime.getGlobalVariables().get("$!"); // Save $! try { zone = zoneVar.convertToString().toString(); } catch (RaiseException typeError) { runtime.getGlobalVariables().set("$!", oldExc); // Restore $! } } time.dt = dt.withZone(getTimeZoneWithOffset(runtime, zone, offset)); return time; }
From source file:org.jvyamlb.SafeConstructorImpl.java
public static Object constructYamlTimestamp(final Constructor ctor, final Node node) { Matcher match = YMD_REGEXP.matcher(node.getValue().toString()); if (match.matches()) { final String year_s = match.group(1); final String month_s = match.group(2); final String day_s = match.group(3); DateTime dt = new DateTime(0, 1, 1, 0, 0, 0, 0); if (year_s != null) { dt = dt.withYear(Integer.parseInt(year_s)); }/*from w w w. ja v a 2 s . c o m*/ if (month_s != null) { dt = dt.withMonthOfYear(Integer.parseInt(month_s)); } if (day_s != null) { dt = dt.withDayOfMonth(Integer.parseInt(day_s)); } return new Object[] { dt }; } match = TIMESTAMP_REGEXP.matcher(node.getValue().toString()); if (!match.matches()) { return new Object[] { ctor.constructPrivateType(node) }; } final String year_s = match.group(1); final String month_s = match.group(2); final String day_s = match.group(3); final String hour_s = match.group(4); final String min_s = match.group(5); final String sec_s = match.group(6); final String fract_s = match.group(7); final String utc = match.group(8); final String timezoneh_s = match.group(9); final String timezonem_s = match.group(10); int usec = 0; if (fract_s != null) { usec = Integer.parseInt(fract_s); if (usec != 0) { while (10 * usec < 1000) { usec *= 10; } } } DateTime dt = new DateTime(0, 1, 1, 0, 0, 0, 0); if ("Z".equalsIgnoreCase(utc)) { dt = dt.withZone(DateTimeZone.forID("Etc/GMT")); } else { if (timezoneh_s != null || timezonem_s != null) { int zone = 0; int sign = +1; if (timezoneh_s != null) { if (timezoneh_s.startsWith("-")) { sign = -1; } zone += Integer.parseInt(timezoneh_s.substring(1)) * 3600000; } if (timezonem_s != null) { zone += Integer.parseInt(timezonem_s) * 60000; } dt = dt.withZone(DateTimeZone.forOffsetMillis(sign * zone)); } } if (year_s != null) { dt = dt.withYear(Integer.parseInt(year_s)); } if (month_s != null) { dt = dt.withMonthOfYear(Integer.parseInt(month_s)); } if (day_s != null) { dt = dt.withDayOfMonth(Integer.parseInt(day_s)); } if (hour_s != null) { dt = dt.withHourOfDay(Integer.parseInt(hour_s)); } if (min_s != null) { dt = dt.withMinuteOfHour(Integer.parseInt(min_s)); } if (sec_s != null) { dt = dt.withSecondOfMinute(Integer.parseInt(sec_s)); } dt = dt.withMillisOfSecond(usec / 1000); return new Object[] { dt, new Integer(usec % 1000) }; }
From source file:org.kairosdb.core.aggregator.RangeAggregator.java
License:Apache License
/** For YEARS, MONTHS, WEEKS, DAYS:/*from w w w .j a va 2 s .c o m*/ Computes the timestamp of the first millisecond of the day of the timestamp. For HOURS, Computes the timestamp of the first millisecond of the hour of the timestamp. For MINUTES, Computes the timestamp of the first millisecond of the minute of the timestamp. For SECONDS, Computes the timestamp of the first millisecond of the second of the timestamp. For MILLISECONDS, returns the timestamp @param timestamp @return */ private long alignRangeBoundary(long timestamp) { DateTime dt = new DateTime(timestamp, m_timeZone); TimeUnit tu = m_sampling.getUnit(); switch (tu) { case YEARS: dt = dt.withDayOfYear(1).withMillisOfDay(0); break; case MONTHS: dt = dt.withDayOfMonth(1).withMillisOfDay(0); break; case WEEKS: dt = dt.withDayOfWeek(1).withMillisOfDay(0); break; case DAYS: case HOURS: case MINUTES: case SECONDS: dt = dt.withHourOfDay(0); dt = dt.withMinuteOfHour(0); dt = dt.withSecondOfMinute(0); default: dt = dt.withMillisOfSecond(0); break; } return dt.getMillis(); }
From source file:org.kuali.kpme.core.calendar.entry.service.CalendarEntryServiceImpl.java
License:Educational Community License
private DateTime plusSemiMonth(DateTime date) { //so assuming the common pairs of this are the 1st & 16th, and then 15th and the last day, // and 14th with the last day minus 1 //so we'll peek at the current date and try to figure out the best guesses for addition. if (date.getDayOfMonth() == date.dayOfMonth().getMaximumValue()) { //date is on the last day of the month. Set next date to the 15th return date.plusMonths(1).withDayOfMonth(15); } else if (date.getDayOfMonth() == 15) { //we are on the 15th of the month, so now lets go to the end of the month return date.withDayOfMonth(date.dayOfMonth().getMaximumValue()); } else if (date.getDayOfMonth() == 1) { //first of the month, next would be 16 return date.withDayOfMonth(16); } else if (date.getDayOfMonth() == 16) { //16th, so add a month and set day to '1' return date.plusMonths(1).withDayOfMonth(1); } else if (date.getDayOfMonth() == 14) { //14th day, set next one to last day minus 1 return date.withDayOfMonth(date.dayOfMonth().getMaximumValue() - 1); } else if (date.getDayOfMonth() == date.dayOfMonth().getMaximumValue() - 1) { //date is on the second to last day of the month. Set next date to the 14th return date.plusMonths(1).withDayOfMonth(14); } else {//from w w w . j a v a 2s . co m // so it isn't one of the common dates... i guess we'll just add 15 days... return date.plusDays(15); } }
From source file:org.kuali.kpme.tklm.leave.accrual.service.AccrualServiceImpl.java
License:Educational Community License
@Override public DateTime getPreviousAccrualIntervalDate(String earnInterval, DateTime aDate) { DateTime previousAccrualIntervalDate = null; if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.DAILY)) { previousAccrualIntervalDate = aDate.minusDays(1); } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.WEEKLY)) { previousAccrualIntervalDate = aDate.minusWeeks(1).withDayOfWeek(DateTimeConstants.SATURDAY); } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.SEMI_MONTHLY)) { previousAccrualIntervalDate = aDate.minusDays(15); if (previousAccrualIntervalDate.getDayOfMonth() <= 15) { previousAccrualIntervalDate = previousAccrualIntervalDate.withDayOfMonth(15); } else {/*from w ww. j ava 2 s.c o m*/ previousAccrualIntervalDate = previousAccrualIntervalDate .withDayOfMonth(previousAccrualIntervalDate.dayOfMonth().getMaximumValue()); } } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.MONTHLY)) { previousAccrualIntervalDate = aDate.minusMonths(1); previousAccrualIntervalDate = previousAccrualIntervalDate .withDayOfMonth(previousAccrualIntervalDate.dayOfMonth().getMaximumValue()); } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.YEARLY)) { previousAccrualIntervalDate = aDate.minusYears(1); previousAccrualIntervalDate = previousAccrualIntervalDate .withDayOfYear(previousAccrualIntervalDate.dayOfYear().getMaximumValue()); } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.NO_ACCRUAL)) { previousAccrualIntervalDate = aDate; } return previousAccrualIntervalDate; }
From source file:org.kuali.kpme.tklm.leave.accrual.service.AccrualServiceImpl.java
License:Educational Community License
@Override public DateTime getNextAccrualIntervalDate(String earnInterval, DateTime aDate) { DateTime nextAccrualIntervalDate = null; if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.DAILY)) { nextAccrualIntervalDate = aDate; } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.WEEKLY)) { if (aDate.getDayOfWeek() != DateTimeConstants.SATURDAY) { nextAccrualIntervalDate = aDate.withDayOfWeek(DateTimeConstants.SATURDAY); } else {/*from ww w . j av a 2s . c o m*/ nextAccrualIntervalDate = aDate.withWeekOfWeekyear(1); } } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.SEMI_MONTHLY)) { if (aDate.getDayOfMonth() <= 15) { nextAccrualIntervalDate = aDate.withDayOfMonth(15); } else { nextAccrualIntervalDate = aDate.withDayOfMonth(aDate.dayOfMonth().getMaximumValue()); } } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.MONTHLY)) { nextAccrualIntervalDate = aDate.withDayOfMonth(aDate.dayOfMonth().getMaximumValue()); } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.YEARLY)) { nextAccrualIntervalDate = aDate.withDayOfYear(aDate.dayOfYear().getMaximumValue()); } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.NO_ACCRUAL)) { nextAccrualIntervalDate = aDate; } return nextAccrualIntervalDate; }
From source file:org.kuali.kpme.tklm.leave.accrual.service.AccrualServiceImpl.java
License:Educational Community License
@Override public int getWorkDaysInAccrualInterval(String earnInterval, DateTime aDate) { if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.DAILY)) { return 1; } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.WEEKLY)) { return 5; } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.SEMI_MONTHLY)) { if (aDate.getDayOfMonth() <= 15) { return TKUtils.getWorkDays(aDate.withDayOfMonth(1), aDate.withDayOfMonth(15)); } else {//from w w w . j a v a 2 s . com return TKUtils.getWorkDays(aDate.withDayOfMonth(16), aDate.withDayOfMonth(aDate.dayOfMonth().getMaximumValue())); } } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.MONTHLY)) { return TKUtils.getWorkDays(aDate.withDayOfMonth(1), aDate.withDayOfMonth(aDate.dayOfMonth().getMaximumValue())); } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.YEARLY)) { return TKUtils.getWorkDays(aDate.withDayOfYear(1), aDate.withDayOfYear(aDate.dayOfYear().getMaximumValue())); } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.NO_ACCRUAL)) { return 0; } return 0; }
From source file:org.kuali.kpme.tklm.leave.accrual.service.AccrualServiceImpl.java
License:Educational Community License
public DateTime getRuleStartDate(String earnInterval, LocalDate serviceDate, Long startAcc) { DateTime ruleStartDate = null; String intervalValue = HrConstants.SERVICE_UNIT_OF_TIME.get(earnInterval); if (intervalValue.equals("Months")) { ruleStartDate = serviceDate.toDateTimeAtStartOfDay().plusMonths(startAcc.intValue()); if (ruleStartDate.getDayOfMonth() > ruleStartDate.dayOfMonth().getMaximumValue()) { ruleStartDate = ruleStartDate.withDayOfMonth(ruleStartDate.dayOfMonth().getMaximumValue()); }//w ww . j a v a2 s . c o m } else if (intervalValue.equals("Years")) { ruleStartDate = serviceDate.toDateTimeAtStartOfDay().withYear(startAcc.intValue()); } else { ruleStartDate = serviceDate.toDateTimeAtStartOfDay(); } return ruleStartDate; }
From source file:org.mifos.dmt.business.Meetings.schedule.MonthlyScheduleWithROD.java
License:Open Source License
protected void getMeetingStartDate() { sanitizeDays();//from w w w. ja va 2s . c om DateTime initialDate = this.createdDate; initialDate = initialDate.withDayOfMonth(1); initialDate = initialDate.plusWeeks((this.rankOfDays - 1)); initialDate = initialDate.withDayOfWeek(this.days); if (initialDate.isBefore(this.createdDate) || initialDate.isEqual(this.createdDate)) { initialDate = initialDate.plusMonths(1); initialDate = initialDate.withDayOfMonth(1); initialDate = initialDate.plusWeeks((this.rankOfDays - 1)); initialDate = initialDate.withDayOfWeek(this.days); } this.startDate = initialDate; }