Example usage for org.joda.time Days ONE

List of usage examples for org.joda.time Days ONE

Introduction

In this page you can find the example usage for org.joda.time Days ONE.

Prototype

Days ONE

To view the source code for org.joda.time Days ONE.

Click Source Link

Document

Constant representing one day.

Usage

From source file:energy.usef.core.event.DayAheadClosureEvent.java

License:Apache License

/**
 * Specific constructor which can receive any {@link LocalDate} defining the period of closure. If the date is <code>null</code>
 * , period will be set to <code>TODAY+1</code>.
 * /*from  w w w . j av  a2  s  . c o m*/
 * @param period {@link LocalDate}.
 */
public DayAheadClosureEvent(LocalDate period) {
    this.period = period == null ? DateTimeUtil.getCurrentDate().plus(Days.ONE) : period;
}

From source file:net.schweerelos.timeline.model.Timeline.java

License:Open Source License

private void recalculate() {
    if (start == null || end == null) {
        logger.warn("recalculating aborted, start and/or end is null");
        numSlices = 0;/*from w  w  w .jav a  2s .  c om*/
        return;
    }
    Interval interval = new Interval(start, end);

    if (Years.yearsIn(interval).isGreaterThan(Years.ZERO)) {
        // make it start at the start of the current increment mode
        start = start.withDayOfYear(start.dayOfYear().getMinimumValue());
        end = end.withDayOfYear(end.dayOfYear().getMaximumValue());
        interval = new Interval(start, end);

        // figure out number of slices
        numSlices = Years.yearsIn(interval).getYears();
        if (start.plusYears(numSlices).isBefore(end)) {
            numSlices += 1;
        }

        // update label extractor
        sliceLabelExtractor = new SliceLabelExtractor() {
            @Override
            public String extractLabel(DateTime from) {
                return from.year().getAsShortText();
            }
        };

        // update increment
        increment = Years.ONE.toPeriod();
        incrementMode = Mode.Years;
    } else if (Months.monthsIn(interval).isGreaterThan(Months.ZERO)) {
        // make it start at the start of the current increment mode
        start = start.withDayOfMonth(start.dayOfMonth().getMinimumValue());
        end = end.withDayOfMonth(end.dayOfMonth().getMaximumValue());
        interval = new Interval(start, end);

        numSlices = Months.monthsIn(interval).getMonths();
        if (start.plusMonths(numSlices).isBefore(end)) {
            numSlices += 1;
        }

        sliceLabelExtractor = new SliceLabelExtractor() {
            @Override
            public String extractLabel(DateTime from) {
                return from.monthOfYear().getAsShortText();
            }
        };

        increment = Months.ONE.toPeriod();
        incrementMode = Mode.Months;
    } else if (Weeks.weeksIn(interval).isGreaterThan(Weeks.ZERO)) {
        start = start.withDayOfWeek(start.dayOfWeek().getMinimumValue());
        end = end.withDayOfWeek(end.dayOfWeek().getMaximumValue());
        interval = new Interval(start, end);

        numSlices = Weeks.weeksIn(interval).getWeeks();
        if (start.plusWeeks(numSlices).isBefore(end)) {
            numSlices += 1;
        }

        sliceLabelExtractor = new SliceLabelExtractor() {
            @Override
            public String extractLabel(DateTime from) {
                return "W" + from.weekOfWeekyear().getAsShortText();
            }
        };

        increment = Weeks.ONE.toPeriod();
        incrementMode = Mode.Weeks;
    } else {
        numSlices = Days.daysIn(interval).getDays();
        if (start.plusDays(numSlices).isBefore(end)) {
            numSlices += 1;
        }
        if (numSlices == 0) {
            // force at least one day to be drawn
            numSlices = 1;
        }

        sliceLabelExtractor = new SliceLabelExtractor() {
            @Override
            public String extractLabel(DateTime from) {
                return from.dayOfMonth().getAsShortText();
            }
        };

        increment = Days.ONE.toPeriod();
        incrementMode = Mode.Days;
    }

    // reset time of day too
    start = start.withMillisOfDay(start.millisOfDay().getMinimumValue());
    end = end.withMillisOfDay(end.millisOfDay().getMaximumValue());

    // recalculate which intervals are within range
    intervalsWithinRange.clear();
    intervalsWithinRange.addAll(calculateIntervalsWithinRange(start, end));

    // notify listeners
    changeSupport.firePropertyChange(INTERVAL_PROPERTY_KEY, interval, new Interval(start, end));
}

