Java Code Examples for java.util.Calendar#MAY

The following examples show how to use java.util.Calendar#MAY . 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: Utils.java    From Conquer with Apache License 2.0 6 votes vote down vote up
public 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:
               throw new IllegalArgumentException("Invalid Month");
       }
}
 
Example 2
Source File: Utils.java    From BottomSheetPickers with Apache License 2.0 6 votes vote down vote up
public 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:
            throw new IllegalArgumentException("Invalid Month");
    }
}
 
Example 3
Source File: DateTools.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
public static Integer season(Date date) throws Exception {
	Calendar cal = DateUtils.toCalendar(date);
	switch (cal.get(Calendar.MONTH)) {
	case Calendar.JANUARY:
	case Calendar.FEBRUARY:
	case Calendar.MARCH:
		return 1;
	case Calendar.APRIL:
	case Calendar.MAY:
	case Calendar.JUNE:
		return 2;
	case Calendar.JULY:
	case Calendar.AUGUST:
	case Calendar.SEPTEMBER:
		return 3;
	case Calendar.OCTOBER:
	case Calendar.NOVEMBER:
	case Calendar.DECEMBER:
	default:
		return 4;
	}
}
 
Example 4
Source File: Utils.java    From DateTimepicker with Apache License 2.0 6 votes vote down vote up
public 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:
            throw new IllegalArgumentException("Invalid Month");
    }
}
 
Example 5
Source File: Utils.java    From narrate-android with Apache License 2.0 6 votes vote down vote up
public 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:
            throw new IllegalArgumentException("Invalid Month");
    }
}
 
Example 6
Source File: CalendarUtils.java    From CalendarListview with MIT License 6 votes vote down vote up
public 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 && year % 100 != 0) || (year % 400 == 0)) ? 29 : 28;
           default:
               throw new IllegalArgumentException("Invalid Month");
       }
}
 
Example 7
Source File: Util.java    From whyline with MIT License 6 votes vote down vote up
public static String getMonthString(int month) {
	
	switch(month) {
	case Calendar.JANUARY : return "January";
	case Calendar.FEBRUARY : return "February";
	case Calendar.MARCH : return "March";
	case Calendar.APRIL : return "April";
	case Calendar.MAY : return "May";
	case Calendar.JUNE : return "June";
	case Calendar.JULY : return "July";
	case Calendar.AUGUST : return "August";
	case Calendar.SEPTEMBER : return "September";
	case Calendar.OCTOBER : return "October";
	case Calendar.NOVEMBER : return "November";
	case Calendar.DECEMBER : return "December";
	default : return "invalid month";
}

}
 
Example 8
Source File: TimestampInequalityRuleTest.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
@Test
public void testRuleWithTBetweenDateAndTime5() throws IOException, ClassNotFoundException {
  Rule rule = TimestampInequalityRule.getRule(">=", "2008-05-21T00");
  Calendar cal = new GregorianCalendar(2008, Calendar.MAY, 21, 1, 45, 44);
  LogData logData = createLogData(cal);
  AssertJUnit.assertTrue(rule.evaluate(logData, null));
}
 
Example 9
Source File: TimestampInequalityRuleTest.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
/**
 * Tests evaluate of a deserialized clone when rule is satisified.
 */
@Test
public void test3() throws IOException, ClassNotFoundException {
  Rule rule = (Rule) SerializationTestHelper.serializeClone(TimestampInequalityRule.getRule(">=", "2008-05-21 00:44:45"));
  Calendar cal = new GregorianCalendar(2008, Calendar.MAY, 21, 0, 45, 44);
  LogData logData = createLogData(cal);
  AssertJUnit.assertTrue(rule.evaluate(logData, null));
}
 
Example 10
Source File: HttpDateTime.java    From play-apk-expansion with Apache License 2.0 5 votes vote down vote up
private static int getMonth(String monthString) {
    int hash = Character.toLowerCase(monthString.charAt(0)) +
            Character.toLowerCase(monthString.charAt(1)) +
            Character.toLowerCase(monthString.charAt(2)) - 3 * 'a';
    switch (hash) {
        case 22:
            return Calendar.JANUARY;
        case 10:
            return Calendar.FEBRUARY;
        case 29:
            return Calendar.MARCH;
        case 32:
            return Calendar.APRIL;
        case 36:
            return Calendar.MAY;
        case 42:
            return Calendar.JUNE;
        case 40:
            return Calendar.JULY;
        case 26:
            return Calendar.AUGUST;
        case 37:
            return Calendar.SEPTEMBER;
        case 35:
            return Calendar.OCTOBER;
        case 48:
            return Calendar.NOVEMBER;
        case 9:
            return Calendar.DECEMBER;
        default:
            throw new IllegalArgumentException();
    }
}
 
