Java Code Examples for java.util.Calendar#APRIL

The following examples show how to use java.util.Calendar#APRIL . 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: 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 3
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 4
Source File: Utils.java    From cathode 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: 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 7
Source File: SimpleMonthView.java    From AppCompat-Extension-Library with Apache License 2.0 6 votes vote down vote up
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:
            throw new IllegalArgumentException("Invalid Month");
    }
}
 
Example 8
Source File: Bug4395196.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] arg)
        {
                int result = 0;
                Locale loc = new Locale("ko","KR");
                Date now = new Date(108, Calendar.APRIL, 9);

                DateFormat df =
                   DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.SHORT,loc);
                SimpleDateFormat sdf = new SimpleDateFormat("",loc);
                sdf.applyPattern("yyyy. M. d a h:mm");
                if( !sdf.format(now).equals(df.format(now))){
                 result++;
                 System.out.println("error at " + sdf.format(now));
                 }
                df =  DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.MEDIUM,loc);
                sdf.applyPattern("yyyy'\ub144' M'\uc6d4' d'\uc77c' '('EE')' a h:mm:ss");
                if( !sdf.format(now).equals(df.format(now))){
                 result++;
                 System.out.println("error at " + sdf.format(now));
                 }
                df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG,loc);
                sdf.applyPattern("yyyy. M. d a h'\uc2dc' mm'\ubd84' ss'\ucd08'");
                if( !sdf.format(now).equals(df.format(now))){
                 result++;
                 System.out.println("error at " + sdf.format(now));
                 }
                df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.FULL,loc);
                sdf.applyPattern("yy. M. d a h'\uc2dc' mm'\ubd84' ss'\ucd08' z");
                if( !sdf.format(now).equals(df.format(now))){
                 result++;
                 System.out.println("error at " + sdf.format(now));
                 }

           if(result > 0) throw new RuntimeException();
}
 
