List of usage examples for org.joda.time DateTime getDayOfMonth
public int getDayOfMonth()
From source file:com.serotonin.mango.util.DateUtils.java
License:Open Source License
public static DateTime truncateDateTime(DateTime time, int periodType) { if (periodType == TimePeriods.SECONDS) time = time.minus(time.getMillisOfSecond()); else if (periodType == TimePeriods.MINUTES) { time = time.minus(time.getMillisOfSecond()); time = time.minus(Common.getPeriod(TimePeriods.SECONDS, time.getSecondOfMinute())); } else if (periodType == TimePeriods.HOURS) { time = time.minus(time.getMillisOfSecond()); time = time.minus(Common.getPeriod(TimePeriods.SECONDS, time.getSecondOfMinute())); time = time.minus(Common.getPeriod(TimePeriods.MINUTES, time.getMinuteOfHour())); } else if (periodType == TimePeriods.DAYS) { time = time.minus(time.getMillisOfDay()); } else if (periodType == TimePeriods.WEEKS) { time = time.minus(time.getMillisOfDay()); time = time.minus(Common.getPeriod(TimePeriods.DAYS, time.getDayOfWeek() - 1)); } else if (periodType == TimePeriods.MONTHS) { time = time.minus(time.getMillisOfDay()); time = time.minus(Common.getPeriod(TimePeriods.DAYS, time.getDayOfMonth() - 1)); } else if (periodType == TimePeriods.YEARS) { time = time.minus(time.getMillisOfDay()); time = time.minus(Common.getPeriod(TimePeriods.DAYS, time.getDayOfYear() - 1)); }//from w w w . ja va 2 s . com return time; }
From source file:com.serotonin.mango.vo.report.ReportVO.java
License:Open Source License
public ReportVO() { // Default the specific date fields. DateTime dt = DateUtils.truncateDateTime(new DateTime(), Common.TimePeriods.DAYS); toYear = dt.getYear();/*w ww . ja v a2 s. c o m*/ toMonth = dt.getMonthOfYear(); toDay = dt.getDayOfMonth(); toHour = dt.getHourOfDay(); toMinute = dt.getMinuteOfHour(); dt = DateUtils.minus(dt, Common.TimePeriods.DAYS, 1); fromYear = dt.getYear(); fromMonth = dt.getMonthOfYear(); fromDay = dt.getDayOfMonth(); fromHour = dt.getHourOfDay(); fromMinute = dt.getMinuteOfHour(); }
From source file:com.serotonin.mango.web.dwr.BaseDwr.java
License:Open Source License
public Map<String, Object> getDateRangeDefaults(int periodType, int period) { Map<String, Object> result = new HashMap<String, Object>(); // Default the specific date fields. DateTime dt = new DateTime(); result.put("toYear", dt.getYear()); result.put("toMonth", dt.getMonthOfYear()); result.put("toDay", dt.getDayOfMonth()); result.put("toHour", dt.getHourOfDay()); result.put("toMinute", dt.getMinuteOfHour()); result.put("toSecond", 0); dt = DateUtils.minus(dt, periodType, period); result.put("fromYear", dt.getYear()); result.put("fromMonth", dt.getMonthOfYear()); result.put("fromDay", dt.getDayOfMonth()); result.put("fromHour", dt.getHourOfDay()); result.put("fromMinute", dt.getMinuteOfHour()); result.put("fromSecond", 0); return result; }
From source file:com.sonicle.webtop.calendar.Service.java
License:Open Source License
public void processPrintScheduler(HttpServletRequest request, HttpServletResponse response) { ByteArrayOutputStream baos = null; UserProfile up = getEnv().getProfile(); try {//from w w w .j av a2s .c o m String filename = ServletUtils.getStringParameter(request, "filename", "print"); String view = ServletUtils.getStringParameter(request, "view", "w5"); String from = ServletUtils.getStringParameter(request, "startDate", true); DateTime startDate = DateTimeUtils.parseYmdHmsWithZone(from, "00:00:00", up.getTimeZone()); ReportConfig.Builder builder = reportConfigBuilder(); DateTime fromDate = null, toDate = null; AbstractAgenda rpt = null; if (view.equals("d")) { fromDate = startDate.withTimeAtStartOfDay(); toDate = startDate.plusDays(1).withTimeAtStartOfDay(); rpt = new RptAgendaSummary(builder.build(), 1); } else if (view.equals("w5")) { fromDate = startDate.withTimeAtStartOfDay(); toDate = startDate.plusDays(5).withTimeAtStartOfDay(); rpt = new RptAgendaWeek5(builder.build()); } else if (view.equals("w")) { fromDate = startDate.withTimeAtStartOfDay(); toDate = startDate.plusDays(7).withTimeAtStartOfDay(); rpt = new RptAgendaWeek7(builder.build()); } else if (view.equals("dw")) { fromDate = startDate.withTimeAtStartOfDay(); toDate = startDate.plusDays(14).withTimeAtStartOfDay(); rpt = new RptAgendaSummary(builder.build(), 14); } else if (view.equals("m")) { if (startDate.getDayOfMonth() == 1) { fromDate = startDate.withTimeAtStartOfDay(); } else { fromDate = startDate.plusMonths(1).withDayOfMonth(1).withTimeAtStartOfDay(); } int days = fromDate.dayOfMonth().getMaximumValue(); toDate = fromDate.plusMonths(1).withDayOfMonth(1).withTimeAtStartOfDay(); rpt = new RptAgendaSummary(builder.build(), days); } else { throw new WTException("View not supported [{0}]", view); } Set<Integer> activeCalIds = getActiveFolderIds(); Map<Integer, Calendar> calendars = folders.entrySet().stream() .filter(map -> activeCalIds.contains(map.getKey())) .collect(Collectors.toMap(map -> map.getKey(), map -> map.getValue().getCalendar())); List<SchedEventInstance> instances = manager.listEventInstances(activeCalIds, new DateTimeRange(fromDate, toDate), up.getTimeZone(), true); rpt.setDataSource(manager, fromDate, toDate, up.getTimeZone(), calendars, instances); baos = new ByteArrayOutputStream(); WT.generateReportToStream(rpt, AbstractReport.OutputType.PDF, baos); ServletUtils.setContentDispositionHeader(response, "inline", filename + ".pdf"); ServletUtils.writeContent(response, baos, "application/pdf"); } catch (Exception ex) { logger.error("Error in PrintScheduler", ex); ServletUtils.writeErrorHandlingJs(response, ex.getMessage()); } finally { IOUtils.closeQuietly(baos); } }
From source file:com.sos.scheduler.model.objects.JodaTools.java
License:Apache License
public static DateTime getStartOfMonth(DateTime base) { return base.minusMillis(base.getMillisOfDay()).minusDays(base.getDayOfMonth() - 1); }
From source file:com.spears.objects.io.DatedFileAppenderImpl.java
License:Open Source License
private static String generateFilename(String rootpath) { String filename;/*from w w w .j a v a2s.co m*/ DateTime date = new DateTime(); int ver = 1; do { filename = String.format("%s/%d/%d/%d/LOG_%s_(%d).log", rootpath, date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), date.toString(DateTimeFormat.forPattern("MM-dd-yyyy_HH.mm")), ver); ver++; } while (new File(filename).exists()); return filename; }
From source file:com.splicemachine.db.iapi.types.SQLDate.java
License:Apache License
public void setValue(DateTime value) throws StandardException { restoreToNull();/*from w w w. j a v a 2s .c o m*/ encodedDate = computeEncodedDate(value.getYear(), value.getMonthOfYear(), value.getDayOfMonth()); isNull = evaluateNull(); }
From source file:com.splicemachine.db.iapi.types.SQLDate.java
License:Apache License
static int computeEncodedDate(DateTime dateTime) throws StandardException { return computeEncodedDate(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth()); }
From source file:com.splicemachine.db.iapi.types.SQLTimestamp.java
License:Apache License
private static int computeEncodedDate(DateTime value) throws StandardException { if (value == null) return 0; return SQLDate.computeEncodedDate(value.getYear(), value.getMonthOfYear(), value.getDayOfMonth()); }
From source file:com.squid.kraken.v4.core.analysis.engine.processor.AnalysisCompute.java
License:Open Source License
private IntervalleObject alignPastInterval(IntervalleObject presentInterval, IntervalleObject pastInterval, Axis joinAxis) throws ScopeException { if (joinAxis != null && presentInterval != null && pastInterval != null) { Object lowerPresent = presentInterval.getLowerBound(); Object lowerPast = pastInterval.getLowerBound(); Object upperPresent = presentInterval.getUpperBound(); Object upperPast = pastInterval.getUpperBound(); ///*from w w w .j a va 2 s . com*/ IDomain image = joinAxis.getDefinition().getImageDomain(); if (lowerPresent instanceof Date && lowerPast instanceof Date) { DateTime lowerPastDT = new DateTime((Date) lowerPast); DateTime lowerPresentDT = new DateTime((Date) lowerPresent); DateTime upperPresentDT = new DateTime((Date) upperPresent); DateTime upperPastDT = new DateTime((Date) upperPast); // realign if (image.isInstanceOf(IDomain.YEARLY)) { // check if present is an exact number of years if (lowerPresentDT.getDayOfYear() == 1 && upperPresentDT.getDayOfYear() == upperPresentDT.dayOfYear().getMaximumValue()) { // check of both periods have the same number of days Period presentPeriod = new Period(new LocalDate(lowerPresent), (new LocalDate(upperPresent)), PeriodType.days()); Period pastPeriod = new Period(new LocalDate(lowerPast), (new LocalDate(upperPast)), PeriodType.days()); if (presentPeriod.getDays() == pastPeriod.getDays()) { presentPeriod = new Period(new LocalDate(lowerPresent), (new LocalDate(upperPresent)).plusDays(1), PeriodType.years()); pastPeriod = new Period(new LocalDate(lowerPast), (new LocalDate(upperPast)).plusDays(1), PeriodType.years()); // realign if (presentPeriod.getYears() > pastPeriod.getYears()) { // some days are missing to align the periods if (lowerPastDT.getDayOfYear() != 1) { // previous period Date newLowerPast = new DateTime(upperPastDT.getYear(), 1, 1, 0, 0).toDate(); return new IntervalleObject(newLowerPast, upperPast); } if (upperPastDT.getDayOfYear() != upperPastDT.dayOfYear().getMaximumValue()) { // year over year Date newUpperPast = new DateTime(upperPastDT.getYear(), 12, 31, 23, 59) .toDate(); return new IntervalleObject(lowerPast, newUpperPast); } } else { // either already aligned, or some days should // be removed if (upperPastDT.getDayOfYear() != upperPastDT.dayOfYear().getMaximumValue()) { // year over Year Date newUpperPast = new DateTime(upperPastDT.getYear() - 1, 12, 31, 23, 59) .toDate(); return new IntervalleObject(lowerPast, newUpperPast); } if (lowerPastDT.getDayOfYear() != 1) { // previous period Date newLowerPast = new DateTime(lowerPastDT.getYear() + 1, 1, 1, 0, 0) .toDate(); return new IntervalleObject(newLowerPast, upperPast); } } } } } else if (image.isInstanceOf(IDomain.QUATERLY) || image.isInstanceOf(IDomain.MONTHLY)) { // check if present is an exact number of month if (lowerPresentDT.getDayOfMonth() == 1 && upperPresentDT.getDayOfMonth() == upperPresentDT.dayOfMonth().getMaximumValue()) { // check of both periods have the same number of days Period presentPeriod = new Period(new LocalDate(lowerPresent), new LocalDate(upperPresent), PeriodType.days()); Period pastPeriod = new Period(new LocalDate(lowerPast), new LocalDate(upperPast), PeriodType.days()); if (presentPeriod.getDays() == pastPeriod.getDays()) { // realign presentPeriod = new Period(new LocalDate(lowerPresent), (new LocalDate(upperPresent)).plusDays(1), PeriodType.months()); pastPeriod = new Period(new LocalDate(lowerPast), (new LocalDate(upperPast)).plusDays(1), PeriodType.months()); if (presentPeriod.getMonths() > pastPeriod.getMonths()) { // some days are missing if (upperPastDT.getDayOfMonth() != upperPastDT.dayOfMonth().getMaximumValue()) { // month over month Date newUpperPast = new DateTime(upperPastDT.getYear(), upperPastDT.getMonthOfYear(), upperPastDT.dayOfMonth().getMaximumValue(), 23, 59).toDate(); return new IntervalleObject(lowerPast, newUpperPast); } if (lowerPastDT.getDayOfMonth() != 1) { // previous period Date newLowerPast = new DateTime(lowerPastDT.getYear(), lowerPastDT.getMonthOfYear(), 1, 0, 0).toDate(); return new IntervalleObject(newLowerPast, upperPast); } } else { // either already aligned, of some days should // be removed if (upperPastDT.getDayOfMonth() != upperPastDT.dayOfMonth().getMaximumValue()) { /// month over month if (upperPastDT.getMonthOfYear() == 1) { Date newUpperPast = new DateTime(upperPastDT.getYear() - 1, 12, 31, 23, 59) .toDate(); return new IntervalleObject(lowerPast, newUpperPast); } else { upperPastDT = upperPastDT.minusMonths(1); Date newUpperPast = new DateTime(upperPastDT.getYear(), upperPastDT.getMonthOfYear(), upperPastDT.dayOfMonth().getMaximumValue(), 23, 59).toDate(); return new IntervalleObject(lowerPast, newUpperPast); } } if (lowerPastDT.getDayOfMonth() != 1) { // previous period if (lowerPastDT.getMonthOfYear() == 12) { Date newLowerPast = new DateTime(lowerPastDT.getYear() + 1, 1, 1, 0, 0) .toDate(); return new IntervalleObject(newLowerPast, upperPast); } else { lowerPastDT = lowerPastDT.plusMonths(1); Date newLowerPast = new DateTime(lowerPastDT.getYear(), lowerPastDT.getMonthOfYear(), 1, 0, 0).toDate(); return new IntervalleObject(newLowerPast, upperPast); } } } } } } } } return pastInterval; }