Example 11
Source File: HttpDateTime.java    From android-download-manager with Apache License 2.0 5 votes vote down vote up
private static int getMonth(String monthString) {
	int hash = Character.toLowerCase(monthString.charAt(0))
			+ Character.toLowerCase(monthString.charAt(1))
			+ Character.toLowerCase(monthString.charAt(2)) - 3 * 'a';
	switch (hash) {
	case 22:
		return Calendar.JANUARY;
	case 10:
		return Calendar.FEBRUARY;
	case 29:
		return Calendar.MARCH;
	case 32:
		return Calendar.APRIL;
	case 36:
		return Calendar.MAY;
	case 42:
		return Calendar.JUNE;
	case 40:
		return Calendar.JULY;
	case 26:
		return Calendar.AUGUST;
	case 37:
		return Calendar.SEPTEMBER;
	case 35:
		return Calendar.OCTOBER;
	case 48:
		return Calendar.NOVEMBER;
	case 9:
		return Calendar.DECEMBER;
	default:
		throw new IllegalArgumentException();
	}
}
 
Example 12
Source File: TimestampInequalityRuleTest.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
/**
 * Tests evaluate of a deserialized clone when rule is not satisfied.
 */
@Test
public void test4() throws IOException, ClassNotFoundException {
  Rule rule = (Rule) SerializationTestHelper.serializeClone(TimestampInequalityRule.getRule("<", "2008-05-21 00:44:44"));
  Calendar cal = new GregorianCalendar(2008, Calendar.MAY, 21, 0, 45, 44);
  LogData logData = createLogData(cal);
  AssertJUnit.assertFalse(rule.evaluate(logData, null));
}
 
Example 13
Source File: HttpDateTime.java    From UnityOBBDownloader with Apache License 2.0 5 votes vote down vote up
private static int getMonth(String monthString) {
    int hash = Character.toLowerCase(monthString.charAt(0)) +
            Character.toLowerCase(monthString.charAt(1)) +
            Character.toLowerCase(monthString.charAt(2)) - 3 * 'a';
    switch (hash) {
        case 22:
            return Calendar.JANUARY;
        case 10:
            return Calendar.FEBRUARY;
        case 29:
            return Calendar.MARCH;
        case 32:
            return Calendar.APRIL;
        case 36:
            return Calendar.MAY;
        case 42:
            return Calendar.JUNE;
        case 40:
            return Calendar.JULY;
        case 26:
            return Calendar.AUGUST;
        case 37:
            return Calendar.SEPTEMBER;
        case 35:
            return Calendar.OCTOBER;
        case 48:
            return Calendar.NOVEMBER;
        case 9:
            return Calendar.DECEMBER;
        default:
            throw new IllegalArgumentException();
    }
}
 
Example 14
Source File: MonthHolderTest.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testDays()
{
  final MonthHolder mh = new MonthHolder(2013, Calendar.MAY);
  final List<DayHolder> list = mh.getDays();
  Assert.assertEquals(31, list.size());
  for (final DayHolder dh : list) {
    Assert.assertEquals(Calendar.MAY, dh.getMonth());
  }
  Assert.assertEquals(1, list.get(0).getDayOfMonth());
  Assert.assertEquals(31, list.get(30).getDayOfMonth());
}
 
