List of usage examples for java.util Calendar FEBRUARY
int FEBRUARY
To view the source code for java.util Calendar FEBRUARY.
Click Source Link
From source file:agency.AgencyManagerImplTest.java
private static Mission newMission02() { Calendar missionBegin = new GregorianCalendar(2014, Calendar.DECEMBER, 6); Calendar missionEnd = new GregorianCalendar(2015, Calendar.FEBRUARY, 9); return newMission("Age of Ultron", missionBegin.getTime(), missionEnd.getTime(), 2, 2, "code name - Dark World"); }
From source file:jscover.util.IoServiceTest.java
@Test public void shouldGenerateReportVersionAndDate() { ReflectionUtils.setField(ioService, "dateTime", dateTime); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, 15); calendar.set(Calendar.MINUTE, 12); calendar.set(Calendar.SECOND, 55); calendar.set(Calendar.DAY_OF_MONTH, 25); calendar.set(Calendar.MONTH, Calendar.FEBRUARY); calendar.set(Calendar.YEAR, 2015); Date date = calendar.getTime(); given(dateTime.getDate()).willReturn(date); String html = ioService.generateJSCoverageHtml("1.0.18-SNAPSHOT"); assertThat(html, containsString("This is version 1.0.18-SNAPSHOT of JSCover")); assertThat(html, containsString("Report generated at 15:12:55 25 Feb 2015")); }
From source file:org.apache.logging.log4j.core.util.datetime.FastDateParserTest.java
@Test public void testDayOf() throws ParseException { final Calendar cal = Calendar.getInstance(NEW_YORK, Locale.US); cal.clear();/*from ww w . j a v a 2 s . co m*/ cal.set(2003, Calendar.FEBRUARY, 10); final DateParser fdf = getInstance("W w F D y", NEW_YORK, Locale.US); assertEquals(cal.getTime(), fdf.parse("3 7 2 41 03")); }
From source file:com.tr4android.support.extension.picker.date.SimpleMonthView.java
private static int getDaysInMonth(int month, int year) { switch (month) { case Calendar.JANUARY: case Calendar.MARCH: case Calendar.MAY: case Calendar.JULY: case Calendar.AUGUST: case Calendar.OCTOBER: case Calendar.DECEMBER: return 31; case Calendar.APRIL: case Calendar.JUNE: case Calendar.SEPTEMBER: case Calendar.NOVEMBER: return 30; case Calendar.FEBRUARY: return (year % 4 == 0) ? 29 : 28; default://from w w w. ja v a 2 s . com throw new IllegalArgumentException("Invalid Month"); } }
From source file:org.apache.logging.log4j.core.util.datetime.FastDateParserTest.java
/** * Test case for {@link FastDateParser#FastDateParser(String, TimeZone, Locale)}. * @throws ParseException so we don't have to catch it *//*w w w .j ava 2s. c o m*/ @Test public void testShortDateStyleWithLocales() throws ParseException { DateParser fdf = getDateInstance(FastDateFormat.SHORT, Locale.US); final Calendar cal = Calendar.getInstance(); cal.clear(); cal.set(2004, Calendar.FEBRUARY, 3); assertEquals(cal.getTime(), fdf.parse("2/3/04")); fdf = getDateInstance(FastDateFormat.SHORT, SWEDEN); assertEquals(cal.getTime(), fdf.parse("2004-02-03")); }
From source file:com.concursive.connect.web.modules.calendar.utils.CalendarView.java
/** * Returns the cell representing the last day in the 42 cell grid Creation * date: (5/2/2000 2:57:08 AM)/*from w w w . j av a 2 s . c o m*/ * * @param tmp Description of Parameter * @return int */ public int getEndCell(Calendar tmp) { int endCell = DAYSINMONTH[tmp.get(Calendar.MONTH)] + this.getStartCell(tmp) - 1; if (tmp.get(Calendar.MONTH) == Calendar.FEBRUARY && ((GregorianCalendar) tmp).isLeapYear(tmp.get(Calendar.YEAR))) { endCell++; } return endCell; }
From source file:org.openmrs.module.radiology.DicomUtilsComponentTest.java
/** * Convenience method to create a mock radiology order *//* w w w.ja v a 2s .c om*/ RadiologyOrder getMockRadiologyOrder() throws Exception { Patient mockPatient = new Patient(); mockPatient.setPatientId(1); PatientIdentifierType patientIdentifierType = new PatientIdentifierType(); patientIdentifierType.setPatientIdentifierTypeId(1); patientIdentifierType.setName("Test Identifier Type"); patientIdentifierType.setDescription("Test description"); PatientIdentifier patientIdentifier = new PatientIdentifier(); patientIdentifier.setIdentifierType(patientIdentifierType); patientIdentifier.setIdentifier("100"); patientIdentifier.setPreferred(true); Set<PatientIdentifier> patientIdentifiers = new HashSet<PatientIdentifier>(); patientIdentifiers.add(patientIdentifier); mockPatient.addIdentifiers(patientIdentifiers); mockPatient.setGender("M"); Set<PersonName> personNames = new HashSet<PersonName>(); PersonName personName = new PersonName(); personName.setFamilyName("Doe"); personName.setGivenName("John"); personName.setMiddleName("Francis"); personNames.add(personName); mockPatient.setNames(personNames); Calendar calendar = Calendar.getInstance(); calendar.set(1950, Calendar.APRIL, 1, 0, 0, 0); mockPatient.setBirthdate(calendar.getTime()); RadiologyOrder mockRadiologyOrder = new RadiologyOrder(); mockRadiologyOrder.setOrderId(20); Field orderNumber = Order.class.getDeclaredField("orderNumber"); orderNumber.setAccessible(true); orderNumber.set(mockRadiologyOrder, "ORD-" + mockRadiologyOrder.getOrderId()); mockRadiologyOrder.setPatient(mockPatient); calendar.set(2015, Calendar.FEBRUARY, 4, 14, 35, 0); mockRadiologyOrder.setScheduledDate(calendar.getTime()); mockRadiologyOrder.setUrgency(Order.Urgency.ON_SCHEDULED_DATE); mockRadiologyOrder.setInstructions("CT ABDOMEN PANCREAS WITH IV CONTRAST"); return mockRadiologyOrder; }
From source file:com.zimbra.cs.mailbox.calendar.ZRecur.java
public List<Date> expandRecurrenceOverRange(ParsedDateTime dtStart, long rangeStart, long rangeEnd) throws ServiceException { List<Date> toRet = new LinkedList<Date>(); Date rangeStartDate = new Date(rangeStart); // subtract 1000ms (1sec) because the code in the method treats // end time as inclusive while the rangeEnd input argument is // exclusive value Date rangeEndDate = new Date(rangeEnd - 1000); Date dtStartDate = new Date(dtStart.getUtcTime()); Date earliestDate;/* w w w . ja va 2s . c o m*/ if (dtStartDate.after(rangeStartDate)) earliestDate = dtStartDate; else earliestDate = rangeStartDate; if (mUntil != null) { Date until = mUntil.getDateForRecurUntil(dtStart.getTimeZone()); if (until.before(rangeEndDate)) rangeEndDate = until; } // Set limit of expansion count. int maxInstancesFromConfig = sExpansionLimits.maxInstances; int maxInstancesExpanded; if (maxInstancesFromConfig <= 0) maxInstancesExpanded = mCount; else if (mCount <= 0) maxInstancesExpanded = maxInstancesFromConfig; else maxInstancesExpanded = Math.min(mCount, maxInstancesFromConfig); int numInstancesExpanded = 1; // initially 1 rather than 0 because DTSTART is always included // Set hard limit of expansion time range. (bug 21989) ParsedDateTime earliestDateTime = ParsedDateTime.fromUTCTime(earliestDate.getTime()); Date hardEndDate = getEstimatedEndTime(earliestDateTime); if (hardEndDate.before(rangeEndDate)) rangeEndDate = hardEndDate; if (rangeEndDate.before(earliestDate)) { ZimbraLog.calendar.debug( "Expanding recurrence over range where range end %s is before earliest date %s", DateUtil.formatDate(rangeEndDate), DateUtil.formatDate(earliestDate)); return toRet; } GregorianCalendar cur = dtStart.getCalendarCopy(); int baseMonthDay = cur.get(Calendar.DAY_OF_MONTH); boolean baseIsLeapDay = ((baseMonthDay == 29) && (cur.get(Calendar.MONTH) == Calendar.FEBRUARY)); // until we hit rangeEnd, or we've SAVED count entries: // // gather each set { // // // // curDate forward one INTERVAL // // } // check Set against BYSETPOS & ranges & count // int interval = mInterval; if (interval <= 0) interval = 1; // DTSTART is always part of the expansion, as long as it falls within // the range. if (!dtStartDate.before(earliestDate) && !dtStartDate.after(rangeEndDate)) toRet.add(dtStartDate); int numConsecutiveIterationsWithoutMatchingInstance = 0; boolean pastHardEndTime = false; long numIterations = 0; // track how many times we looped while (!pastHardEndTime && (maxInstancesExpanded <= 0 || numInstancesExpanded < maxInstancesExpanded)) { numIterations++; boolean curIsAtOrAfterEarliestDate = !cur.getTime().before(earliestDate); boolean curIsAfterEndDate = cur.getTime().after(rangeEndDate); List<Calendar> addList = new LinkedList<Calendar>(); switch (mFreq) { case HOURLY: /* * BYSECOND - for each listed second * BYMINUTE - for each listed minute in hour * BYHOUR - match iff in hour list * BYDAY - for each day listed * BYMONTHDAY - only those monthdays * BYYEARDAY - only those yeardays * BYMONTH - only those months */ if (!checkMonthList(cur)) continue; if (!checkYearDayList(cur)) continue; if (!checkMonthDayList(cur)) continue; if (!checkDayList(cur)) continue; if (!checkHourList(cur)) continue; addList.add((Calendar) (cur.clone())); cur.add(Calendar.HOUR_OF_DAY, interval); addList = expandHourList(addList); addList = expandMinuteList(addList); addList = expandSecondList(addList); break; case DAILY: /* * BYSECOND - for each listed second in day * BYMINUTE - for each listed minute in day * BYHOUR - for each listed hour in day * BYDAY - no ordinal allowed, match iff in day list * BYMONTHDAY - only that day * BYYEARDAY - only that day * BYWEEKNO -- YEARLY ONLY * BYMONTH - only that month * * while (count check & until check & rangeEnd check) { * if (byMonth && !month matches) * curDay = set MONTH to matching month * * if (byYearDay && !yearday matches) * curDay = set DAY to next matching yearday * * if (byMonthday && !monthday matches) * curDay = skip to next matching monthday * * if (byDay && !day in list) * curDay = skip to next mathcing byDay * * if (!byHour or FOR EACH HOUR IN HOURLIST) * if (!byMinute or FOR EACH MINUTE IN MINLIST) * if (!bySecond or FOR EACH SECOND IN LIST) * ----add to list--- * * check against BYSETPOS * * curDay+=1 day * } * */ if (!checkMonthList(cur)) continue; if (!checkYearDayList(cur)) continue; if (!checkMonthDayList(cur)) continue; if (!checkDayList(cur)) continue; addList.add((Calendar) (cur.clone())); cur.add(Calendar.DAY_OF_YEAR, interval); addList = expandHourList(addList); addList = expandMinuteList(addList); addList = expandSecondList(addList); break; case WEEKLY: /* * BYSECOND - for every listed second * BYMINUTE - for every listed minute * BYHOUR - for every listed hour * BYDAY - for every listed day * BYMONTHDAY - MAYBE once a month * BYYEARDAY - MAYBE once a year * BYMONTH - iff month matches * * for each (INTERVAL)WEEK{ * if (byMonth && !month matches) * curDay = set MONTH to DtStart in next matching month * * if (byYearDay && !yearday matches) * curDay = set date to next matching yearday * * if (byMonthDay && !monthday matches) * curDay = skip to next matching monthday * * if (!byDay or FOREACH day in list) * if (!byHour or FOREACH hour in list) * if (!byMinute or FOREACH minute in list) * if (!bySecond or FOREACH second in list) * ----add to list---- * * check against BYSETPOS * * curDay += 1 week * } while (count check & until check & rangeEnd check) * */ if (!checkMonthList(cur)) continue; if (!checkYearDayList(cur)) continue; if (!checkMonthDayList(cur)) continue; addList.add((Calendar) (cur.clone())); cur.add(Calendar.WEEK_OF_YEAR, interval); addList = expandDayListForWeekly(addList); addList = expandHourList(addList); addList = expandMinuteList(addList); addList = expandSecondList(addList); break; case MONTHLY: if (!checkMonthList(cur)) continue; if (!checkYearDayList(cur)) continue; addList.add((Calendar) (cur.clone())); cur.set(Calendar.DAY_OF_MONTH, 1); cur.add(Calendar.MONTH, interval); int daysInMonth = cur.getActualMaximum(Calendar.DAY_OF_MONTH); cur.set(Calendar.DAY_OF_MONTH, Math.min(baseMonthDay, daysInMonth)); addList = expandMonthDayList(addList); addList = expandDayListForMonthlyYearly(addList); addList = expandHourList(addList); addList = expandMinuteList(addList); addList = expandSecondList(addList); break; case YEARLY: /* * BYSECOND * BYMINUTE * BYHOUR * BYDAY * BYMONTHDAY * BYYEARDAY * BYWEEKNO - specified week * BYMONTH - once */ if (baseIsLeapDay) { // previously adding a year to a leap day will have rounded down to the 28th. // If this happened, we need to be sure that if we are back in a leap // year, it is back at 29th cur.set(Calendar.DAY_OF_MONTH, cur.getActualMaximum(Calendar.DAY_OF_MONTH)); } if (ignoreYearForRecurrenceExpansion(cur, baseIsLeapDay)) { cur.add(Calendar.YEAR, interval); break; } addList.add((Calendar) (cur.clone())); cur.add(Calendar.YEAR, interval); addList = expandMonthList(addList); addList = expandYearDayList(addList); addList = expandMonthDayList(addList); addList = expandDayListForMonthlyYearly(addList); addList = expandHourList(addList); addList = expandMinuteList(addList); addList = expandSecondList(addList); break; default: // MINUTELY and SECONDLY are intentionally not supported for performance reasons. return toRet; } addList = handleSetPos(addList); boolean noInstanceFound = true; boolean foundInstancePastEndDate = false; // add all the ones that match! for (Calendar addCal : addList) { Date toAdd = addCal.getTime(); // We already counted DTSTART before the main loop, so don't // count it twice. if (toAdd.compareTo(dtStartDate) == 0) { noInstanceFound = false; continue; } // we still have expanded this instance, even if it isn't in our // current date window if (toAdd.after(dtStartDate)) numInstancesExpanded++; if (!toAdd.after(rangeEndDate)) { if (!toAdd.before(earliestDate)) { toRet.add(toAdd); noInstanceFound = false; } } else { foundInstancePastEndDate = true; break; } if (maxInstancesExpanded > 0 && numInstancesExpanded >= maxInstancesExpanded) break; } // Detect invalid rule. If the rule was invalid the current iteration, which is for the current // frequency interval, would have found no matching instance. The next iteration will also find // no matching instance, and there is no need to keep iterating until we go past the hard end // time or COUNT/UNTIL limit. // // However, we have to make an exception for leap year. An yearly rule looking for February 29th // will find no instance in up to 3 consecutive years before finding Feb 29th in the fourth year. // // So the invalid rule detection must look for at least 4 consecutive failed iterations. if (curIsAtOrAfterEarliestDate) { if (noInstanceFound) numConsecutiveIterationsWithoutMatchingInstance++; else numConsecutiveIterationsWithoutMatchingInstance = 0; if (numConsecutiveIterationsWithoutMatchingInstance >= 4) { ZimbraLog.calendar.warn("Invalid recurrence rule: " + toString()); return toRet; } } pastHardEndTime = foundInstancePastEndDate || (noInstanceFound && curIsAfterEndDate); } return toRet; }
From source file:cn.mljia.common.notify.utils.DateUtils.java
/** * ?/*w w w . j a v a 2 s . c om*/ * * @param date * @return */ public static Date[] getSeasonDate(Date date) { Date[] season = new Date[3]; Calendar c = Calendar.getInstance(); c.setTime(date); int nSeason = getSeason(date); if (nSeason == 1) {// c.set(Calendar.MONTH, Calendar.JANUARY); season[0] = c.getTime(); c.set(Calendar.MONTH, Calendar.FEBRUARY); season[1] = c.getTime(); c.set(Calendar.MONTH, Calendar.MARCH); season[2] = c.getTime(); } else if (nSeason == 2) {// c.set(Calendar.MONTH, Calendar.APRIL); season[0] = c.getTime(); c.set(Calendar.MONTH, Calendar.MAY); season[1] = c.getTime(); c.set(Calendar.MONTH, Calendar.JUNE); season[2] = c.getTime(); } else if (nSeason == 3) {// c.set(Calendar.MONTH, Calendar.JULY); season[0] = c.getTime(); c.set(Calendar.MONTH, Calendar.AUGUST); season[1] = c.getTime(); c.set(Calendar.MONTH, Calendar.SEPTEMBER); season[2] = c.getTime(); } else if (nSeason == 4) {// c.set(Calendar.MONTH, Calendar.OCTOBER); season[0] = c.getTime(); c.set(Calendar.MONTH, Calendar.NOVEMBER); season[1] = c.getTime(); c.set(Calendar.MONTH, Calendar.DECEMBER); season[2] = c.getTime(); } return season; }
From source file:cn.mljia.common.notify.utils.DateUtils.java
/** * /*from w w w . j a v a 2s . c om*/ * 1 2 3 4 * * @param date * @return */ public static int getSeason(Date date) { int season = 0; Calendar c = Calendar.getInstance(); c.setTime(date); int month = c.get(Calendar.MONTH); switch (month) { case Calendar.JANUARY: case Calendar.FEBRUARY: case Calendar.MARCH: season = 1; break; case Calendar.APRIL: case Calendar.MAY: case Calendar.JUNE: season = 2; break; case Calendar.JULY: case Calendar.AUGUST: case Calendar.SEPTEMBER: season = 3; break; case Calendar.OCTOBER: case Calendar.NOVEMBER: case Calendar.DECEMBER: season = 4; break; default: break; } return season; }