From source file:org.hawkular.metrics.core.impl.DateTimeService.java

License:Apache License

/**
 * This method determines the 24 hour time slice for the specified time and returns the start of that time slice.
 *
 * @param time The DateTime to be rounded down
 * @return A DateTime rounded down to the start of the 24 hour time slice in which the time parameter falls.
 * @see #current24HourTimeSlice()//  ww w. j a  v  a  2  s . c  om
 */
public DateTime get24HourTimeSlice(DateTime time) {
    return getTimeSlice(time, Days.ONE.toStandardDuration());
}

From source file:org.hawkular.metrics.datetime.DateTimeService.java

License:Apache License

/**
 * This method determines the 24 hour time slice for the specified time and returns the start of that time slice.
 *
 * @param time The DateTime to be rounded down
 * @return A DateTime rounded down to the start of the 24 hour time slice in which the time parameter falls.
 * @see #current24HourTimeSlice()/*from  w  w  w.j  ava2s  .  co  m*/
 */
public static DateTime get24HourTimeSlice(DateTime time) {
    return getTimeSlice(time, Days.ONE.toStandardDuration());
}

From source file:org.mifos.calendar.DayOfWeek.java

License:Open Source License

public static int monday() {
    return Days.ONE.getDays();
}

From source file:org.projectbuendia.client.ui.chart.LocalizedChartDataGridAdapter.java

License:Apache License

public LocalizedChartDataGridAdapter(Context context, List<LocalizedObs> observations, LocalDate admissionDate,
        LocalDate firstSymptomsDate, LayoutInflater layoutInflater) {
    mContext = context;//from w  w w .  ja  va2  s .  c o  m
    LocalizedChartHelper localizedChartHelper = new LocalizedChartHelper(context.getContentResolver());
    mLayoutInflater = layoutInflater;
    Resources resources = context.getResources();
    mAdmissionDate = admissionDate;
    mFirstSymptomsDate = firstSymptomsDate;

    // Even though these Drawables are currently identical, referencing different drawables
    // for row headers and table cells ensures that RecyclerView does not improperly reuse
    // one as the other.
    this.mBackgroundLight = resources.getDrawable(R.drawable.chart_grid_background_light);
    this.mBackgroundDark = resources.getDrawable(R.drawable.chart_grid_background_dark);
    this.mRowHeaderBackgroundLight = resources.getDrawable(R.drawable.chart_grid_row_header_background_light);
    this.mRowHeaderBackgroundDark = resources.getDrawable(R.drawable.chart_grid_row_header_background_dark);

    Row row = null;
    TreeSet<LocalDate> days = new TreeSet<>();
    mToday = LocalDate.now(mChronology);
    for (LocalizedObs ob : observations) {
        // Observations come through ordered by the chart row, then the observation time, so we
        // want to maintain that order.
        if (row == null || !ob.conceptName.equals(row.mName)) {
            row = new Row(ob.conceptUuid, ob.conceptName);
            mRows.add(row);
        }

        if (ob.value == null || Concepts.UNKNOWN_UUID.equals(ob.value)
                || LocalizedChartHelper.NO_SYMPTOM_VALUES.contains(ob.value)) {
            // Don't display anything in the cell if there are no positive observations.
            continue;
        }

        DateTime obsDateTime = new DateTime(ob.encounterTimeMillis, mChronology);
        String columnId = toColumnId(obsDateTime);
        days.add(obsDateTime.toLocalDate());

        LOG.v("Column: %s, Observation: %s", columnId, ob.toString());
        if (row.mColumnIdsToLocalizedValues.containsKey(columnId)) {
            LOG.v("Overriding previous observation with value: %s",
                    row.mColumnIdsToLocalizedValues.get(columnId));
        }

        // If this is any bleeding site, also show a dot in the "any bleeding" row.
        if (Concepts.BLEEDING_SITES_NAME.equals(ob.groupName)) {
            mColumnIdsWithAnyBleeding.add(columnId);
        }

        // For notes, perform a concatenation rather than overwriting.
        if (Concepts.NOTES_UUID.equals(ob.conceptUuid)) {
            String oldText = row.mColumnIdsToValues.get(columnId);
            String newText = (oldText == null ? "" : oldText + "\n\n") + Dates.toMediumString(obsDateTime)
                    + "\n" + ob.value;
            row.mColumnIdsToValues.put(columnId, newText);
        } else {
            row.mColumnIdsToValues.put(columnId, ob.value);
        }

        row.mColumnIdsToLocalizedValues.put(columnId, ob.localizedValue);
    }

    // Create the list of all the columns to show.  Today and the admission date should
    // always be present, as well as any days between the last observation and today.
    days.add(mToday);
    if (admissionDate != null) {
        days.add(admissionDate);
    }
    LocalDate lastDay = days.last();
    for (LocalDate d = days.first(); !d.isAfter(lastDay); d = d.plus(Days.ONE)) {
        DateTime dayStart = d.toDateTimeAtStartOfDay();
        mColumnIds.add(toColumnId(dayStart));
        mColumnIds.add(toColumnId(dayStart.withHourOfDay(12)));
    }

    // If there are no observations, put some known rows to make it clearer what is being
    // displayed.
    if (mRows.isEmpty()) {
        List<LocalizedObs> emptyChart = localizedChartHelper.getEmptyChart(LocalizedChartHelper.ENGLISH_LOCALE);
        for (LocalizedObs ob : emptyChart) {
            mRows.add(new Row(ob.conceptUuid, ob.conceptName));
        }
    }
}