Example 15
Source File: DateTools.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
public static Date ceilSeason(Date date, Integer adjust) throws Exception {
	Calendar cal = DateUtils.toCalendar(date);
	switch (cal.get(Calendar.MONTH)) {
	case Calendar.JANUARY:
		cal.set(Calendar.MONTH, Calendar.MARCH);
		break;
	case Calendar.FEBRUARY:
		cal.set(Calendar.MONTH, Calendar.MARCH);
		break;
	case Calendar.MARCH:
		cal.set(Calendar.MONTH, Calendar.MARCH);
		break;
	case Calendar.APRIL:
		cal.set(Calendar.MONTH, Calendar.JUNE);
		break;
	case Calendar.MAY:
		cal.set(Calendar.MONTH, Calendar.JUNE);
		break;
	case Calendar.JUNE:
		cal.set(Calendar.MONTH, Calendar.JUNE);
		break;
	case Calendar.JULY:
		cal.set(Calendar.MONTH, Calendar.SEPTEMBER);
		break;
	case Calendar.AUGUST:
		cal.set(Calendar.MONTH, Calendar.SEPTEMBER);
		break;
	case Calendar.SEPTEMBER:
		cal.set(Calendar.MONTH, Calendar.SEPTEMBER);
		break;
	case Calendar.OCTOBER:
		cal.set(Calendar.MONTH, Calendar.DECEMBER);
		break;
	case Calendar.NOVEMBER:
		cal.set(Calendar.MONTH, Calendar.DECEMBER);
		break;
	case Calendar.DECEMBER:
		cal.set(Calendar.MONTH, Calendar.DECEMBER);
		break;
	default:
	}
	if ((null != adjust) && (adjust != 0)) {
		cal.add(Calendar.MONTH, (adjust * 3));
	}
	return DateUtils.ceiling(cal, Calendar.MONTH).getTime();
}
 
Example 16
Source File: ISO8601DateFormat.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
    Appends a date in the format "YYYY-mm-dd HH:mm:ss,SSS"
    to <code>sbuf</code>. For example: "1999-11-27 15:49:37,459".

    @param sbuf the <code>StringBuffer</code> to write to
 */
 public
 StringBuffer format(Date date, StringBuffer sbuf,
	      FieldPosition fieldPosition) {

   long now = date.getTime();
   int millis = (int)(now % 1000);

   if ((now - millis) != lastTime) {
     // We reach this point at most once per second
     // across all threads instead of each time format()
     // is called. This saves considerable CPU time.

     calendar.setTime(date);

     int start = sbuf.length();

     int year =  calendar.get(Calendar.YEAR);
     sbuf.append(year);

     String month;
     switch(calendar.get(Calendar.MONTH)) {
     case Calendar.JANUARY: month = "-01-"; break;
     case Calendar.FEBRUARY: month = "-02-";  break;
     case Calendar.MARCH: month = "-03-"; break;
     case Calendar.APRIL: month = "-04-";  break;
     case Calendar.MAY: month = "-05-"; break;
     case Calendar.JUNE: month = "-06-";  break;
     case Calendar.JULY: month = "-07-"; break;
     case Calendar.AUGUST: month = "-08-";  break;
     case Calendar.SEPTEMBER: month = "-09-"; break;
     case Calendar.OCTOBER: month = "-10-"; break;
     case Calendar.NOVEMBER: month = "-11-";  break;
     case Calendar.DECEMBER: month = "-12-";  break;
     default: month = "-NA-"; break;
     }
     sbuf.append(month);

     int day = calendar.get(Calendar.DAY_OF_MONTH);
     if(day < 10)
sbuf.append('0');
     sbuf.append(day);

     sbuf.append(' ');

     int hour = calendar.get(Calendar.HOUR_OF_DAY);
     if(hour < 10) {
sbuf.append('0');
     }
     sbuf.append(hour);
     sbuf.append(':');

     int mins = calendar.get(Calendar.MINUTE);
     if(mins < 10) {
sbuf.append('0');
     }
     sbuf.append(mins);
     sbuf.append(':');

     int secs = calendar.get(Calendar.SECOND);
     if(secs < 10) {
sbuf.append('0');
     }
     sbuf.append(secs);

     sbuf.append(',');

     // store the time string for next time to avoid recomputation
     sbuf.getChars(start, sbuf.length(), lastTimeString, 0);
     lastTime = now - millis;
   }
   else {
     sbuf.append(lastTimeString);
   }


   if (millis < 100)
     sbuf.append('0');
   if (millis < 10)
     sbuf.append('0');

   sbuf.append(millis);
   return sbuf;
 }
 
