Java Code Examples for java.util.Calendar#OCTOBER

The following examples show how to use java.util.Calendar#OCTOBER . 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 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 2
Source File: BillingServiceBeanIT.java    From development with Apache License 2.0 6 votes vote down vote up
@Test
public void testSubLastMonthHourBased() throws Exception {
    final int testMonth = Calendar.OCTOBER;
    final int testDay = 1;
    final long billingTime = getBillingTime(testYear, testMonth, testDay);
    final Date date = getDate(testYear, testMonth - 2, testDay, 0, 0);

    creSub(P_5_ID, SUBSCRIPTION_ID, date, null);

    startBillingRun(billingTime);
    BigDecimal value = P_5_PRICE_PER_PERIOD.multiply(BD30)
            .multiply(new BigDecimal(24));
    verify(new Date[][] { { getStartDate(testYear, testMonth),
            getEndDate(testYear, testMonth) } }, value, testMonth);
    xmlValidator.validateBillingResultXML();
}
 
Example 3
Source File: CalendarUtils.java    From UltimateAndroid 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 4
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 5
Source File: ValidationByExceptionHandlerTest.java    From blog with MIT License 6 votes vote down vote up
@Test
public void test_WHEN_valid_GIVEN_valid_model_THEN_ok_no_errors() {

	// GIVEN

	PersonModel person = new PersonModel( //
			"Kim", //
			"Kardashian", //
			new GregorianCalendar(1980, Calendar.OCTOBER, 21));
	ValidationByExceptionHandler validator = new ValidationByExceptionHandler();

	// WHEN

	validator.validate(person);

	// THEN
	// nothing to do
}
 
Example 6
Source File: ValidationByResponseHandlerTest.java    From blog with MIT License 6 votes vote down vote up
@Test
public void test_WHEN_valid_GIVEN_valid_model_THEN_ok_no_errors() {

	// GIVEN

	PersonModel person = new PersonModel( //
			"Kim", //
			"Kardashian", //
			new GregorianCalendar(1980, Calendar.OCTOBER, 21));
	ValidationByResponseHandler validator = new ValidationByResponseHandler();

	// WHEN

	Response response = validator.validate(person);

	// THEN
	assertThat(response.getStatus()).isEqualTo(200);
}
 
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: TestLocalDateTime_Basics.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testToDate_springDST() {
    LocalDateTime base = new LocalDateTime(2007, 4, 2, 0, 20, 0, 0);
    
    SimpleTimeZone testZone = new SimpleTimeZone(3600000, "NoMidnight",
            Calendar.APRIL, 2, 0, 0, Calendar.OCTOBER, 2, 0, 3600000);
    TimeZone currentZone = TimeZone.getDefault();
    try {
        TimeZone.setDefault(testZone);
        Date test = base.toDate();
        check(base, 2007, 4, 2, 0, 20, 0, 0);
        assertEquals("Mon Apr 02 01:00:00 GMT+02:00 2007", test.toString());
    } finally {
        TimeZone.setDefault(currentZone);
    }
}
 
Example 9
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 10
Source File: Kits.java    From XDroidMvp with MIT License 5 votes vote down vote up
/**
 * 获取月份的天数
 *
 * @param mills
 * @return
 */
public static int getDaysInMonth(long mills) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(mills);

    int year = calendar.get(Calendar.YEAR);
    int month = calendar.get(Calendar.MONTH);

    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 11
Source File: TestLocalDateTime_Basics.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testToDate_springDST_Zone() {
    LocalDateTime base = new LocalDateTime(2007, 4, 2, 0, 20, 0, 0);
    
    SimpleTimeZone testZone = new SimpleTimeZone(3600000, "NoMidnight",
            Calendar.APRIL, 2, 0, 0, Calendar.OCTOBER, 2, 0, 3600000);
    TimeZone currentZone = TimeZone.getDefault();
    try {
        TimeZone.setDefault(testZone);
        Date test = base.toDate(TimeZone.getDefault());
        check(base, 2007, 4, 2, 0, 20, 0, 0);
        assertEquals("Mon Apr 02 01:00:00 GMT+02:00 2007", test.toString());
    } finally {
        TimeZone.setDefault(currentZone);
    }
}
 
