Java Code Examples for java.util.Calendar#DECEMBER

The following examples show how to use java.util.Calendar#DECEMBER . 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: 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 2
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 3
Source File: Utils.java    From ClockPlus with GNU General Public License v3.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: AppCompatDatePickerDelegate.java    From AppCompat-Extension-Library 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: MonthPickerDialog.java    From MonthAndYearPicker with MIT License 6 votes vote down vote up
/**
 * Set the Minimum, maximum enabled months and starting , ending years.
 *
 * @param minMonth minimum enabled month in picker
 * @param maxMonth maximum enabled month in picker
 * @param minYear  starting year
 * @param maxYear  ending year
 * @return
 */
public Builder setMonthAndYearRange(@IntRange(from = Calendar.JANUARY, to = Calendar.DECEMBER)
                                            int minMonth,
                                    @IntRange(from = Calendar.JANUARY, to = Calendar.DECEMBER)
                                            int maxMonth,
                                    int minYear, int maxYear) {
    if (minMonth >= Calendar.JANUARY && minMonth <= Calendar.DECEMBER &&
            maxMonth >= Calendar.JANUARY && maxMonth <= Calendar.DECEMBER) {
        this._minMonth = minMonth;
        this._maxMonth = maxMonth;

    } else {
        throw new IllegalArgumentException("Month range should be between 0 " +
                "(Calender.JANUARY) to 11 (Calendar.DECEMBER)");
    }

    if (minYear <= maxYear) {
        this._minYear = minYear;
        this._maxYear = maxYear;
    } else {
        throw new IllegalArgumentException("Minimum year should be less then Maximum year");
    }
    return this;
}
 
Example 6
Source File: DateUtils.java    From CustomizableCalendar 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) ? 29 : 28;
        default:
            throw new IllegalArgumentException("Invalid Month");
    }
}
 
Example 7
Source File: CalendarUtils.java    From AirCalendar 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)) ? 28 : 29;
           default:
               throw new IllegalArgumentException("Invalid Month");
       }
}
 
Example 8
Source File: WeeklyCalendarComponent.java    From olat with Apache License 2.0 6 votes vote down vote up
/**
 * Set focus of calendar-component to certain date. Calculate correct week-of-year and year for certain date.
 * 
 * @param gotoDate
 */
public void setDate(final Date gotoDate) {
    final Calendar cal = CalendarUtils.createCalendarInstance(getTranslator().getLocale());
    cal.setTime(gotoDate);
    int weekYear = cal.get(Calendar.YEAR);
    final int week = cal.get(Calendar.WEEK_OF_YEAR);
    if (week == 1) {
        // Week 1 is a special case: the date could be the last days of december, but the week is still counted as week one of the next year. Use the next year in
        // this case to match the week number.
        if (cal.get(Calendar.MONTH) == Calendar.DECEMBER) {
            weekYear++;
        }
    } else if (week >= 52) {
        // Opposite check: date could be first days of january, but the week is still counted as the last week of the passed year. Use the last year in this case to
        // match the week number.
        if (cal.get(Calendar.MONTH) == Calendar.JANUARY) {
            weekYear--;
        }
    }
    setFocus(weekYear, week);
}
 
Example 9
Source File: CalendarUtil.java    From Music-Player with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the time elapsed so far this month and the last numMonths months in milliseconds.
 *
 * @param numMonths Additional number of months prior to the current month to calculate.
 * @return Time elapsed this month and the last numMonths months in milliseconds.
 */
public long getElapsedMonths(int numMonths) {
    // Today + rest of this month
    long elapsed = getElapsedMonth();

    // Previous numMonths months
    int month = calendar.get(Calendar.MONTH);
    int year = calendar.get(Calendar.YEAR);
    for (int i = 0; i < numMonths; i++) {
        month--;

        if (month < Calendar.JANUARY) {
            month = Calendar.DECEMBER;
            year--;
        }

        elapsed += getDaysInMonth(year, month) * MS_PER_DAY;
    }

    return elapsed;
}
 