From source file:org.whole.lang.xsd.parsers.SchemaDataTypeParsers.java

License:Open Source License

public static IDataTypeParser date() {
    if (dateDataTypeParser == null) {
        dateDataTypeParser = new AbstractISO8601DataTypeParser(dateFormatter()) {
            protected Object parseWithTimeZone(DateTimeParserBucket bucket) {
                DateTimeZone zone = DateTimeZone.forOffsetMillis(bucket.getOffset());
                return new Interval(new DateTime(bucket.computeMillis(), validate(zone)), Days.ONE);
            }/*from w ww. ja  va  2 s  . co m*/

            protected Object parseWithoutTimeZone(DateTimeParserBucket bucket) {
                return new LocalDate(bucket.computeMillis());
            }

            @Override
            public String unparseObject(EntityDescriptor<?> ed, Object value) {
                if (value instanceof ReadableInterval) {
                    // make use of recoverable time zones
                    DateTime start = ((ReadableInterval) value).getStart();
                    int millisOffset = start.getZone().getOffset(0L);
                    DateTimeZone zone = DateTimeZone.forOffsetMillis(millisOffset > TZ_REC_UPPER_MILLIS
                            ? millisOffset - H24
                            : (millisOffset <= TZ_REC_LOWER_MILLIS ? millisOffset + H24 : millisOffset));
                    return getFormatter().withZone(zone).print(start);
                } else
                    return super.unparseObject(ed, value);
            }
        };
    }
    return dateDataTypeParser;
}

From source file:org.whole.lang.xsd.parsers.SchemaDataTypeParsers.java

License:Open Source License

public static IDataTypeParser monthDay() {
    if (monthDayDataTypeParser == null) {
        monthDayDataTypeParser = new AbstractISO8601DataTypeParser(monthDayFormatter()) {
            protected Object parseWithTimeZone(DateTimeParserBucket bucket) {
                DateTimeZone zone = DateTimeZone.forOffsetMillis(bucket.getOffset());
                return new Interval(new DateTime(bucket.computeMillis(), validate(zone)), Days.ONE);
            }//from  w  w  w  .j  a v  a 2s.c o  m

            protected Object parseWithoutTimeZone(DateTimeParserBucket bucket) {
                return new LocalDate(bucket.computeMillis());
            }
        };
    }
    return monthDayDataTypeParser;
}

