@Test public void testParseMonth() { Month month = Month.parseMonth("1990-01"); assertEquals(1, month.getMonth()); assertEquals(1990, month.getYear().getYear()); month = Month.parseMonth("02-1991"); assertEquals(2, month.getMonth()); assertEquals(1991, month.getYear().getYear()); month = Month.parseMonth(DATE_FORMAT_SYMBOLS.getMonths()[2] + " 1993"); assertEquals(3, month.getMonth()); assertEquals(1993, month.getYear().getYear()); }
public static Month parseMonth(String s) { Month result = null; if (s == null) { return result; } s = s.trim(); int i = Month.findSeparator(s); String s1, s2; boolean yearIsFirst; if (i == -1) { yearIsFirst = true; s1 = s.substring(0, 5); s2 = s.substring(5); } else { s1 = s.substring(0, i).trim(); s2 = s.substring(i + 1, s.length()).trim(); Year y1 = Month.evaluateAsYear(s1); if (y1 == null) { yearIsFirst = false; } else { Year y2 = Month.evaluateAsYear(s2); if (y2 == null) { yearIsFirst = true; } else { yearIsFirst = (s1.length() > s2.length()); } } } Year year; int month; if (yearIsFirst) { year = Month.evaluateAsYear(s1); month = SerialDate.stringToMonthCode(s2); } else { year = Month.evaluateAsYear(s2); month = SerialDate.stringToMonthCode(s1); } if (month == -1) { throw new TimePeriodFormatException("Can't evaluate the month."); } if (year == null) { throw new TimePeriodFormatException("Can't evaluate the year."); } result = new Month(month, year); return result; }
Month extends RegularTimePeriod implements Serializable { public static Month parseMonth(String s) { Month result = null; if (s == null) { return result; } s = s.trim(); int i = Month.findSeparator(s); String s1, s2; boolean yearIsFirst; if (i == -1) { yearIsFirst = true; s1 = s.substring(0, 5); s2 = s.substring(5); } else { s1 = s.substring(0, i).trim(); s2 = s.substring(i + 1, s.length()).trim(); Year y1 = Month.evaluateAsYear(s1); if (y1 == null) { yearIsFirst = false; } else { Year y2 = Month.evaluateAsYear(s2); if (y2 == null) { yearIsFirst = true; } else { yearIsFirst = (s1.length() > s2.length()); } } } Year year; int month; if (yearIsFirst) { year = Month.evaluateAsYear(s1); month = SerialDate.stringToMonthCode(s2); } else { year = Month.evaluateAsYear(s2); month = SerialDate.stringToMonthCode(s1); } if (month == -1) { throw new TimePeriodFormatException("Can't evaluate the month."); } if (year == null) { throw new TimePeriodFormatException("Can't evaluate the year."); } result = new Month(month, year); return result; } }
Month extends RegularTimePeriod implements Serializable { public static Month parseMonth(String s) { Month result = null; if (s == null) { return result; } s = s.trim(); int i = Month.findSeparator(s); String s1, s2; boolean yearIsFirst; if (i == -1) { yearIsFirst = true; s1 = s.substring(0, 5); s2 = s.substring(5); } else { s1 = s.substring(0, i).trim(); s2 = s.substring(i + 1, s.length()).trim(); Year y1 = Month.evaluateAsYear(s1); if (y1 == null) { yearIsFirst = false; } else { Year y2 = Month.evaluateAsYear(s2); if (y2 == null) { yearIsFirst = true; } else { yearIsFirst = (s1.length() > s2.length()); } } } Year year; int month; if (yearIsFirst) { year = Month.evaluateAsYear(s1); month = SerialDate.stringToMonthCode(s2); } else { year = Month.evaluateAsYear(s2); month = SerialDate.stringToMonthCode(s1); } if (month == -1) { throw new TimePeriodFormatException("Can't evaluate the month."); } if (year == null) { throw new TimePeriodFormatException("Can't evaluate the year."); } result = new Month(month, year); return result; } Month();  Month(int month, int year);  Month(int month, Year year);  Month(Date time);  Month(Date time, TimeZone zone, Locale locale); }
Month extends RegularTimePeriod implements Serializable { public static Month parseMonth(String s) { Month result = null; if (s == null) { return result; } s = s.trim(); int i = Month.findSeparator(s); String s1, s2; boolean yearIsFirst; if (i == -1) { yearIsFirst = true; s1 = s.substring(0, 5); s2 = s.substring(5); } else { s1 = s.substring(0, i).trim(); s2 = s.substring(i + 1, s.length()).trim(); Year y1 = Month.evaluateAsYear(s1); if (y1 == null) { yearIsFirst = false; } else { Year y2 = Month.evaluateAsYear(s2); if (y2 == null) { yearIsFirst = true; } else { yearIsFirst = (s1.length() > s2.length()); } } } Year year; int month; if (yearIsFirst) { year = Month.evaluateAsYear(s1); month = SerialDate.stringToMonthCode(s2); } else { year = Month.evaluateAsYear(s2); month = SerialDate.stringToMonthCode(s1); } if (month == -1) { throw new TimePeriodFormatException("Can't evaluate the month."); } if (year == null) { throw new TimePeriodFormatException("Can't evaluate the year."); } result = new Month(month, year); return result; } Month();  Month(int month, int year);  Month(int month, Year year);  Month(Date time);  Month(Date time, TimeZone zone, Locale locale); Year getYear(); int getYearValue(); int getMonth(); @Override long getFirstMillisecond(); @Override long getLastMillisecond(); @Override void peg(Calendar calendar); @Override RegularTimePeriod previous(); @Override RegularTimePeriod next(); @Override long getSerialIndex(); @Override String toString(); @Override boolean equals(Object obj); @Override int hashCode(); @Override int compareTo(TimePeriod o1); @Override long getFirstMillisecond(Calendar calendar); @Override long getLastMillisecond(Calendar calendar); static Month parseMonth(String s); }
Month extends RegularTimePeriod implements Serializable { public static Month parseMonth(String s) { Month result = null; if (s == null) { return result; } s = s.trim(); int i = Month.findSeparator(s); String s1, s2; boolean yearIsFirst; if (i == -1) { yearIsFirst = true; s1 = s.substring(0, 5); s2 = s.substring(5); } else { s1 = s.substring(0, i).trim(); s2 = s.substring(i + 1, s.length()).trim(); Year y1 = Month.evaluateAsYear(s1); if (y1 == null) { yearIsFirst = false; } else { Year y2 = Month.evaluateAsYear(s2); if (y2 == null) { yearIsFirst = true; } else { yearIsFirst = (s1.length() > s2.length()); } } } Year year; int month; if (yearIsFirst) { year = Month.evaluateAsYear(s1); month = SerialDate.stringToMonthCode(s2); } else { year = Month.evaluateAsYear(s2); month = SerialDate.stringToMonthCode(s1); } if (month == -1) { throw new TimePeriodFormatException("Can't evaluate the month."); } if (year == null) { throw new TimePeriodFormatException("Can't evaluate the year."); } result = new Month(month, year); return result; } Month();  Month(int month, int year);  Month(int month, Year year);  Month(Date time);  Month(Date time, TimeZone zone, Locale locale); Year getYear(); int getYearValue(); int getMonth(); @Override long getFirstMillisecond(); @Override long getLastMillisecond(); @Override void peg(Calendar calendar); @Override RegularTimePeriod previous(); @Override RegularTimePeriod next(); @Override long getSerialIndex(); @Override String toString(); @Override boolean equals(Object obj); @Override int hashCode(); @Override int compareTo(TimePeriod o1); @Override long getFirstMillisecond(Calendar calendar); @Override long getLastMillisecond(Calendar calendar); static Month parseMonth(String s);  }