Example 12
Source File: SimpleTimeZoneTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void testDstParis2014_30thMarch_26thOctober_UtcTime() {
    TimeZone timeZone = new SimpleTimeZone(PARIS_RAW_OFFSET, "Europe/Paris",
            Calendar.MARCH, 30, 0, 3600000, SimpleTimeZone.UTC_TIME,
            Calendar.OCTOBER, 26, 0, 3600000, SimpleTimeZone.UTC_TIME, 3600000);

    checkDstParis2014(timeZone);
}
 
Example 13
Source File: TestLocalDate_Basics.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testToDate_autumnDST() {
    LocalDate base = new LocalDate(2007, 10, 2);
    
    SimpleTimeZone testZone = new SimpleTimeZone(3600000, "NoMidnight",
            Calendar.APRIL, 2, 0, 0, Calendar.OCTOBER, 2, 0, 3600000);
    TimeZone currentZone = TimeZone.getDefault();
    try {
        TimeZone.setDefault(testZone);
        Date test = base.toDate();
        check(base, 2007, 10, 2);
        assertEquals("Tue Oct 02 00:00:00 GMT+02:00 2007", test.toString());
    } finally {
        TimeZone.setDefault(currentZone);
    }
}
 
Example 14
Source File: DateTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * java.util.Date#Date()
 */
public void test_Constructor() {
    // Test for method java.util.Date()
    GregorianCalendar gc = new GregorianCalendar(1998, Calendar.OCTOBER,
            13, 19, 9);
    long oldTime = gc.getTime().getTime();
    long now = new Date().getTime();
    assertTrue("Created incorrect date: " + oldTime + " now: " + now,
            oldTime < now);
}
 
Example 15
Source File: Utils.java    From Birdays with Apache License 2.0 4 votes vote down vote up
/**
 * Returns zodiac name of certain date
 */
public static int getZodiacId(long date) {
    int resId = 0;
    dayOfBirthday.setTimeInMillis(date);

    switch (getMonth(dayOfBirthday)) {
        case Calendar.JANUARY:
            resId = getDay(dayOfBirthday) < 21 ? R.string.capricorn : R.string.aquarius;
            break;
        case Calendar.FEBRUARY:
            resId = getDay(dayOfBirthday) < 20 ? R.string.aquarius : R.string.pisces;
            break;
        case Calendar.MARCH:
            resId = getDay(dayOfBirthday) < 21 ? R.string.pisces : R.string.aries;
            break;
        case Calendar.APRIL:
            resId = getDay(dayOfBirthday) < 21 ? R.string.aries : R.string.taurus;
            break;
        case Calendar.MAY:
            resId = getDay(dayOfBirthday) < 22 ? R.string.taurus : R.string.gemini;
            break;
        case Calendar.JUNE:
            resId = getDay(dayOfBirthday) < 22 ? R.string.gemini : R.string.cancer;
            break;
        case Calendar.JULY:
            resId = getDay(dayOfBirthday) < 23 ? R.string.cancer : R.string.leo;
            break;
        case Calendar.AUGUST:
            resId = getDay(dayOfBirthday) < 23 ? R.string.leo : R.string.virgo;
            break;
        case Calendar.SEPTEMBER:
            resId = getDay(dayOfBirthday) < 24 ? R.string.virgo : R.string.libra;
            break;
        case Calendar.OCTOBER:
            resId = getDay(dayOfBirthday) < 24 ? R.string.libra : R.string.scorpio;
            break;
        case Calendar.NOVEMBER:
            resId = getDay(dayOfBirthday) < 23 ? R.string.scorpio : R.string.sagittarius;
            break;
        case Calendar.DECEMBER:
            resId = getDay(dayOfBirthday) < 22 ? R.string.sagittarius : R.string.capricorn;
            break;
    }
    return resId;
}
 
Example 16
Source File: TimeSpanTest.java    From ews-java-api with MIT License 4 votes vote down vote up
/**
 * testTimeSpanToXSDuration
 */
@Test
public void testTimeSpanToXSDuration() {
  Calendar calendar = new GregorianCalendar(2008, Calendar.OCTOBER, 10);
  timeSpanToXSDuration(calendar);
}
 
Example 17
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 18
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;
}
 
Example 19
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 20
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;
    }
}