From source file:org.whole.lang.xsd.parsers.SchemaDataTypeParsers.java

License:Open Source License

public static IDataTypeParser day() {
    if (dayDataTypeParser == null) {
        dayDataTypeParser = new AbstractISO8601DataTypeParser(dayFormatter()) {
            protected Object parseWithTimeZone(DateTimeParserBucket bucket) {
                DateTimeZone zone = DateTimeZone.forOffsetMillis(bucket.getOffset());
                return new Interval(new DateTime(bucket.computeMillis(), validate(zone)), Days.ONE);
            }//from  w  w w.  ja  v a  2 s . c  o m

            protected Object parseWithoutTimeZone(DateTimeParserBucket bucket) {
                return new LocalDate(bucket.computeMillis());
            }
        };
    }
    return dayDataTypeParser;
}

From source file:ru.touchin.templates.calendar.CalendarUtils.java

License:Apache License

/**
 * Create list of {@link CalendarItem} according to start and end Dates.
 *
 * @param startDate Start date of the range;
 * @param endDate   End date of the range;
 * @return List of CalendarItems that could be one of these: {@link CalendarHeaderItem}, {@link CalendarDayItem} or {@link CalendarEmptyItem}.
 *//*from   w w  w .j a  v  a  2  s.  c  o m*/
@NonNull
@SuppressWarnings("checkstyle:MethodLength")
public static List<CalendarItem> fillRanges(@NonNull final DateTime startDate,
        @NonNull final DateTime endDate) {
    final DateTime cleanStartDate = startDate.withTimeAtStartOfDay();
    final DateTime cleanEndDate = endDate.plusDays(1).withTimeAtStartOfDay();

    DateTime tempTime = cleanStartDate;

    final List<CalendarItem> calendarItems = fillCalendarTillCurrentDate(cleanStartDate, tempTime);

    tempTime = tempTime.plusDays(Days.ONE.getDays());

    final int totalDaysCount = Days.daysBetween(tempTime, cleanEndDate).getDays();
    int shift = calendarItems.get(calendarItems.size() - 1).getEndRange();
    int firstDate = tempTime.getDayOfMonth() - 1;
    int daysEnded = 1;

    while (true) {
        final int daysInCurrentMonth = tempTime.dayOfMonth().getMaximumValue();
        final long firstRangeDate = tempTime.getMillis();

        if ((daysEnded + (daysInCurrentMonth - firstDate)) <= totalDaysCount) {
            tempTime = tempTime.plusMonths(1).withDayOfMonth(1);

            calendarItems.add(new CalendarDayItem(firstRangeDate, firstDate + 1, shift + daysEnded,
                    shift + daysEnded + (daysInCurrentMonth - firstDate) - 1, ComparingToToday.AFTER_TODAY));
            daysEnded += daysInCurrentMonth - firstDate;
            if (daysEnded == totalDaysCount) {
                break;
            }
            firstDate = 0;

            final int firstDayInWeek = tempTime.getDayOfWeek() - 1;

            if (firstDayInWeek != 0) {
                calendarItems.add(new CalendarEmptyItem(shift + daysEnded,
                        shift + daysEnded + (DAYS_IN_WEEK - firstDayInWeek - 1)));
                shift += (DAYS_IN_WEEK - firstDayInWeek);
            }

            calendarItems.add(new CalendarHeaderItem(tempTime.getYear(), tempTime.getMonthOfYear() - 1,
                    shift + daysEnded, shift + daysEnded));
            shift += 1;

            if (firstDayInWeek != 0) {
                calendarItems
                        .add(new CalendarEmptyItem(shift + daysEnded, shift + daysEnded + firstDayInWeek - 1));
                shift += firstDayInWeek;
            }

        } else {
            calendarItems.add(new CalendarDayItem(firstRangeDate, firstDate + 1, shift + daysEnded,
                    shift + totalDaysCount, ComparingToToday.AFTER_TODAY));
            break;
        }
    }

    return calendarItems;
}