Example 10
Source File: Week.java    From RipplePower with Apache License 2.0 6 votes vote down vote up
public Week(Date time, TimeZone zone, Locale locale) {
	Calendar calendar = Calendar.getInstance(zone, locale);
	calendar.setTime(time);

	int tempWeek = calendar.get(Calendar.WEEK_OF_YEAR);
	if (tempWeek == 1 && calendar.get(Calendar.MONTH) == Calendar.DECEMBER) {
		this.week = 1;
		this.year = (short) (calendar.get(Calendar.YEAR) + 1);
	} else {
		this.week = (byte) Math.min(tempWeek, LAST_WEEK_IN_YEAR);
		int yyyy = calendar.get(Calendar.YEAR);
		if (calendar.get(Calendar.MONTH) == Calendar.JANUARY && this.week >= 52) {
			yyyy--;
		}
		this.year = (short) yyyy;
	}
	peg(calendar);
}
 
Example 11
Source File: Week.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a time period for the week in which the specified date/time
 * falls, calculated relative to the specified time zone.
 *
 * @param time  the date/time (<code>null</code> not permitted).
 * @param zone  the time zone (<code>null</code> not permitted).
 * @param locale  the locale (<code>null</code> not permitted).
 *
 * @since 1.0.7
 */
public Week(Date time, TimeZone zone, Locale locale) {
    ParamChecks.nullNotPermitted(time, "time");
    ParamChecks.nullNotPermitted(zone, "zone");
    ParamChecks.nullNotPermitted(locale, "locale");
    Calendar calendar = Calendar.getInstance(zone, locale);
    calendar.setTime(time);

    // sometimes the last few days of the year are considered to fall in
    // the *first* week of the following year.  Refer to the Javadocs for
    // GregorianCalendar.
    int tempWeek = calendar.get(Calendar.WEEK_OF_YEAR);
    if (tempWeek == 1
            && calendar.get(Calendar.MONTH) == Calendar.DECEMBER) {
        this.week = 1;
        this.year = (short) (calendar.get(Calendar.YEAR) + 1);
    }
    else {
        this.week = (byte) Math.min(tempWeek, LAST_WEEK_IN_YEAR);
        int yyyy = calendar.get(Calendar.YEAR);
        // alternatively, sometimes the first few days of the year are
        // considered to fall in the *last* week of the previous year...
        if (calendar.get(Calendar.MONTH) == Calendar.JANUARY
                && this.week >= 52) {
            yyyy--;
        }
        this.year = (short) yyyy;
    }
    peg(calendar);
}
 
Example 12
Source File: Elixir_005_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Creates a time period for the week in which the specified date/time
 * falls, calculated relative to the specified time zone.
 *
 * @param time  the date/time (<code>null</code> not permitted).
 * @param zone  the time zone (<code>null</code> not permitted).
 * @param locale  the locale (<code>null</code> not permitted).
 *
 * @since 1.0.7
 */
public Week(Date time, TimeZone zone, Locale locale) {
    if (time == null) {
        throw new IllegalArgumentException("Null 'time' argument.");
    }
    if (zone == null) {
        throw new IllegalArgumentException("Null 'zone' argument.");
    }
    if (locale == null) {
        throw new IllegalArgumentException("Null 'locale' argument.");
    }
    Calendar calendar = Calendar.getInstance(zone, locale);
    calendar.setTime(time);

    // sometimes the last few days of the year are considered to fall in
    // the *first* week of the following year.  Refer to the Javadocs for
    // GregorianCalendar.
    int tempWeek = calendar.get(Calendar.WEEK_OF_YEAR);
    if (tempWeek == 1
            && calendar.get(Calendar.MONTH) == Calendar.DECEMBER) {
        this.week = 1;
        this.year = (short) (calendar.get(Calendar.YEAR) + 1);
    }
    else {
        this.week = (byte) Math.min(tempWeek, LAST_WEEK_IN_YEAR);
        int yyyy = calendar.get(Calendar.YEAR);
        // alternatively, sometimes the first few days of the year are
        // considered to fall in the *last* week of the previous year...
        if (calendar.get(Calendar.MONTH) == Calendar.JANUARY
                && this.week >= 52) {
            yyyy--;
        }
        this.year = (short) yyyy;
    }
    peg(calendar);
}
 