Example 17
Source File: Monthname.java    From tddl5 with Apache License 2.0 4 votes vote down vote up
@Override
public Object compute(Object[] args, ExecutionContext ec) {
    for (Object arg : args) {
        if (ExecUtils.isNull(arg)) {
            return null;
        }
    }

    java.sql.Timestamp timestamp = DataType.TimestampType.convertFrom(args[0]);
    Calendar cal = Calendar.getInstance();
    cal.setTime(timestamp);

    int monthName = cal.get(Calendar.MONTH);
    switch (monthName) {
        case Calendar.JANUARY:
            return "January";
        case Calendar.FEBRUARY:
            return "February";
        case Calendar.MARCH:
            return "March";
        case Calendar.APRIL:
            return "April";
        case Calendar.MAY:
            return "May";
        case Calendar.JUNE:
            return "June";
        case Calendar.JULY:
            return "July";
        case Calendar.AUGUST:
            return "August";
        case Calendar.SEPTEMBER:
            return "September";
        case Calendar.OCTOBER:
            return "October";
        case Calendar.NOVEMBER:
            return "November";
        case Calendar.DECEMBER:
            return "December";
        default:
            return "Undecimber";
    }
}
 
Example 18
Source File: TimeConstraint.java    From hawkular-alerts with Apache License 2.0 4 votes vote down vote up
private int month(String sMonth) {
    if (isEmpty(sMonth)) {
        return -1;
    }
    if (sMonth.length() < 3) {
        return -1;
    }
    String prefix = sMonth.substring(0, 3).toLowerCase();
    MONTH m = MONTH.fromString(prefix);
    if (m == null) {
        return -1;
    }
    switch (m) {
        case JANUARY:
            return Calendar.JANUARY;
        case FEBRUARY:
            return Calendar.FEBRUARY;
        case MARCH:
            return Calendar.MARCH;
        case APRIL:
            return Calendar.APRIL;
        case MAY:
            return Calendar.MAY;
        case JUNE:
            return Calendar.JUNE;
        case JULY:
            return Calendar.JULY;
        case AUGUST:
            return Calendar.AUGUST;
        case SEPTEMBER:
            return Calendar.SEPTEMBER;
        case OCTOBER:
            return Calendar.OCTOBER;
        case NOVEMBER:
            return Calendar.NOVEMBER;
        case DECEMBER:
            return Calendar.DECEMBER;
        default:
            return -1;
    }
}
 
Example 19
Source File: FormatterLoggerManualExample.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
Calendar getBirthdayCalendar() {
    return new GregorianCalendar(1995, Calendar.MAY, 23);
}
 
Example 20
Source File: FunnyEasterEgg.java    From QuickShop-Reremake with GNU General Public License v3.0 4 votes vote down vote up
private boolean easterDay() {
    int year = new Date().getYear();
    int a = year % 19,
            b = year / 100,
            c = year % 100,
            d = b / 4,
            e = b % 4,
            g = (8 * b + 13) / 25,
            h = (19 * a + b - d - g + 15) % 30,
            j = c / 4,
            k = c % 4,
            m = (a + 11 * h) / 319,
            r = (2 * e + 2 * j - k - h + m + 32) % 7,
            n = (h - m + r + 90) / 25,
            p = (h - m + r + n + 19) % 32;

    int result;
    switch (n) {
        case 1:
            result = Calendar.JANUARY;
            break;
        case 2:
            result = Calendar.FEBRUARY;
            break;
        case 3:
            result = Calendar.MARCH;
            break;
        case 4:
            result = Calendar.APRIL;
            break;
        case 5:
            result = Calendar.MAY;
            break;
        case 6:
            result = Calendar.JUNE;
            break;
        case 7:
            result = Calendar.JULY;
            break;
        case 8:
            result = Calendar.AUGUST;
            break;
        case 9:
            result = Calendar.SEPTEMBER;
            break;
        case 10:
            result = Calendar.OCTOBER;
            break;
        case 11:
            result = Calendar.NOVEMBER;
            break;
        case 12:
            result = Calendar.DECEMBER;
            break;
        default:
            throw new IllegalStateException("Unexpected value: " + n);
    }
    Date eaterDay = new Date(year, result, p);
    Date currentDate = new Date(System.currentTimeMillis());
    if (currentDate.getYear() == eaterDay.getYear()) {
        if (currentDate.getMonth() == eaterDay.getMonth()) {
            return currentDate.getDay() == eaterDay.getDay();
        }
    }
    return false;
}