Example 9
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 10
Source File: TestLocalDate_Basics.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testToDate_springDST() {
    LocalDate base = new LocalDate(2007, 4, 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, 4, 2);
        assertEquals("Mon Apr 02 01:00:00 GMT+02:00 2007", test.toString());
    } finally {
        TimeZone.setDefault(currentZone);
    }
}
 
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() {
    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 12
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 13
Source File: SimpleTimeZoneTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * java.util.SimpleTimeZone#hashCode()
 */
public void test_hashCode() {
    // Test for method int java.util.SimpleTimeZone.hashCode()
    // For lack of a better test.
    st1 = new SimpleTimeZone(-5 * 3600000, "EST", Calendar.APRIL, 1,
            -Calendar.SUNDAY, 2 * 3600000, Calendar.OCTOBER, -1,
            Calendar.SUNDAY, 2 * 3600000);
    assertTrue(TimeZone.getTimeZone("EST").hashCode() != 0);
    assertTrue(st1.hashCode() != 0);
}
 
Example 14
Source File: BillingServiceRolePricesIT.java    From development with Apache License 2.0 5 votes vote down vote up
/**
 * Billing test for parameters and options price model with priced roles..
 * 
 * @throws Exception
 */
@Test
public void testBillingWithRolesForParametersAndOptions() throws Exception {

    final int testMonth = Calendar.APRIL;
    final int testDay = 1;
    final int testYear = 2010;
    final long billingTime = getTimeInMillisForBilling(testYear, testMonth,
            testDay);

    long subscriptionCreationTime = getTimeInMillisForBilling(testYear,
            testMonth - 2, testDay);
    long subscriptionActivationTime = getTimeInMillisForBilling(testYear,
            testMonth - 2, testDay);

    int userNumber = 1;
    BigDecimal expectedPrice = new BigDecimal(1867)
            .setScale(Numbers.BIGDECIMAL_SCALE);

    initDataParametersAndOptions(userNumber, subscriptionCreationTime,
            subscriptionActivationTime);

    runTX(new Callable<Void>() {
        @Override
        public Void call() throws Exception {
            billingService.startBillingRun(billingTime);
            return null;
        }
    });
    Document doc = getBillingDocument();

    String netCosts = XMLConverter.getNodeTextContentByXPath(doc,
            "/BillingDetails/OverallCosts/@grossAmount");
    checkEquals("Wrong net costs found", expectedPrice.toPlainString(),
            netCosts);
    xmlValidator.validateBillingResultXML();
}
 
Example 15
Source File: WorkCalendarHelper.java    From Open-Lowcode with Eclipse Public License 2.0 5 votes vote down vote up
private int getMonthInCalendar(ChoiceValue<WesternmonthsChoiceDefinition> month) {
	if (month.equals(WesternmonthsChoiceDefinition.get().M01))
		return Calendar.JANUARY;
	if (month.equals(WesternmonthsChoiceDefinition.get().M02))
		return Calendar.FEBRUARY;
	if (month.equals(WesternmonthsChoiceDefinition.get().M03))
		return Calendar.MARCH;
	if (month.equals(WesternmonthsChoiceDefinition.get().M04))
		return Calendar.APRIL;
	if (month.equals(WesternmonthsChoiceDefinition.get().M05))
		return Calendar.MAY;
	if (month.equals(WesternmonthsChoiceDefinition.get().M06))
		return Calendar.JUNE;
	if (month.equals(WesternmonthsChoiceDefinition.get().M07))
		return Calendar.JULY;
	if (month.equals(WesternmonthsChoiceDefinition.get().M08))
		return Calendar.AUGUST;
	if (month.equals(WesternmonthsChoiceDefinition.get().M09))
		return Calendar.SEPTEMBER;
	if (month.equals(WesternmonthsChoiceDefinition.get().M10))
		return Calendar.OCTOBER;
	if (month.equals(WesternmonthsChoiceDefinition.get().M11))
		return Calendar.NOVEMBER;
	if (month.equals(WesternmonthsChoiceDefinition.get().M12))
		return Calendar.DECEMBER;

	return -1;

}
 
Example 16
Source File: RangerTimeOfDayMatcherTest.java    From ranger with Apache License 2.0 4 votes vote down vote up
@Test
public void test_end2end_happyPath() {
	RangerPolicyItemCondition itemCondition = mock(RangerPolicyItemCondition.class);
	when(itemCondition.getValues()).thenReturn(Arrays.asList("2:45a.m. -7:00 AM", "  9:15AM- 5:30P.M. ", "11pm-2am"));

	RangerTimeOfDayMatcher matcher = new RangerTimeOfDayMatcher();
	matcher.setConditionDef(null);
	matcher.setPolicyItemCondition(itemCondition);
	matcher.init();
	
	Object[][] input = new Object[][] {
			{ 1, 0, true },
			{ 2, 0, true },
			{ 2, 1, false },
			{ 2, 44, false },
			{ 2, 45, true },
			{ 3, 0, true },
			{ 7, 0, true },
			{ 7, 01, false },
			{ 8, 0, false },
			{ 9, 15, true },
			{10, 0, true },
			{17, 0, true},
			{17, 30, true},
			{17, 31, false},
			{18, 0, false },
			{22, 59, false },
			{23, 0, true },
	};
	
	RangerAccessRequest request = mock(RangerAccessRequest.class);
	for (Object[] data : input) {
		int hour = (int)data[0];
		int minute = (int)data[1];
		Calendar c = new GregorianCalendar(2015, Calendar.APRIL, 1, hour, minute);
		Date aDate = c.getTime();
		when(request.getAccessTime()).thenReturn(aDate);
		boolean matchExpected = (boolean)data[2];
		if (matchExpected) {
			Assert.assertTrue("" + hour, matcher.isMatched(request));
		} else {
			Assert.assertFalse("" + hour, matcher.isMatched(request));
		}
	}
}
 
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: MultiCalendarAdapter.java    From holo-calendar with Apache License 2.0 4 votes vote down vote up
/**
 * Get the title for the current position
 *
 * @param position - The position in the ViewPager
 * @return Title: MONTH YEAR -> MARCH 2013
 */
@Override
public String getTitle(final int position) {
    final Context context = mContext;
    final Calendar date = Calendar.getInstance();
    date.setTimeInMillis((mCalendarView.getFirstValidDay().getTimeInMillis()));
    date.add(Calendar.MONTH, position);

    final String month;
    switch(date.get(Calendar.MONTH)) {
        case Calendar.JANUARY:
            month = context.getString(R.string.lib_month_january);
            break;
        case Calendar.FEBRUARY:
            month = context.getString(R.string.lib_month_february);
            break;
        case Calendar.MARCH:
            month = context.getString(R.string.lib_month_march);
            break;
        case Calendar.APRIL:
            month = context.getString(R.string.lib_month_april);
            break;
        case Calendar.MAY:
            month = context.getString(R.string.lib_month_may);
            break;
        case Calendar.JUNE:
            month = context.getString(R.string.lib_month_june);
            break;
        case Calendar.JULY:
            month = context.getString(R.string.lib_month_july);
            break;
        case Calendar.AUGUST:
            month = context.getString(R.string.lib_month_august);
            break;
        case Calendar.SEPTEMBER:
            month = context.getString(R.string.lib_month_september);
            break;
        case Calendar.OCTOBER:
            month = context.getString(R.string.lib_month_october);
            break;
        case Calendar.NOVEMBER:
            month = context.getString(R.string.lib_month_november);
            break;
        default:
        case Calendar.DECEMBER:
            month = context.getString(R.string.lib_month_december);
            break;
    }

    return month + " " + date.get(Calendar.YEAR);
}
 
Example 19
Source File: YesterdayFunctionTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
private Date createYesterdaysDate() {
  final GregorianCalendar gcal = new GregorianCalendar( 2011, Calendar.APRIL, 6, 0, 0, 0 );
  gcal.setTimeZone( getContext().getLocalizationContext().getTimeZone() );
  return gcal.getTime();
}
 
Example 20
Source File: monthConverter.java    From openbd-core with GNU General Public License v3.0 4 votes vote down vote up
/**
 * takes a month and returns the index of it - JAN => 1, FEB => 2...
 * assumes byte[] is in lower case
 * returns -1 if an invalid month.
 */
 
public static int convertMonthToInt(char[] month){
  
  switch (month[0]){

    case 'j':
      if (equivalent(month, "january")){
        return Calendar.JANUARY;
      }
      else if (equivalent(month, "june")){
        return Calendar.JUNE;
      }
      else if (equivalent(month, "july")){
        return Calendar.JULY;
      }
      else
        return -1;
    
    case 'M':
    case 'm':
      if (equivalent(month, "may")){
        return Calendar.MAY;
      }
      else if (equivalent(month, "march")){
        return Calendar.MARCH;
      }
      else
        return -1;
    
    case 'A':
    case 'a':
      if (equivalent(month, "april")){
        return Calendar.APRIL;
      }
      else if (equivalent(month, "august")){
        return Calendar.AUGUST;
      }
      else
        return -1;
    
    case 'F':
    case 'f':
      if (equivalent(month, "february")){
        return Calendar.FEBRUARY;
      }
      else
        return -1;
        
    case 'D':
    case 'd':
      if (equivalent(month, "december")){
        return Calendar.DECEMBER;
      }
      else
        return -1;
        
    case 'S':
    case 's':
      if (equivalent(month, "september")){
        return Calendar.SEPTEMBER;
      }
      else
        return -1;
        
    case 'O':
    case 'o':
      if (equivalent(month, "october")){
        return Calendar.OCTOBER;
      }
      else
        return -1;
    
    case 'N':
    case 'n':
      if (equivalent(month, "november")){
        return Calendar.NOVEMBER;
      }
      else 
        return -1;
    
    default:
      return -1;
  }//switch
  
}