Example 13
Source File: FunnyEasterEgg.java    From QuickShop-Reremake with GNU General Public License v3.0 5 votes vote down vote up
private boolean chineseSpringDay() {
    Date chineseCalender = new LunarCalendar(new Date()).getDate();
    if (chineseCalender.getMonth() == Calendar.DECEMBER && chineseCalender.getDay() == 31) {
        return true;
    }
    return chineseCalender.getMonth() == Calendar.JANUARY && chineseCalender.getDay() == 1;
}
 
Example 14
Source File: Week.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a time period for the week in which the specified date/time
 * falls, calculated relative to the specified time zone.
 *
 * @param time  the date/time (<code>null</code> not permitted).
 * @param zone  the time zone (<code>null</code> not permitted).
 * @param locale  the locale (<code>null</code> not permitted).
 *
 * @since 1.0.7
 */
public Week(Date time, TimeZone zone, Locale locale) {
    ParamChecks.nullNotPermitted(time, "time");
    ParamChecks.nullNotPermitted(zone, "zone");
    ParamChecks.nullNotPermitted(locale, "locale");
    Calendar calendar = Calendar.getInstance(zone, locale);
    calendar.setTime(time);

    // sometimes the last few days of the year are considered to fall in
    // the *first* week of the following year.  Refer to the Javadocs for
    // GregorianCalendar.
    int tempWeek = calendar.get(Calendar.WEEK_OF_YEAR);
    if (tempWeek == 1
            && calendar.get(Calendar.MONTH) == Calendar.DECEMBER) {
        this.week = 1;
        this.year = (short) (calendar.get(Calendar.YEAR) + 1);
    }
    else {
        this.week = (byte) Math.min(tempWeek, LAST_WEEK_IN_YEAR);
        int yyyy = calendar.get(Calendar.YEAR);
        // alternatively, sometimes the first few days of the year are
        // considered to fall in the *last* week of the previous year...
        if (calendar.get(Calendar.MONTH) == Calendar.JANUARY
                && this.week >= 52) {
            yyyy--;
        }
        this.year = (short) yyyy;
    }
    peg(calendar);
}
 
Example 15
Source File: ChristmasHat.java    From MineLittlePony with MIT License 5 votes vote down vote up
private static boolean isChristmasDay() {
    if (!dayChecked) {
        dayChecked = true;
        Calendar cal = Calendar.getInstance();
        dayResult = cal.get(Calendar.MONTH) == Calendar.DECEMBER
                 && cal.get(Calendar.DAY_OF_MONTH) == 25;
    }


    return dayResult;
}
 
Example 16
Source File: AllFragment.java    From Birdays with Apache License 2.0 4 votes vote down vote up
private Separator getSeparator(Person person) {
    Separator separator = null;
    switch (person.getMonth()) {
        case Calendar.JANUARY:
            if (!adapter.containsSeparatorJanuary) {
                adapter.containsSeparatorJanuary = true;
                separator = new Separator(Separator.TYPE_JANUARY);
            }
            break;
        case Calendar.FEBRUARY:
            if (!adapter.containsSeparatorFebruary) {
                adapter.containsSeparatorFebruary = true;
                separator = new Separator(Separator.TYPE_FEBRUARY);
            }
            break;
        case Calendar.MARCH:
            if (!adapter.containsSeparatorMarch) {
                adapter.containsSeparatorMarch = true;
                separator = new Separator(Separator.TYPE_MARCH);
            }
            break;
        case Calendar.APRIL:
            if (!adapter.containsSeparatorApril) {
                adapter.containsSeparatorApril = true;
                separator = new Separator(Separator.TYPE_APRIL);
            }
            break;
        case Calendar.MAY:
            if (!adapter.containsSeparatorMay) {
                adapter.containsSeparatorMay = true;
                separator = new Separator(Separator.TYPE_MAY);
            }
            break;
        case Calendar.JUNE:
            if (!adapter.containsSeparatorJune) {
                adapter.containsSeparatorJune = true;
                separator = new Separator(Separator.TYPE_JUNE);
            }
            break;
        case Calendar.JULY:
            if (!adapter.containsSeparatorJuly) {
                adapter.containsSeparatorJuly = true;
                separator = new Separator(Separator.TYPE_JULY);
            }
            break;
        case Calendar.AUGUST:
            if (!adapter.containsSeparatorAugust) {
                adapter.containsSeparatorAugust = true;
                separator = new Separator(Separator.TYPE_AUGUST);
            }
            break;
        case Calendar.SEPTEMBER:
            if (!adapter.containsSeparatorSeptember) {
                adapter.containsSeparatorSeptember = true;
                separator = new Separator(Separator.TYPE_SEPTEMBER);
            }
            break;
        case Calendar.OCTOBER:
            if (!adapter.containsSeparatorOctober) {
                adapter.containsSeparatorOctober = true;
                separator = new Separator(Separator.TYPE_OCTOBER);
            }
            break;
        case Calendar.NOVEMBER:
            if (!adapter.containsSeparatorNovember) {
                adapter.containsSeparatorNovember = true;
                separator = new Separator(Separator.TYPE_NOVEMBER);
            }
            break;
        case Calendar.DECEMBER:
            if (!adapter.containsSeparatorDecember) {
                adapter.containsSeparatorDecember = true;
                separator = new Separator(Separator.TYPE_DECEMBER);
            }
            break;
    }
    return separator;
}
 
