List of usage examples for org.joda.time DateTime withDayOfMonth
public DateTime withDayOfMonth(int dayOfMonth)
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 */// www . j a va 2 s . c o 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:com.barchart.feed.ddf.message.enums.DDF_TradeDay.java
License:BSD License
/** * recover full trade date from DDF day code and todays date * //from w ww . j av a2 s . c o m * expressed in UTC zone * * year, month, day : should be treated as local market trade date. * * @param tradeDay the trade day * @param todayDate the today date * @return the time value */ public static TimeValue tradeDateFrom(final DDF_TradeDay tradeDay, final DateTime todayDate) { // trading day of month reported by the feed final int tradingDayNum = tradeDay.day; // current day of month final int currentDayNum = todayDate.getDayOfMonth(); // positive for same month if trading date is in the future // unless day enum is not a day in the month ??? final int difference = tradingDayNum - currentDayNum; final boolean isSmall = Math.abs(difference) <= HOLIDAY_THESHOLD; final boolean isLarge = !isSmall; // final boolean isSameMonthSameDay = (difference == 0); final boolean isSameMonthPastDay = difference < 0 & isSmall; final boolean isSameMonthNextDay = difference > 0 & isSmall; final boolean isPastMonthPastDay = difference > 0 & isLarge; final boolean isNextMonthNextDay = difference < 0 & isLarge; // DateTime generated; try { if (isSameMonthSameDay) { generated = todayDate; } else if (isSameMonthPastDay) { generated = todayDate.withDayOfMonth(tradingDayNum); } else if (isSameMonthNextDay) { generated = todayDate.withDayOfMonth(tradingDayNum); } else if (isPastMonthPastDay) { generated = todayDate.minusMonths(1).withDayOfMonth(tradingDayNum); } else if (isNextMonthNextDay) { generated = todayDate.plusMonths(1).withDayOfMonth(tradingDayNum); } else { logger.error("should not happen"); generated = todayDate; } } catch (final Exception e) { generated = todayDate; } final DateTime result = new DateTime(// generated.getYear(), // generated.getMonthOfYear(), // generated.getDayOfMonth(), // 0, 0, 0, 0, ZONE_UTC); final long millisUTC = result.getMillis(); return ValueBuilder.newTime(millisUTC); }
From source file:com.court.controller.CollectionSheetFxmlController.java
private java.util.Date getDayOfMonth(java.util.Date instDate) { DateTimeZone zone = DateTimeZone.forID("Asia/Colombo"); DateTime insDateE = new DateTime(new SimpleDateFormat("yyyy-MM-dd").format(instDate), zone); DateTime nowDate = insDateE.withDayOfMonth(25); return nowDate.toDate(); }
From source file:com.edoli.calendarlms.CalendarView.java
License:Apache License
private void setupDate() { DateTime date = DateTime.now(); date = date.withDayOfMonth(1); setDate(date); mCalendarPager.setCurrentCalendar(date); }
From source file:com.ehdev.chronos.lib.types.holders.PayPeriodHolder.java
License:Open Source License
/** * Will do the calculations for the start and end of the process *//*from w w w .j a v a2s .co m*/ public void generate() { //Get the start and end of pay period DateTime startOfPP = gJob.getStartOfPayPeriod(); gDuration = gJob.getDuration(); DateTime endOfPP = DateTime.now(); //Today long duration = endOfPP.getMillis() - startOfPP.getMillis(); DateTimeZone startZone = startOfPP.getZone(); DateTimeZone endZone = endOfPP.getZone(); long offset = endZone.getOffset(endOfPP) - startZone.getOffset(startOfPP); int weeks = (int) ((duration + offset) / 1000 / 60 / 60 / 24 / 7); /* System.out.println("end of pp: " + endOfPP); System.out.println("start of pp: " + startOfPP); System.out.println("dur: " + duration); System.out.println("weeks diff: " + weeks); */ switch (gDuration) { case ONE_WEEK: //weeks = weeks; startOfPP = startOfPP.plusWeeks(weeks); endOfPP = startOfPP.plusWeeks(1); break; case TWO_WEEKS: weeks = weeks / 2; startOfPP = startOfPP.plusWeeks(weeks * 2); endOfPP = startOfPP.plusWeeks(2); break; case THREE_WEEKS: weeks = weeks / 3; startOfPP = startOfPP.plusWeeks(weeks * 3); endOfPP = startOfPP.plusWeeks(3); break; case FOUR_WEEKS: weeks = weeks / 4; startOfPP = startOfPP.plusWeeks(weeks * 4); endOfPP = startOfPP.plusWeeks(4); break; case FULL_MONTH: //in this case, endOfPP is equal to now startOfPP = DateMidnight.now().toDateTime().withDayOfMonth(1); endOfPP = startOfPP.plusMonths(1); break; case FIRST_FIFTEENTH: DateTime now = DateTime.now(); if (now.getDayOfMonth() >= 15) { startOfPP = now.withDayOfMonth(15); endOfPP = startOfPP.plusDays(20).withDayOfMonth(1); } else { startOfPP = now.withDayOfMonth(1); endOfPP = now.withDayOfMonth(15); } break; default: break; } if (startOfPP.isAfter(DateTime.now())) { startOfPP = startOfPP.minusWeeks(getDays() / 7); endOfPP = endOfPP.minusWeeks(getDays() / 7); } gStartOfPP = startOfPP; gEndOfPP = endOfPP; }
From source file:com.google.android.apps.paco.NonESMSignalGenerator.java
License:Open Source License
DateTime getNthDOWOfMonth(DateTime midnightTomorrow, Integer nthOfMonth, Integer dow) { int dtconstDow = dow == 0 ? 7 : dow; DateTime first = midnightTomorrow.withDayOfMonth(1); if (first.getDayOfWeek() > dtconstDow) { return first.plusWeeks(nthOfMonth).withDayOfWeek(dtconstDow); } else {// w w w . j av a2s. c o m return first.plusWeeks(nthOfMonth - 1).withDayOfWeek(dtconstDow); } }
From source file:com.gst.spm.service.SpmService.java
License:Apache License
public Survey createSurvey(final Survey survey) { this.securityContext.authenticatedUser(); final Survey previousSurvey = this.surveyRepository.findByKey(survey.getKey(), new Date()); if (previousSurvey != null) { this.deactivateSurvey(previousSurvey.getId()); }/* w w w . j a va2s . co m*/ // set valid from to start of today final DateTime validFrom = DateTime.now().withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0) .withMillisOfSecond(0); survey.setValidFrom(validFrom.toDate()); // set valid from to end in 100 years final DateTime validTo = validFrom.withDayOfMonth(31).withMonthOfYear(12).withHourOfDay(23) .withMinuteOfHour(59).withSecondOfMinute(59).withMillisOfSecond(999).plusYears(100); survey.setValidTo(validTo.toDate()); return this.surveyRepository.save(survey); }
From source file:com.kopysoft.chronos.activities.fragment.JobFragment.java
License:Open Source License
@Override public void onPause() { super.onPause(); Chronos chrono = new Chronos(getActivity()); Job thisJob = chrono.getAllJobs().get(0); /*//from w w w . ja v a 2 s . c o m EditText dataPayRate; Spinner dataPayPeriodLength; DatePicker dataStartOfPayPeriod; TimePicker dataTimePicker; */ Log.d(TAG, "onPause()"); dataPayRate.clearFocus(); dataPayPeriodLength.clearFocus(); dataStartOfPayPeriod.clearFocus(); dataTimePicker.clearFocus(); try { thisJob.setPayRate(Float.parseFloat(dataPayRate.getText().toString())); Log.d(TAG, "Pay Rate: " + thisJob.getPayRate()); } catch (NumberFormatException e) { Toast.makeText(getActivity(), "Pay Rate format incorrect", Toast.LENGTH_SHORT).show(); } PayPeriodDuration duration = PayPeriodDuration.values()[dataPayPeriodLength.getSelectedItemPosition()]; thisJob.setDuration(duration); DateTime newTime = thisJob.getStartOfPayPeriod(); newTime = newTime.withDayOfMonth(dataStartOfPayPeriod.getDayOfMonth()); newTime = newTime.withMonthOfYear(dataStartOfPayPeriod.getMonth() + 1); newTime = newTime.withYear(dataStartOfPayPeriod.getYear()); newTime = newTime.withHourOfDay(dataTimePicker.getCurrentHour()); newTime = newTime.withMinuteOfHour(dataTimePicker.getCurrentMinute()); thisJob.setStartOfPayPeriod(newTime); chrono.updateJob(thisJob); chrono.close(); }
From source file:com.phloc.datetime.PDTUtils.java
License:Apache License
/** * Get the start- and end-week numbers for the passed year and month. * * @param aDT//from ww w . j a va 2s . c o m * The object to use year and month from. * @return A non-<code>null</code> pair where the first item is the initial * week number, and the second item is the month's last week number. */ @Nonnull public static IReadonlyPair<Integer, Integer> getWeeksOfMonth(@Nonnull final DateTime aDT) { final int nStart = aDT.withDayOfMonth(1).getWeekOfWeekyear(); final int nEnd = aDT.withDayOfMonth(aDT.dayOfMonth().getMaximumValue()).getWeekOfWeekyear(); return ReadonlyPair.create(Integer.valueOf(nStart), Integer.valueOf(nEnd)); }
From source file:com.qcadoo.localization.api.utils.DateUtils.java
License:Open Source License
private static DateTime roundUpDate(final DateTime dateTime, final String dateExpressionPart) { DateTime roundedDate = dateTime; final String[] date = dateExpressionPart.split("-"); if (date.length < 3 || StringUtils.isBlank(date[2])) { final int day = roundedDate.dayOfMonth().getMaximumValue(); roundedDate = roundedDate.withDayOfMonth(day); }/* w ww .j av a 2 s .co m*/ if (date.length < 2 || StringUtils.isBlank(date[1])) { roundedDate = roundedDate.withMonthOfYear(12); } return roundedDate; }