List of usage examples for org.joda.time DateTime withDayOfYear
public DateTime withDayOfYear(int dayOfYear)
From source file:DataRequestParser.java
private DateTime getDateWith(int year, int doy) { // temp date object DateTime dt = new DateTime(); // set the year dt = dt.withYear(year);// ww w. j a v a 2 s . com // set the day of year dt = dt.withDayOfYear(doy); return dt; }
From source file:com.arpnetworking.kairosdb.aggregators.MovingWindowAggregator.java
License:Apache License
/** * For YEARS, MONTHS, WEEKS, DAYS: 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 Timestamp in milliseconds to use as a basis for range alignment * @return timestamp aligned to the configured sampling unit *//* w w w. j a va 2 s . co m*/ @SuppressWarnings("fallthrough") @SuppressFBWarnings("SF_SWITCH_FALLTHROUGH") private long alignRangeBoundary(final long timestamp) { DateTime dt = new DateTime(timestamp, _timeZone); final 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: dt = dt.withHourOfDay(0); case HOURS: dt = dt.withMinuteOfHour(0); case MINUTES: dt = dt.withSecondOfMinute(0); case SECONDS: default: dt = dt.withMillisOfSecond(0); break; } return dt.getMillis(); }
From source file:gov.usgs.anss.query.filefactory.SacHeaders.java
License:Open Source License
public static SacTimeSeries setEventHeader(SacTimeSeries sac, DateTime eventOrigin, Double eventLat, Double eventLon, Double eventDepth, Double eventMag, int sacMagType, int sacEventType) { if (eventLat == null) { eventLat = -12345.0;/*from w w w .j av a 2 s. c o m*/ } if (eventLon == null) { eventLon = -12345.0; } if (eventDepth == null) { eventDepth = -12345.0; } if (eventMag == null) { eventMag = -12345.0; } // SAC stores year day (nzjday) but not month and day. DateTime start = new DateTime(sac.nzyear, 1, 1, sac.nzhour, sac.nzmin, sac.nzsec, sac.nzmsec, DateTimeZone.UTC); start = start.withDayOfYear(sac.nzjday); double timeDiff = (start.getMillis() - eventOrigin.getMillis()) / 1000.0d; sac.nzyear = eventOrigin.getYear(); sac.nzjday = eventOrigin.getDayOfYear(); sac.nzhour = eventOrigin.getHourOfDay(); sac.nzmin = eventOrigin.getMinuteOfHour(); sac.nzsec = eventOrigin.getSecondOfMinute(); sac.nzmsec = eventOrigin.getMillisOfSecond(); sac.b = sac.b + timeDiff; sac.e = sac.e + timeDiff; sac.iztype = SacTimeSeries.IO; sac.evla = eventLat; sac.evlo = eventLon; sac.evdp = eventDepth; sac.mag = eventMag; sac.imagtyp = sacMagType; sac.ievtyp = sacEventType; sac.lcalda = 1; return sac; }
From source file:net.schweerelos.timeline.model.Timeline.java
License:Open Source License
public void setInterval(DateTime start, DateTime end) { DateTimeZone defaultTimeZone = DateTimeZone.getDefault(); // make sure we don't start before the start of the intervals (in years) DateTime firstStart = allIntervals.getFirstStart(); firstStart = firstStart.withDayOfYear(firstStart.dayOfYear().getMinimumValue()); if (start != null && start.toDateTime(defaultTimeZone).isBefore(firstStart)) { this.start = firstStart; } else {/*from w w w . ja va2s . c o m*/ this.start = start; } // make sure we don't end after the end of the intervals (in years) DateTime lastEnd = allIntervals.getLastEnd(); lastEnd = lastEnd.withDayOfYear(lastEnd.dayOfYear().getMaximumValue()); if (end != null && end.toDateTime(defaultTimeZone).isAfter(lastEnd)) { this.end = lastEnd; } else { this.end = end; } recalculate(); }
From source file:org.efaps.esjp.common.datetime.JodaTimeUtils.java
License:Apache License
/** * @param _parameter parameter as passed by the eFaps API * @return new DateTime/* ww w.ja va 2s .c o m*/ * @throws EFapsException on error */ public static DateTime getDefaultvalue(final Parameter _parameter) throws EFapsException { final JodaTimeUtils utils = new JodaTimeUtils(); DateTime ret = new DateTime().withTimeAtStartOfDay() .withChronology(Context.getThreadContext().getChronology()); for (final DateDefaultValues value : DateDefaultValues.values()) { if (utils.containsProperty(_parameter, value.toString())) { final String strValue = utils.getProperty(_parameter, value.toString()); switch (value) { case TODAY: ret = new DateTime().withChronology(Context.getThreadContext().getChronology()); break; case WEEKS: ret = ret.plusWeeks(Integer.valueOf(strValue)); break; case MONTHS: ret = ret.plusMonths(Integer.valueOf(strValue)); break; case YEARS: ret = ret.plusYears(Integer.valueOf(strValue)); break; case WITHDAYOFMONTH: ret = ret.withDayOfMonth(Integer.valueOf(strValue)); break; case WITHDAYOFWEEK: ret = ret.withDayOfWeek(Integer.valueOf(strValue)); break; case LASTDAYOFMONTH: ret = ret.dayOfMonth().withMaximumValue(); break; case WITHDAYOFYEAR: ret = ret.withDayOfYear(Integer.valueOf(strValue)); default: break; } } } return ret; }
From source file:org.kairosdb.core.aggregator.RangeAggregator.java
License:Apache License
/** For YEARS, MONTHS, WEEKS, DAYS:/*w w w. ja v a 2s . 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.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 {/* ww w. j av a 2s .c om*/ 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 {// w w w . j a v a 2 s . 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 {/*w w w.j av a2s . c o m*/ 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.obm.imap.archive.services.SchedulingDatesService.java
License:Open Source License
private DateTime yearlyNextTreatmentDate(SchedulingConfiguration schedulingConfiguration, DateTime currentDateTime, DateTime currentDateWithScheduledTime) { DateTime dayOfYear = currentDateWithScheduledTime .withDayOfYear(schedulingConfiguration.getDayOfYear().getDayOfYear()); if (dayOfYear.isAfter(currentDateTime)) { return dayOfYear; }//from ww w . ja va2 s . c om return dayOfYear.plusYears(1); }