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:gbc.jtimecalc.AbstractTimeDifferenceCalculatorTest.java
public void shouldReturn30DaysWithoutTailingZeroes() { Calendar end = prepareCalendar(2006, Calendar.FEBRUARY, 1, 1, 0, 0, 0); // 1.02.2006 01:00:00.0 setEndTime(end.getTimeInMillis());/*from w ww . j ava 2 s.c o m*/ Calendar start = (Calendar) end.clone(); start.add(Calendar.DATE, -30); setStartTime(start.getTimeInMillis()); // 2.01.2006 00:00:00.0 expectedValue = messages.get("30DaysWithoutTailingZeroes"); }
From source file:org.openmrs.module.radiology.test.RadiologyTestData.java
/** * Convenience method constructing a mock patient for the tests *///from w w w . j a v a2s. co m public static Patient getMockPatient2() { Patient mockPatient = new Patient(); mockPatient.setPatientId(2); mockPatient.addIdentifiers(getPatientIdentifiers("101")); mockPatient.setGender("F"); Set<PersonName> personNames = new HashSet<PersonName>(); PersonName personName = new PersonName(); personName.setFamilyName("Doe"); personName.setGivenName("Jane"); personName.setMiddleName("Francine"); personNames.add(personName); mockPatient.setNames(personNames); Calendar cal = Calendar.getInstance(); cal.set(1955, Calendar.FEBRUARY, 1, 0, 0, 0); mockPatient.setBirthdate(cal.getTime()); return mockPatient; }
From source file:gbc.jtimecalc.AbstractTimeDifferenceCalculatorTest.java
public void shouldReturn2Months3Days0Hours0Minutes0seconds() { Calendar end = prepareCalendar(2006, Calendar.FEBRUARY, 1, 0, 0, 0, 0); // 1.02.2006 00:00:00.0 setEndTime(end.getTimeInMillis());/*w w w .j a v a 2s. com*/ Calendar start = (Calendar) end.clone(); start.set(Calendar.MONTH, Calendar.DECEMBER); start.set(Calendar.YEAR, 2005); // 1.12.2005 00:00:00.0 setStartTime(start.getTimeInMillis()); expectedValue = messages.get("2Months3Days"); }
From source file:org.kuali.kfs.module.endow.businessobject.lookup.CalculateProcessDateUsingFrequencyCodeService.java
/** * This method will check and return either maximum days in the month as 28 or 29 for leap year. * It first sets the month to February and then checks the maximum days.. * @return maxDays Maximum number of days in the month of February for calendar. *///from ww w. j av a 2 s. c om protected int checkMaximumDaysInFebruary() { int maxDays; Calendar februaryMonthlyDateCalendar = Calendar.getInstance(); februaryMonthlyDateCalendar.set(Calendar.MONTH, Calendar.FEBRUARY); maxDays = februaryMonthlyDateCalendar.getActualMaximum(Calendar.DAY_OF_MONTH); return maxDays; }
From source file:org.openmrs.module.radiology.test.RadiologyTestData.java
/** * Convenience method constructing a mock patient for the tests *///w w w . j a v a 2s . com public static Patient getMockPatient3() { Patient mockPatient = new Patient(); mockPatient.setPatientId(3); mockPatient.addIdentifiers(getPatientIdentifiers("102")); mockPatient.setGender("F"); Set<PersonName> personNames = new HashSet<PersonName>(); PersonName personName = new PersonName(); personName.setFamilyName("Diaz"); personName.setGivenName("Maria"); personName.setMiddleName("Sophia"); personNames.add(personName); mockPatient.setNames(personNames); Calendar cal = Calendar.getInstance(); cal.set(1980, Calendar.FEBRUARY, 1, 0, 0, 0); mockPatient.setBirthdate(cal.getTime()); return mockPatient; }
From source file:com.gemstone.gemfire.rest.internal.web.controllers.RestAPIsAndInterOpsDUnitTest.java
public static void doPutsInClientCache() { ClientCache cache = GemFireCacheImpl.getInstance(); assertNotNull(cache);//from ww w. ja va2 s.c om Region<String, Object> region = cache.getRegion(PEOPLE_REGION_NAME); //put person object final Person person1 = new Person(101L, "Mithali", "Dorai", "Raj", DateTimeUtils.createDate(1982, Calendar.DECEMBER, 4), Gender.FEMALE); final Person person2 = new Person(102L, "Sachin", "Ramesh", "Tendulkar", DateTimeUtils.createDate(1975, Calendar.DECEMBER, 14), Gender.MALE); final Person person3 = new Person(103L, "Saurabh", "Baburav", "Ganguly", DateTimeUtils.createDate(1972, Calendar.AUGUST, 29), Gender.MALE); final Person person4 = new Person(104L, "Rahul", "subrymanyam", "Dravid", DateTimeUtils.createDate(1979, Calendar.MARCH, 17), Gender.MALE); final Person person5 = new Person(105L, "Jhulan", "Chidambaram", "Goswami", DateTimeUtils.createDate(1983, Calendar.NOVEMBER, 25), Gender.FEMALE); region.put("1", person1); region.put("2", person2); region.put("3", person3); region.put("4", person4); region.put("5", person5); final Person person6 = new Person(101L, "Rahul", "Rajiv", "Gndhi", DateTimeUtils.createDate(1970, Calendar.MAY, 14), Gender.MALE); final Person person7 = new Person(102L, "Narendra", "Damodar", "Modi", DateTimeUtils.createDate(1945, Calendar.DECEMBER, 24), Gender.MALE); final Person person8 = new Person(103L, "Atal", "Bihari", "Vajpayee", DateTimeUtils.createDate(1920, Calendar.AUGUST, 9), Gender.MALE); final Person person9 = new Person(104L, "Soniya", "Rajiv", "Gandhi", DateTimeUtils.createDate(1929, Calendar.MARCH, 27), Gender.FEMALE); final Person person10 = new Person(104L, "Priyanka", "Robert", "Gandhi", DateTimeUtils.createDate(1973, Calendar.APRIL, 15), Gender.FEMALE); final Person person11 = new Person(104L, "Murali", "Manohar", "Joshi", DateTimeUtils.createDate(1923, Calendar.APRIL, 25), Gender.MALE); final Person person12 = new Person(104L, "Lalkrishna", "Parmhansh", "Advani", DateTimeUtils.createDate(1910, Calendar.JANUARY, 01), Gender.MALE); final Person person13 = new Person(104L, "Shushma", "kumari", "Swaraj", DateTimeUtils.createDate(1943, Calendar.AUGUST, 10), Gender.FEMALE); final Person person14 = new Person(104L, "Arun", "raman", "jetly", DateTimeUtils.createDate(1942, Calendar.OCTOBER, 27), Gender.MALE); final Person person15 = new Person(104L, "Amit", "kumar", "shah", DateTimeUtils.createDate(1958, Calendar.DECEMBER, 21), Gender.MALE); final Person person16 = new Person(104L, "Shila", "kumari", "Dixit", DateTimeUtils.createDate(1927, Calendar.FEBRUARY, 15), Gender.FEMALE); Map<String, Object> userMap = new HashMap<String, Object>(); userMap.put("6", person6); userMap.put("7", person7); userMap.put("8", person8); userMap.put("9", person9); userMap.put("10", person10); userMap.put("11", person11); userMap.put("12", person12); userMap.put("13", person13); userMap.put("14", person14); userMap.put("15", person15); userMap.put("16", person16); region.putAll(userMap); if (cache != null) cache.getLogger().info("Gemfire Cache Client: Puts successfully done"); }
From source file:org.apache.logging.log4j.core.util.datetime.FastDateParserTest.java
private void testLocales(final String format, final boolean eraBC) throws Exception { final Calendar cal = Calendar.getInstance(GMT); cal.clear();//from ww w .ja v a2s .co m cal.set(2003, Calendar.FEBRUARY, 10); if (eraBC) { cal.set(Calendar.ERA, GregorianCalendar.BC); } for (final Locale locale : Locale.getAvailableLocales()) { // ja_JP_JP cannot handle dates before 1868 properly if (eraBC && locale.equals(FastDateParser.JAPANESE_IMPERIAL)) { continue; } final SimpleDateFormat sdf = new SimpleDateFormat(format, locale); final DateParser fdf = getInstance(format, locale); try { checkParse(locale, cal, sdf, fdf); } catch (final ParseException ex) { Assert.fail("Locale " + locale + " failed with " + format + " era " + (eraBC ? "BC" : "AD") + "\n" + trimMessage(ex.toString())); } } }
From source file:Time.java
/** * Return the 1-based month number of the month of this day. 1 = January, 2 = * February and so on.//from ww w .j ava 2s . c om * * @return Month number of this month */ public int getMonthNo() { // It is tempting to return getMonth() + 1 but this is conceptually // wrong, as Calendar month is an enumeration and the values are tags // only and can be anything. switch (getMonth()) { case Calendar.JANUARY: return 1; case Calendar.FEBRUARY: return 2; case Calendar.MARCH: return 3; case Calendar.APRIL: return 4; case Calendar.MAY: return 5; case Calendar.JUNE: return 6; case Calendar.JULY: return 7; case Calendar.AUGUST: return 8; case Calendar.SEPTEMBER: return 9; case Calendar.OCTOBER: return 10; case Calendar.NOVEMBER: return 11; case Calendar.DECEMBER: return 12; } // This will never happen return 0; }
From source file:org.apache.james.protocols.imap.utils.DecoderUtilsTest.java
@Test public void testDecodeMonth() throws Exception { assertEquals(Calendar.JANUARY, DecoderUtils.decodeMonth('J', 'A', 'N')); assertEquals(Calendar.JANUARY, DecoderUtils.decodeMonth('j', 'a', 'n')); assertEquals(Calendar.FEBRUARY, DecoderUtils.decodeMonth('F', 'E', 'B')); assertEquals(Calendar.FEBRUARY, DecoderUtils.decodeMonth('f', 'e', 'b')); assertEquals(Calendar.MARCH, DecoderUtils.decodeMonth('M', 'A', 'R')); assertEquals(Calendar.MARCH, DecoderUtils.decodeMonth('m', 'a', 'r')); assertEquals(Calendar.APRIL, DecoderUtils.decodeMonth('A', 'P', 'R')); assertEquals(Calendar.APRIL, DecoderUtils.decodeMonth('a', 'p', 'r')); assertEquals(Calendar.MAY, DecoderUtils.decodeMonth('M', 'A', 'Y')); assertEquals(Calendar.MAY, DecoderUtils.decodeMonth('m', 'a', 'y')); assertEquals(Calendar.JUNE, DecoderUtils.decodeMonth('J', 'U', 'N')); assertEquals(Calendar.JUNE, DecoderUtils.decodeMonth('j', 'u', 'n')); assertEquals(Calendar.JULY, DecoderUtils.decodeMonth('J', 'U', 'L')); assertEquals(Calendar.JULY, DecoderUtils.decodeMonth('j', 'u', 'l')); assertEquals(Calendar.AUGUST, DecoderUtils.decodeMonth('A', 'U', 'G')); assertEquals(Calendar.AUGUST, DecoderUtils.decodeMonth('a', 'u', 'g')); assertEquals(Calendar.SEPTEMBER, DecoderUtils.decodeMonth('S', 'E', 'P')); assertEquals(Calendar.SEPTEMBER, DecoderUtils.decodeMonth('s', 'e', 'p')); assertEquals(Calendar.OCTOBER, DecoderUtils.decodeMonth('O', 'C', 'T')); assertEquals(Calendar.OCTOBER, DecoderUtils.decodeMonth('o', 'c', 't')); assertEquals(Calendar.NOVEMBER, DecoderUtils.decodeMonth('N', 'O', 'V')); assertEquals(Calendar.NOVEMBER, DecoderUtils.decodeMonth('n', 'o', 'v')); assertEquals(Calendar.DECEMBER, DecoderUtils.decodeMonth('D', 'E', 'C')); assertEquals(Calendar.DECEMBER, DecoderUtils.decodeMonth('d', 'e', 'c')); }
From source file:cn.com.sinosoft.util.time.DurationFormatUtils.java
/** * <p>Formats the time gap as a string, using the specified format. * Padding the left hand side of numbers with zeroes is optional and * the timezone may be specified. </p> * * <p>When calculating the difference between months/days, it chooses to * calculate months first. So when working out the number of months and * days between January 15th and March 10th, it choose 1 month and * 23 days gained by choosing January->February = 1 month and then * calculating days forwards, and not the 1 month and 26 days gained by * choosing March -> February = 1 month and then calculating days * backwards. </p>//from w w w. ja va 2 s . c om * * <p>For more control, the <a href="http://joda-time.sf.net/">Joda-Time</a> * library is recommended.</p> * * @param startMillis the start of the duration * @param endMillis the end of the duration * @param format the way in which to format the duration * @param padWithZeros whether to pad the left hand side of numbers with 0's * @param timezone the millis are defined in * @return the time as a String */ public static String formatPeriod(long startMillis, long endMillis, String format, boolean padWithZeros, TimeZone timezone) { // Used to optimise for differences under 28 days and // called formatDuration(millis, format); however this did not work // over leap years. // TODO: Compare performance to see if anything was lost by // losing this optimisation. Token[] tokens = lexx(format); // timezones get funky around 0, so normalizing everything to GMT // stops the hours being off Calendar start = Calendar.getInstance(timezone); start.setTime(new Date(startMillis)); Calendar end = Calendar.getInstance(timezone); end.setTime(new Date(endMillis)); // initial estimates int milliseconds = end.get(Calendar.MILLISECOND) - start.get(Calendar.MILLISECOND); int seconds = end.get(Calendar.SECOND) - start.get(Calendar.SECOND); int minutes = end.get(Calendar.MINUTE) - start.get(Calendar.MINUTE); int hours = end.get(Calendar.HOUR_OF_DAY) - start.get(Calendar.HOUR_OF_DAY); int days = end.get(Calendar.DAY_OF_MONTH) - start.get(Calendar.DAY_OF_MONTH); int months = end.get(Calendar.MONTH) - start.get(Calendar.MONTH); int years = end.get(Calendar.YEAR) - start.get(Calendar.YEAR); // each initial estimate is adjusted in case it is under 0 while (milliseconds < 0) { milliseconds += 1000; seconds -= 1; } while (seconds < 0) { seconds += 60; minutes -= 1; } while (minutes < 0) { minutes += 60; hours -= 1; } while (hours < 0) { hours += 24; days -= 1; } if (Token.containsTokenWithValue(tokens, M)) { while (days < 0) { days += start.getActualMaximum(Calendar.DAY_OF_MONTH); months -= 1; start.add(Calendar.MONTH, 1); } while (months < 0) { months += 12; years -= 1; } if (!Token.containsTokenWithValue(tokens, y) && years != 0) { while (years != 0) { months += 12 * years; years = 0; } } } else { // there are no M's in the format string if (!Token.containsTokenWithValue(tokens, y)) { int target = end.get(Calendar.YEAR); if (months < 0) { // target is end-year -1 target -= 1; } while ((start.get(Calendar.YEAR) != target)) { days += start.getActualMaximum(Calendar.DAY_OF_YEAR) - start.get(Calendar.DAY_OF_YEAR); // Not sure I grok why this is needed, but the brutal tests show it is if (start instanceof GregorianCalendar) { if ((start.get(Calendar.MONTH) == Calendar.FEBRUARY) && (start.get(Calendar.DAY_OF_MONTH) == 29)) { days += 1; } } start.add(Calendar.YEAR, 1); days += start.get(Calendar.DAY_OF_YEAR); } years = 0; } while (start.get(Calendar.MONTH) != end.get(Calendar.MONTH)) { days += start.getActualMaximum(Calendar.DAY_OF_MONTH); start.add(Calendar.MONTH, 1); } months = 0; while (days < 0) { days += start.getActualMaximum(Calendar.DAY_OF_MONTH); months -= 1; start.add(Calendar.MONTH, 1); } } // The rest of this code adds in values that // aren't requested. This allows the user to ask for the // number of months and get the real count and not just 0->11. if (!Token.containsTokenWithValue(tokens, d)) { hours += 24 * days; days = 0; } if (!Token.containsTokenWithValue(tokens, H)) { minutes += 60 * hours; hours = 0; } if (!Token.containsTokenWithValue(tokens, m)) { seconds += 60 * minutes; minutes = 0; } if (!Token.containsTokenWithValue(tokens, s)) { milliseconds += 1000 * seconds; seconds = 0; } return format(tokens, years, months, days, hours, minutes, seconds, milliseconds, padWithZeros); }