org.joda.time.DateTimeConstants Java Examples
The following examples show how to use
org.joda.time.DateTimeConstants.
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: JodaDateConverterTest.java From projectforge-webapp with GNU General Public License v3.0 | 6 votes |
@Test public void convertToString() { final PFUserDO user = new PFUserDO(); user.setTimeZone(DateHelper.EUROPE_BERLIN); user.setLocale(Locale.GERMAN); user.setDateFormat("dd.MM.yyyy"); PFUserContext.setUser(user); JodaDateConverter conv = new JodaDateConverter(); DateMidnight testDate = createDate(1970, DateTimeConstants.NOVEMBER, 21, EUROPE_BERLIN); assertEquals("21.11.1970", conv.convertToString(testDate, Locale.GERMAN)); user.setLocale(Locale.ENGLISH); user.setDateFormat("MM/dd/yyyy"); conv = new JodaDateConverter(); assertEquals("11/21/1970", conv.convertToString(testDate, Locale.GERMAN)); user.setLocale(Locale.GERMAN); user.setDateFormat("dd.MM.yyyy"); conv = new JodaDateConverter(); testDate = createDate(2009, DateTimeConstants.FEBRUARY, 1, EUROPE_BERLIN); assertEquals("01.02.2009", conv.convertToString(testDate, Locale.GERMAN)); user.setLocale(Locale.ENGLISH); user.setDateFormat("MM/dd/yyyy"); conv = new JodaDateConverter(); assertEquals("02/01/2009", conv.convertToString(testDate, Locale.GERMAN)); }
Example #2
Source File: DateRangeStaticFacotry.java From onetwo with Apache License 2.0 | 6 votes |
public static Collection<DateRange> splitAsDateRangeByWeek(LocalDate start, LocalDate end){ Set<DateRange> dates = new LinkedHashSet<DateRange>(); dates.add(new DateRange(start, start.withDayOfWeek(DateTimeConstants.SUNDAY))); LocalDate startDateOfWeek = start.withDayOfWeek(DateTimeConstants.MONDAY).plusWeeks(1); while(!startDateOfWeek.isAfter(end)){ LocalDate endDateOfWeek = startDateOfWeek.withDayOfWeek(DateTimeConstants.SUNDAY); if(endDateOfWeek.isAfter(end)){ endDateOfWeek = end; } dates.add(new DateRange(startDateOfWeek, endDateOfWeek)); startDateOfWeek = startDateOfWeek.plusWeeks(1); } return dates; }
Example #3
Source File: BasicChronology.java From astor with GNU General Public License v2.0 | 6 votes |
public long getDateTimeMillis( int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond) throws IllegalArgumentException { Chronology base; if ((base = getBase()) != null) { return base.getDateTimeMillis(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond); } FieldUtils.verifyValueBounds(DateTimeFieldType.hourOfDay(), hourOfDay, 0, 23); FieldUtils.verifyValueBounds(DateTimeFieldType.minuteOfHour(), minuteOfHour, 0, 59); FieldUtils.verifyValueBounds(DateTimeFieldType.secondOfMinute(), secondOfMinute, 0, 59); FieldUtils.verifyValueBounds(DateTimeFieldType.millisOfSecond(), millisOfSecond, 0, 999); return getDateMidnightMillis(year, monthOfYear, dayOfMonth) + hourOfDay * DateTimeConstants.MILLIS_PER_HOUR + minuteOfHour * DateTimeConstants.MILLIS_PER_MINUTE + secondOfMinute * DateTimeConstants.MILLIS_PER_SECOND + millisOfSecond; }
Example #4
Source File: CopticChronology.java From astor with GNU General Public License v2.0 | 6 votes |
long calculateFirstDayOfYearMillis(int year) { // Java epoch is 1970-01-01 Gregorian which is 1686-04-23 Coptic. // Calculate relative to the nearest leap year and account for the // difference later. int relativeYear = year - 1687; int leapYears; if (relativeYear <= 0) { // Add 3 before shifting right since /4 and >>2 behave differently // on negative numbers. leapYears = (relativeYear + 3) >> 2; } else { leapYears = relativeYear >> 2; // For post 1687 an adjustment is needed as jan1st is before leap day if (!isLeapYear(year)) { leapYears++; } } long millis = (relativeYear * 365L + leapYears) * (long)DateTimeConstants.MILLIS_PER_DAY; // Adjust to account for difference between 1687-01-01 and 1686-04-23. return millis + (365L - 112) * DateTimeConstants.MILLIS_PER_DAY; }
Example #5
Source File: Alarm.java From prayer-times-android with Apache License 2.0 | 6 votes |
private static int jodaWDToJavaWD(int wd) { switch (wd) { case DateTimeConstants.MONDAY: return Calendar.MONDAY; case DateTimeConstants.TUESDAY: return Calendar.TUESDAY; case DateTimeConstants.WEDNESDAY: return Calendar.WEDNESDAY; case DateTimeConstants.THURSDAY: return Calendar.THURSDAY; case DateTimeConstants.FRIDAY: return Calendar.FRIDAY; case DateTimeConstants.SATURDAY: return Calendar.SATURDAY; case DateTimeConstants.SUNDAY: return Calendar.SUNDAY; } return 0; }
Example #6
Source File: BasicGJChronology.java From astor with GNU General Public License v2.0 | 6 votes |
long getYearDifference(long minuendInstant, long subtrahendInstant) { int minuendYear = getYear(minuendInstant); int subtrahendYear = getYear(subtrahendInstant); // Inlined remainder method to avoid duplicate calls to get. long minuendRem = minuendInstant - getYearMillis(minuendYear); long subtrahendRem = subtrahendInstant - getYearMillis(subtrahendYear); // Balance leap year differences on remainders. if (subtrahendRem >= FEB_29) { if (isLeapYear(subtrahendYear)) { if (!isLeapYear(minuendYear)) { subtrahendRem -= DateTimeConstants.MILLIS_PER_DAY; } } else if (minuendRem >= FEB_29 && isLeapYear(minuendYear)) { minuendRem -= DateTimeConstants.MILLIS_PER_DAY; } } int difference = minuendYear - subtrahendYear; if (minuendRem < subtrahendRem) { difference--; } return difference; }
Example #7
Source File: Nopol2017_0088_s.java From coming with MIT License | 6 votes |
public long getDateTimeMillis( int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond) throws IllegalArgumentException { Chronology base; if ((base = getBase()) != null) { return base.getDateTimeMillis(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond); } FieldUtils.verifyValueBounds(DateTimeFieldType.hourOfDay(), hourOfDay, 0, 23); FieldUtils.verifyValueBounds(DateTimeFieldType.minuteOfHour(), minuteOfHour, 0, 59); FieldUtils.verifyValueBounds(DateTimeFieldType.secondOfMinute(), secondOfMinute, 0, 59); FieldUtils.verifyValueBounds(DateTimeFieldType.millisOfSecond(), millisOfSecond, 0, 999); return getDateMidnightMillis(year, monthOfYear, dayOfMonth) + hourOfDay * DateTimeConstants.MILLIS_PER_HOUR + minuteOfHour * DateTimeConstants.MILLIS_PER_MINUTE + secondOfMinute * DateTimeConstants.MILLIS_PER_SECOND + millisOfSecond; }
Example #8
Source File: Cardumen_0071_s.java From coming with MIT License | 6 votes |
long getYearDifference(long minuendInstant, long subtrahendInstant) { int minuendYear = getYear(minuendInstant); int subtrahendYear = getYear(subtrahendInstant); // Inlined remainder method to avoid duplicate calls to get. long minuendRem = minuendInstant - getYearMillis(minuendYear); long subtrahendRem = subtrahendInstant - getYearMillis(subtrahendYear); // Balance leap year differences on remainders. if (subtrahendRem >= FEB_29) { if (isLeapYear(subtrahendYear)) { if (!isLeapYear(minuendYear)) { subtrahendRem -= DateTimeConstants.MILLIS_PER_DAY; } } else if (minuendRem >= FEB_29 && isLeapYear(minuendYear)) { minuendRem -= DateTimeConstants.MILLIS_PER_DAY; } } int difference = minuendYear - subtrahendYear; if (minuendRem < subtrahendRem) { difference--; } return difference; }
Example #9
Source File: Nopol2017_0088_t.java From coming with MIT License | 6 votes |
/** * @param instant millis from 1970-01-01T00:00:00Z */ int getDayOfWeek(long instant) { // 1970-01-01 is day of week 4, Thursday. long daysSince19700101; if (instant >= 0) { daysSince19700101 = instant / DateTimeConstants.MILLIS_PER_DAY; } else { daysSince19700101 = (instant - (DateTimeConstants.MILLIS_PER_DAY - 1)) / DateTimeConstants.MILLIS_PER_DAY; if (daysSince19700101 < -3) { return 7 + (int) ((daysSince19700101 + 4) % 7); } } return 1 + (int) ((daysSince19700101 + 3) % 7); }
Example #10
Source File: QuarterlyPeriodFilter.java From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License | 6 votes |
private static DateTime fixStartDate(DateTime startDate) { if(startDate==null) { return null; } int month = startDate.getMonthOfYear(); if (month <= 3) { return startDate.withMonthOfYear(DateTimeConstants.JANUARY).withDayOfMonth(1); } else if (month <= 6) { return startDate.withMonthOfYear(DateTimeConstants.APRIL).withDayOfMonth(1); } else if (month <= 9) { return startDate.withMonthOfYear(DateTimeConstants.JULY).withDayOfMonth(1); } else if (month <= 12) { return startDate.withMonthOfYear(DateTimeConstants.OCTOBER).withDayOfMonth(1); } return startDate; }
Example #11
Source File: BiMonthlyPeriodFilter.java From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License | 6 votes |
private static DateTime fixStartDate(DateTime startDate) { if(startDate==null) { return null; } int month = startDate.getMonthOfYear(); if (month <= 2) { return startDate.withMonthOfYear(DateTimeConstants.JANUARY).withDayOfMonth(1); } else if (month <= 4) { return startDate.withMonthOfYear(DateTimeConstants.MARCH).withDayOfMonth(1); } else if (month <= 6) { return startDate.withMonthOfYear(DateTimeConstants.MAY).withDayOfMonth(1); } else if (month <= 8) { return startDate.withMonthOfYear(DateTimeConstants.JULY).withDayOfMonth(1); } else if (month <= 10) { return startDate.withMonthOfYear(DateTimeConstants.SEPTEMBER).withDayOfMonth(1); } else { return startDate.withMonthOfYear(DateTimeConstants.NOVEMBER).withDayOfMonth(1); } }
Example #12
Source File: SixMonthlyAprilPeriodFilter.java From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static DateTime fixStartDate(DateTime startDate) { if(startDate==null) { return null; } int month = startDate.getMonthOfYear(); if (month >= 4 && month <= 9) { return startDate.withMonthOfYear(DateTimeConstants.APRIL).withDayOfMonth(1); } else if( month>9) { return startDate.withMonthOfYear(DateTimeConstants.OCTOBER).withDayOfMonth(1); } else{ return startDate.withYear(startDate.getYear()-1).withMonthOfYear(DateTimeConstants.OCTOBER).withDayOfMonth(1); } }
Example #13
Source File: HijriDate.java From prayer-times-android with Apache License 2.0 | 5 votes |
@NonNull public static List<Pair<HijriDate, Integer>> getHolydaysForHijriYear(int year) { List<Pair<HijriDate, Integer>> dates = new ArrayList<>(); dates.add(new Pair<>(HijriDate.fromHijri(year, MUHARRAM, 1), MONTH)); dates.add(new Pair<>(HijriDate.fromHijri(year, MUHARRAM, 1), ISLAMIC_NEW_YEAR)); dates.add(new Pair<>(HijriDate.fromHijri(year, MUHARRAM, 10), ASHURA)); dates.add(new Pair<>(HijriDate.fromHijri(year, SAFAR, 1), MONTH)); dates.add(new Pair<>(HijriDate.fromHijri(year, RABIAL_AWWAL, 1), MONTH)); dates.add(new Pair<>(HijriDate.fromHijri(year, RABIAL_AWWAL, 11), MAWLID_AL_NABI)); dates.add(new Pair<>(HijriDate.fromHijri(year, RABIAL_AKHIR, 1), MONTH)); dates.add(new Pair<>(HijriDate.fromHijri(year, JUMADAAL_AWWAL, 1), MONTH)); dates.add(new Pair<>(HijriDate.fromHijri(year, JUMADAAL_AKHIR, 1), MONTH)); dates.add(new Pair<>(HijriDate.fromHijri(year, RAJAB, 1), MONTH)); dates.add(new Pair<>(HijriDate.fromHijri(year, RAJAB, 1), THREE_MONTHS)); HijriDate ragaib = HijriDate.fromGreg(HijriDate.fromHijri(year, RAJAB, 1).getLocalDate().withDayOfWeek(DateTimeConstants.FRIDAY)); if (ragaib.getMonth() < RAJAB) ragaib = ragaib.plusDays(7); dates.add(new Pair<>(ragaib.plusDays(-1), RAGAIB)); dates.add(new Pair<>(HijriDate.fromHijri(year, RAJAB, 26), MIRAJ)); dates.add(new Pair<>(HijriDate.fromHijri(year, SHABAN, 1), MONTH)); dates.add(new Pair<>(HijriDate.fromHijri(year, SHABAN, 14), BARAAH)); dates.add(new Pair<>(HijriDate.fromHijri(year, RAMADAN, 1), MONTH)); dates.add(new Pair<>(HijriDate.fromHijri(year, RAMADAN, 1), RAMADAN_BEGIN)); dates.add(new Pair<>(HijriDate.fromHijri(year, RAMADAN, 26), LAYLATALQADR)); dates.add(new Pair<>(HijriDate.fromHijri(year, SHAWWAL, 1).plusDays(-1), LAST_RAMADAN)); dates.add(new Pair<>(HijriDate.fromHijri(year, SHAWWAL, 1), MONTH)); dates.add(new Pair<>(HijriDate.fromHijri(year, SHAWWAL, 1), EID_AL_FITR_DAY1)); dates.add(new Pair<>(HijriDate.fromHijri(year, SHAWWAL, 2), EID_AL_FITR_DAY2)); dates.add(new Pair<>(HijriDate.fromHijri(year, SHAWWAL, 3), EID_AL_FITR_DAY3)); dates.add(new Pair<>(HijriDate.fromHijri(year, DHUL_QADA, 1), MONTH)); dates.add(new Pair<>(HijriDate.fromHijri(year, DHUL_HIJJA, 9), ARAFAT)); dates.add(new Pair<>(HijriDate.fromHijri(year, DHUL_HIJJA, 1), MONTH)); dates.add(new Pair<>(HijriDate.fromHijri(year, DHUL_HIJJA, 10), EID_AL_ADHA_DAY1)); dates.add(new Pair<>(HijriDate.fromHijri(year, DHUL_HIJJA, 11), EID_AL_ADHA_DAY2)); dates.add(new Pair<>(HijriDate.fromHijri(year, DHUL_HIJJA, 12), EID_AL_ADHA_DAY3)); dates.add(new Pair<>(HijriDate.fromHijri(year, DHUL_HIJJA, 13), EID_AL_ADHA_DAY4)); Collections.sort(dates, (o1, o2) -> o1.first.compareTo(o2.first)); return dates; }
Example #14
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; }
Example #15
Source File: Time_27_PeriodFormatterBuilder_s.java From coming with MIT License | 5 votes |
public void printTo(Writer out, ReadablePeriod period, Locale locale) throws IOException { long valueLong = getFieldValue(period); if (valueLong == Long.MAX_VALUE) { return; } int value = (int) valueLong; if (iFieldType >= SECONDS_MILLIS) { value = (int) (valueLong / DateTimeConstants.MILLIS_PER_SECOND); } if (iPrefix != null) { iPrefix.printTo(out, value); } int minDigits = iMinPrintedDigits; if (minDigits <= 1) { FormatUtils.writeUnpaddedInteger(out, value); } else { FormatUtils.writePaddedInteger(out, value, minDigits); } if (iFieldType >= SECONDS_MILLIS) { int dp = (int) (Math.abs(valueLong) % DateTimeConstants.MILLIS_PER_SECOND); if (iFieldType == SECONDS_MILLIS || dp > 0) { out.write('.'); FormatUtils.writePaddedInteger(out, dp, 3); } } if (iSuffix != null) { iSuffix.printTo(out, value); } }
Example #16
Source File: TestReadableDurationConverter.java From astor with GNU General Public License v2.0 | 5 votes |
public void testSetInto_Object() throws Exception { MutablePeriod m = new MutablePeriod(PeriodType.yearMonthDayTime()); ReadableDurationConverter.INSTANCE.setInto(m, new Duration( 3L * DateTimeConstants.MILLIS_PER_DAY + 4L * DateTimeConstants.MILLIS_PER_MINUTE + 5L ), null); assertEquals(0, m.getYears()); assertEquals(0, m.getMonths()); assertEquals(0, m.getWeeks()); assertEquals(0, m.getDays()); assertEquals(3 * 24, m.getHours()); assertEquals(4, m.getMinutes()); assertEquals(0, m.getSeconds()); assertEquals(5, m.getMillis()); }
Example #17
Source File: Time_13_PeriodFormatterBuilder_t.java From coming with MIT License | 5 votes |
public void printTo(StringBuffer buf, ReadablePeriod period, Locale locale) { long valueLong = getFieldValue(period); if (valueLong == Long.MAX_VALUE) { return; } int value = (int) valueLong; if (iFieldType >= SECONDS_MILLIS) { value = (int) (valueLong / DateTimeConstants.MILLIS_PER_SECOND); } if (iPrefix != null) { iPrefix.printTo(buf, value); } int bufLen = buf.length(); int minDigits = iMinPrintedDigits; if (minDigits <= 1) { FormatUtils.appendUnpaddedInteger(buf, value); } else { FormatUtils.appendPaddedInteger(buf, value, minDigits); } if (iFieldType >= SECONDS_MILLIS) { int dp = (int) (Math.abs(valueLong) % DateTimeConstants.MILLIS_PER_SECOND); if (iFieldType == SECONDS_MILLIS || dp > 0) { if (valueLong < 0 && valueLong > -DateTimeConstants.MILLIS_PER_SECOND) { buf.insert(bufLen, '-'); } buf.append('.'); FormatUtils.appendPaddedInteger(buf, dp, 3); } } if (iSuffix != null) { iSuffix.printTo(buf, value); } }
Example #18
Source File: BiWeeklyPeriodFilter.java From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static DateTime getStartDayOfFirstBiWeek(DateTime date){ LocalDate localDate = new LocalDate( date.getYear(), date.getMonthOfYear(), 1 ); while ( localDate.getDayOfWeek() != DateTimeConstants.MONDAY ) { localDate = localDate.plusDays( 1 ); } return localDate.toDateTimeAtStartOfDay(); }
Example #19
Source File: BasicChronology.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Get the millis for the first week of a year. * * @param year the year to use * @return millis */ long getFirstWeekOfYearMillis(int year) { long jan1millis = getYearMillis(year); int jan1dayOfWeek = getDayOfWeek(jan1millis); if (jan1dayOfWeek > (8 - iMinDaysInFirstWeek)) { // First week is end of previous year because it doesn't have enough days. return jan1millis + (8 - jan1dayOfWeek) * (long)DateTimeConstants.MILLIS_PER_DAY; } else { // First week is start of this year because it has enough days. return jan1millis - (jan1dayOfWeek - 1) * (long)DateTimeConstants.MILLIS_PER_DAY; } }
Example #20
Source File: PeriodFormatterBuilder.java From astor with GNU General Public License v2.0 | 5 votes |
public int calculatePrintedLength(ReadablePeriod period, Locale locale) { long valueLong = getFieldValue(period); if (valueLong == Long.MAX_VALUE) { return 0; } int sum = Math.max(FormatUtils.calculateDigitCount(valueLong), iMinPrintedDigits); if (iFieldType >= SECONDS_MILLIS) { // valueLong contains the seconds and millis fields // the minimum output is 0.000, which is 4 or 5 digits with a negative sum = (valueLong < 0 ? Math.max(sum, 5) : Math.max(sum, 4)); // plus one for the decimal point sum++; if (iFieldType == SECONDS_OPTIONAL_MILLIS && (Math.abs(valueLong) % DateTimeConstants.MILLIS_PER_SECOND) == 0) { sum -= 4; // remove three digits and decimal point } // reset valueLong to refer to the seconds part for the prefic/suffix calculation valueLong = valueLong / DateTimeConstants.MILLIS_PER_SECOND; } int value = (int) valueLong; if (iPrefix != null) { sum += iPrefix.calculatePrintedLength(value); } if (iSuffix != null) { sum += iSuffix.calculatePrintedLength(value); } return sum; }
Example #21
Source File: WeeklyWednesdayExpiryDayValidatorTest.java From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testCanNotEditPreviousPeriodEndsSameTodayMinusDifferenceMinusOneExpiryDays() { LocalDate periodDate = new LocalDate(); periodDate = periodDate.minusWeeks(1).withDayOfWeek(DateTimeConstants.WEDNESDAY); int expiryDays = Days.daysBetween(periodDate.plusDays(6), new LocalDate()).getDays() - 1; WeeklyWednesdayExpiryDayValidator weeklyExpiryDayValidator = new WeeklyWednesdayExpiryDayValidator(expiryDays, periodDate.toString(PATTERN)); assertFalse(weeklyExpiryDayValidator.canEdit()); }
Example #22
Source File: FinancialYearAprilExpiryDayValidatorTest.java From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testCanNotEditPreviousPeriodEndsSameTodayMinusDifferenceExpiryDays() { LocalDate periodDate = new LocalDate(); periodDate = periodDate.minusYears(1).withMonthOfYear( DateTimeConstants.APRIL).withDayOfMonth(1); int expiryDays = Days.daysBetween(periodDate.plusYears(1), new LocalDate()).getDays(); FinancialYearAprilExpiryDayValidator yearlyExpiryDayValidator = new FinancialYearAprilExpiryDayValidator( expiryDays, periodDate.toString(PATTERN)); assertFalse(yearlyExpiryDayValidator.canEdit()); }
Example #23
Source File: CalendarWindowsTest.java From beam with Apache License 2.0 | 5 votes |
@Test public void testWeeks() throws Exception { Map<IntervalWindow, Set<String>> expected = new HashMap<>(); final List<Long> timestamps = Arrays.asList( makeTimestamp(2014, 1, 1, 0, 0).getMillis(), makeTimestamp(2014, 1, 5, 5, 5).getMillis(), makeTimestamp(2014, 1, 8, 0, 0).getMillis(), makeTimestamp(2014, 1, 12, 5, 5).getMillis(), makeTimestamp(2015, 1, 1, 0, 0).getMillis(), makeTimestamp(2015, 1, 6, 5, 5).getMillis()); expected.put( new IntervalWindow(makeTimestamp(2014, 1, 1, 0, 0), makeTimestamp(2014, 1, 8, 0, 0)), set(timestamps.get(0), timestamps.get(1))); expected.put( new IntervalWindow(makeTimestamp(2014, 1, 8, 0, 0), makeTimestamp(2014, 1, 15, 0, 0)), set(timestamps.get(2), timestamps.get(3))); expected.put( new IntervalWindow(makeTimestamp(2014, 12, 31, 0, 0), makeTimestamp(2015, 1, 7, 0, 0)), set(timestamps.get(4), timestamps.get(5))); assertEquals( expected, runWindowFn(CalendarWindows.weeks(1, DateTimeConstants.WEDNESDAY), timestamps)); }
Example #24
Source File: BasicWeekyearDateTimeField.java From astor with GNU General Public License v2.0 | 5 votes |
public long roundFloor(long instant) { // Note: This works fine, but it ideally shouldn't invoke other // fields from within a field. instant = iChronology.weekOfWeekyear().roundFloor(instant); int wow = iChronology.getWeekOfWeekyear(instant); if (wow > 1) { instant -= ((long) DateTimeConstants.MILLIS_PER_WEEK) * (wow - 1); } return instant; }
Example #25
Source File: FinancialYearAprilExpiryDayValidatorTest.java From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testCanEditPreviousPeriodEndsSameTodayMinusDifferencePlusTwoExpiryDays() { LocalDate periodDate = new LocalDate(); periodDate = periodDate.minusYears(1).withMonthOfYear( DateTimeConstants.APRIL).withDayOfMonth(1); int expiryDays = Days.daysBetween(periodDate.plusYears(1), new LocalDate()).getDays() + 2; FinancialYearAprilExpiryDayValidator yearlyExpiryDayValidator = new FinancialYearAprilExpiryDayValidator( expiryDays, periodDate.toString(PATTERN)); assertTrue(yearlyExpiryDayValidator.canEdit()); }
Example #26
Source File: 1_BasicChronology.java From SimFix with GNU General Public License v2.0 | 5 votes |
/** * @param instant millis from 1970-01-01T00:00:00Z */ int getMillisOfDay(long instant) { if (instant >= 0) { return (int) (instant % DateTimeConstants.MILLIS_PER_DAY); } else { return (DateTimeConstants.MILLIS_PER_DAY - 1) + (int) ((instant + 1) % DateTimeConstants.MILLIS_PER_DAY); } }
Example #27
Source File: 1_BasicChronology.java From SimFix with GNU General Public License v2.0 | 5 votes |
/** * @param instant millis from 1970-01-01T00:00:00Z */ int getWeekyear(long instant) { int year = getYear(instant); int week = getWeekOfWeekyear(instant, year); if (week == 1) { return getYear(instant + DateTimeConstants.MILLIS_PER_WEEK); } else if (week > 51) { return getYear(instant - (2 * DateTimeConstants.MILLIS_PER_WEEK)); } else { return year; } }
Example #28
Source File: Time_13_PeriodFormatterBuilder_t.java From coming with MIT License | 5 votes |
public int calculatePrintedLength(ReadablePeriod period, Locale locale) { long valueLong = getFieldValue(period); if (valueLong == Long.MAX_VALUE) { return 0; } int sum = Math.max(FormatUtils.calculateDigitCount(valueLong), iMinPrintedDigits); if (iFieldType >= SECONDS_MILLIS) { // valueLong contains the seconds and millis fields // the minimum output is 0.000, which is 4 or 5 digits with a negative sum = (valueLong < 0 ? Math.max(sum, 5) : Math.max(sum, 4)); // plus one for the decimal point sum++; if (iFieldType == SECONDS_OPTIONAL_MILLIS && (Math.abs(valueLong) % DateTimeConstants.MILLIS_PER_SECOND) == 0) { sum -= 4; // remove three digits and decimal point } // reset valueLong to refer to the seconds part for the prefic/suffix calculation valueLong = valueLong / DateTimeConstants.MILLIS_PER_SECOND; } int value = (int) valueLong; if (iPrefix != null) { sum += iPrefix.calculatePrintedLength(value); } if (iSuffix != null) { sum += iSuffix.calculatePrintedLength(value); } return sum; }
Example #29
Source File: DateHelper.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
public final static int convertCalendarDayOfWeekToJoda(final int calendarDayOfWeek) { if (calendarDayOfWeek == Calendar.SUNDAY) { return DateTimeConstants.SUNDAY; } return calendarDayOfWeek - 1; }
Example #30
Source File: WeekThursdayIterator.java From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public ArrayList<DateHolder> next() { cPeriod = cPeriod.plusYears(1); cPeriod = cPeriod.plusMonths(1); cPeriod = cPeriod.withDayOfYear(1).withDayOfWeek(DateTimeConstants.THURSDAY); return generatePeriod(); }