Java Code Examples for org.joda.time.DateTime#withDayOfYear()
The following examples show how to use
org.joda.time.DateTime#withDayOfYear() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CalendarDate.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
public static CalendarDate withDoy(Calendar cal, int year, int doy, int hourOfDay, int minuteOfHour, int secondOfMinute) { Chronology base = Calendar.getChronology(cal); /* * if (base == null) * base = ISOChronology.getInstanceUTC(); // already in UTC * else * base = ZonedChronology.getInstance( base, DateTimeZone.UTC); // otherwise wrap it to be in UTC */ DateTime dt = new DateTime(year, 1, 1, hourOfDay, minuteOfHour, secondOfMinute, base); dt = dt.withZone(DateTimeZone.UTC); dt = dt.withDayOfYear(doy); if (!Calendar.isDefaultChronology(cal)) dt = dt.withChronology(Calendar.getChronology(cal)); return new CalendarDate(cal, dt); }
Example 2
Source File: QuarterlyPeriodFilter.java From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License | 6 votes |
private static DateTime fixEndDate(DateTime endDate) { if(endDate==null) { return null; } int month = endDate.getMonthOfYear(); if (month <= 3) { return endDate.withMonthOfYear(DateTimeConstants.MARCH).withDayOfMonth( endDate.dayOfMonth().getMaximumValue()); } else if (month <= 6) { return endDate.withMonthOfYear(DateTimeConstants.JUNE).withDayOfMonth( endDate.dayOfMonth().getMaximumValue()); } else if (month <= 9) { return endDate.withMonthOfYear(DateTimeConstants.SEPTEMBER).withDayOfMonth( endDate.dayOfMonth().getMaximumValue()); } else if (month <= 12) { endDate = endDate.withYear(endDate.getYear()).withMonthOfYear( DateTimeConstants.JANUARY); return endDate.withDayOfYear(endDate.dayOfYear().getMaximumValue()); } return endDate; }
Example 3
Source File: DhisConvenienceTest.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Creates a date. * * @param day the day of the year. * @return a date. */ public Date getDay( int day ) { DateTime dataTime = DateTime.now(); dataTime = dataTime.withTimeAtStartOfDay(); dataTime = dataTime.withDayOfYear( day ); return dataTime.toDate(); }
Example 4
Source File: SixMonthlyPeriodFilter.java From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static DateTime fixEndDate(DateTime endDate) { if(endDate==null) { return null; } int month = endDate.getMonthOfYear(); if (month <= 6) { endDate = endDate.withMonthOfYear(DateTimeConstants.JULY); endDate = endDate.withDayOfMonth(endDate.dayOfMonth().getMinimumValue()); } else if (month <= 12) { endDate = endDate.withYear(endDate.getYear() + 1).withMonthOfYear( DateTimeConstants.JANUARY); endDate = endDate.withDayOfYear(endDate.dayOfYear().getMaximumValue()); } return endDate; }