Example 17
Source File: Moon.java    From TabletClock with MIT License 4 votes vote down vote up
public static MoonPhases get(Date when) {
	Calendar cal = Calendar.getInstance();
	cal.setTime(when);
	int y = cal.get(Calendar.YEAR);
	int m = cal.get(Calendar.MONTH) + (12 - Calendar.DECEMBER); //+1 because january is 0
	int d = cal.get(Calendar.DAY_OF_MONTH);

	int yy = y - (12 - m) / 10;
	int mm = m + 9;
	if (mm >= 12) {
		mm = mm - 12;
	}
	int k1 = (int) (365.25 * (yy + 4712));
	int k2 = (int) (30.6001 * mm + 0.5);
	int k3 = (int) (((yy / 100) + 49) * 0.75) - 38;
	// 'j' for dates in Julian calendar:
	int j = k1 + k2 + d + 59;
	if (j > 2299160) {
		// For Gregorian calendar:
		j = j - k3; // 'j' is the Julian date at 12h UT (Universal Time)
	}
	double t = (j - 2451550.1) / 29.530588853;
	double phase = t - Math.floor(t);
	double age = phase * 29.53;

	if (age < 1.84566) {
		return MoonPhases.MOON_NEW;
	} else if (age < 5.53699) {
		return MoonPhases.MOON_EVENING_CRESCENT;
	} else if (age < 9.22831) {
		return MoonPhases.MOON_FIRST_QUARTER;
	} else if (age < 12.91963) {
		return MoonPhases.MOON_WAXING_GIBBOUS;
	} else if (age < 16.61096) {
		return MoonPhases.MOON_FULL;
	} else if (age < 20.30228) {
		return MoonPhases.MOON_WANING_GIBBOUS;
	} else if (age < 23.99361) {
		return MoonPhases.MOON_LAST_QUARTER;
	} else if (age < 27.68493) {
		return MoonPhases.MOON_MORNING_CRESCENT;
	} else {
		return MoonPhases.MOON_NEW;
	}
}
 
Example 18
Source File: SnowRenderer.java    From The-5zig-Mod with MIT License 4 votes vote down vote up
public SnowRenderer() {
	Calendar calendar = Calendar.getInstance();

	render = (calendar.get(Calendar.MONTH) == Calendar.DECEMBER && calendar.get(Calendar.DAY_OF_MONTH) >= 15) || (calendar.get(Calendar.MONTH) == Calendar.JANUARY && calendar.get(
			Calendar.DAY_OF_MONTH) <= 15);
}
 
Example 19
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
  
}
 
Example 20
Source File: SnowRenderer.java    From The-5zig-Mod with GNU General Public License v3.0 4 votes vote down vote up
public SnowRenderer() {
	Calendar calendar = Calendar.getInstance();

	render = (calendar.get(Calendar.MONTH) == Calendar.DECEMBER && calendar.get(Calendar.DAY_OF_MONTH) >= 15) || (calendar.get(Calendar.MONTH) == Calendar.JANUARY && calendar.get(
			Calendar.DAY_OF_MONTH) <= 15);
}