Java Code Examples for java.util.Calendar#FEBRUARY

The following examples show how to use java.util.Calendar#FEBRUARY . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: DateTimepicker   File: Utils.java    License: 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 Project: cathode   File: Utils.java    License: 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
private void checkBirthday(int year, int month, int day) {
    var charactersData = getDAO(PlayerDAO.class).findBirthdayCharacters(year, month, day);
    charactersData.forEach(characterData -> {
        var name = PlayerNameTable.getInstance().getNameById(characterData.getCharId());
        if(isNull(name)) {
            return;
        }

        var age = year - characterData.getCreateDate().getYear();
        var text = Config.ALT_BIRTHDAY_MAIL_TEXT.replace("$c1", name).replace("$s1", String.valueOf(age));

        final var mail = MailData.of(characterData.getCharId(), Config.ALT_BIRTHDAY_MAIL_SUBJECT, text, MailType.BIRTHDAY);
        final Attachment attachments = new Attachment(mail.getSender(), mail.getId());
        attachments.addItem("Birthday", Config.ALT_BIRTHDAY_GIFT, 1, null, null);
        mail.attach(attachments);
        MailEngine.getInstance().sendMail(mail);
        _count++;
    });

    // If character birthday is 29-Feb and year isn't leap, send gift on 28-feb
    final GregorianCalendar calendar = new GregorianCalendar();
    if ((month == Calendar.FEBRUARY) && (day == 28) && !calendar.isLeapYear(_today.get(Calendar.YEAR))) {
        checkBirthday(year, month, 29);
    }
}
 
Example 4
Source Project: BottomSheetPickers   File: Utils.java    License: 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 Project: narrate-android   File: Utils.java    License: 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 Project: ClockPlus   File: Utils.java    License: 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 7
Source Project: netty-4.1.22   File: DateFormatter.java    License: Apache License 2.0 5 votes vote down vote up
private boolean tryParseMonth(CharSequence txt, int tokenStart, int tokenEnd) {
    int len = tokenEnd - tokenStart;

    if (len != 3) {
        return false;
    }

    if (matchMonth("Jan", txt, tokenStart)) {
        month = Calendar.JANUARY;
    } else if (matchMonth("Feb", txt, tokenStart)) {
        month = Calendar.FEBRUARY;
    } else if (matchMonth("Mar", txt, tokenStart)) {
        month = Calendar.MARCH;
    } else if (matchMonth("Apr", txt, tokenStart)) {
        month = Calendar.APRIL;
    } else if (matchMonth("May", txt, tokenStart)) {
        month = Calendar.MAY;
    } else if (matchMonth("Jun", txt, tokenStart)) {
        month = Calendar.JUNE;
    } else if (matchMonth("Jul", txt, tokenStart)) {
        month = Calendar.JULY;
    } else if (matchMonth("Aug", txt, tokenStart)) {
        month = Calendar.AUGUST;
    } else if (matchMonth("Sep", txt, tokenStart)) {
        month = Calendar.SEPTEMBER;
    } else if (matchMonth("Oct", txt, tokenStart)) {
        month = Calendar.OCTOBER;
    } else if (matchMonth("Nov", txt, tokenStart)) {
        month = Calendar.NOVEMBER;
    } else if (matchMonth("Dec", txt, tokenStart)) {
        month = Calendar.DECEMBER;
    } else {
        return false;
    }

    return true;
}
 
Example 8
Source Project: bazel   File: ZipUtilTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test public void testTimeConversion_DosToUnix() {
  int dos = (20 << 25) | (2 << 21) | (14 << 16) | (3 << 11) | (7 << 5) | (15 >> 1);

  Calendar time = new GregorianCalendar(2000, Calendar.FEBRUARY, 14, 3, 7, 14);
  long expectedUnixTime = time.getTimeInMillis();
  assertThat(ZipUtil.dosToUnixTime(dos)).isEqualTo(expectedUnixTime);
}
 
Example 9
Source Project: Alite   File: HttpDateTime.java    License: GNU General Public License v3.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 Project: mumu   File: DateUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 
 * 1 第一季度 2 第二季度 3 第三季度 4 第四季度
 * 
 * @param date
 * @return
 */
public static int getSeason(Date date) {

	int season = 0;

	Calendar c = Calendar.getInstance();
	c.setTime(date);
	int month = c.get(Calendar.MONTH);
	switch (month) {
	case Calendar.JANUARY:
	case Calendar.FEBRUARY:
	case Calendar.MARCH:
		season = 1;
		break;
	case Calendar.APRIL:
	case Calendar.MAY:
	case Calendar.JUNE:
		season = 2;
		break;
	case Calendar.JULY:
	case Calendar.AUGUST:
	case Calendar.SEPTEMBER:
		season = 3;
		break;
	case Calendar.OCTOBER:
	case Calendar.NOVEMBER:
	case Calendar.DECEMBER:
		season = 4;
		break;
	default:
		break;
	}
	return season;
}
 
Example 11
@Test
public void shouldConvertWithCorrectFormat() {

    Calendar date = new GregorianCalendar(2004, Calendar.FEBRUARY, 29);
    String result = converter.convert(date);

    Assert.assertEquals("2004-02-29", result);
}
 
Example 12
@Test
public void testMigrationBeginOfFebruary() throws Exception {
    final int testMonth = Calendar.FEBRUARY;
    final int testDay = 1;
    final BigDecimal price = new BigDecimal("11942.0322580645");

    testMigrationBase(testYear, testMonth, testDay, price);
    xmlValidator.validateBillingResultXML();
}
 
Example 13
Source Project: TofuCraftReload   File: EntityFukumame.java    License: MIT License 4 votes vote down vote up
private boolean chkdate() {
    Calendar cal = Calendar.getInstance();
    return cal.get(Calendar.MONTH) == Calendar.FEBRUARY && cal.get(Calendar.DATE) == 3;
}
 
Example 14
Source Project: bazel   File: ZipUtilTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test public void testTimeConversion_UnixToUnix() {
  Calendar from = new GregorianCalendar(2000, Calendar.FEBRUARY, 14, 3, 7, 15);
  Calendar to = new GregorianCalendar(2000, Calendar.FEBRUARY, 14, 3, 7, 14);
  assertThat(ZipUtil.dosToUnixTime(ZipUtil.unixToDosTime(from.getTimeInMillis())))
      .isEqualTo(to.getTimeInMillis());
}
 
Example 15
/**
 * @see org.projectforge.web.calendar.MyFullCalendarEventsProvider#buildEvents(org.joda.time.DateTime, org.joda.time.DateTime)
 */
@Override
protected void buildEvents(final DateTime start, final DateTime end)
{
  if (filter.isShowBirthdays() == false) {
    // Don't show birthdays.
    return;
  }
  DateTime from = start;
  if (start.getMonthOfYear() == Calendar.MARCH && start.getDayOfMonth() == 1) {
    from = start.minusDays(1);
  }
  final Set<BirthdayAddress> set = addressDao.getBirthdays(from.toDate(), end.toDate(), 1000, true);
  for (final BirthdayAddress birthdayAddress : set) {
    final AddressDO address = birthdayAddress.getAddress();
    final int month = birthdayAddress.getMonth() + 1;
    final int dayOfMonth = birthdayAddress.getDayOfMonth();
    DateTime date = getDate(from, end, month, dayOfMonth);
    // February, 29th fix:
    if (date == null && month == Calendar.FEBRUARY + 1 && dayOfMonth == 29) {
      date = getDate(from, end, month + 1, 1);
    }
    if (date == null && WebConfiguration.isDevelopmentMode() == true) {
      log.info("Date "
          + birthdayAddress.getDayOfMonth()
          + "/"
          + (birthdayAddress.getMonth() + 1)
          + " not found between "
          + from
          + " and "
          + end);
      continue;
    } else {
      if (dataProtection == false && date != null) {
        birthdayAddress.setAge(date.toDate());
      }
    }
    final Event event = new Event().setAllDay(true);
    event.setClassName(EVENT_CLASS_NAME);
    final String id = "" + address.getId();
    event.setId(id);
    event.setStart(date);
    final StringBuffer buf = new StringBuffer();
    if (dataProtection == false) {
      // Birthday is not visible for all users (age == 0).
      buf.append(
          DateTimeFormatter.instance().getFormattedDate(address.getBirthday(), DateFormats.getFormatString(DateFormatType.DATE_SHORT)))
          .append(" ");
    }
    buf.append(address.getFirstName()).append(" ").append(address.getName());
    if (dataProtection == false && birthdayAddress.getAge() > 0) {
      // Birthday is not visible for all users (age == 0).
      buf.append(" (").append(birthdayAddress.getAge()).append(" ").append(PFUserContext.getLocalizedString("address.age.short")).append(")");
    }
    event.setTitle(buf.toString());
    if (birthdayAddress.isFavorite() == true) {
      // Colors of events of birthdays of favorites (for default color see CalendarPanel):
      event.setBackgroundColor("#06790E");
      event.setBorderColor("#06790E");
      event.setTextColor("#FFFFFF");
    }
    events.put(id, event);
  }
}
 
Example 16
@Test
public void testRead() throws Exception {
    Entity entity = fromJson(Entity.class,
        "{"
            + "\"complexType\": \"SoftLayer_TestEntity\","
            + "\"bar\": \"some string\","
            + "\"foo\": \"another string\","
            + "\"baz\": null,"
            + "\"date\": \"1984-02-25T20:15:25-06:00\","
            + "\"notApiProperty\": \"bad value\","
            + "\"child\": {"
            + "    \"complexType\": \"SoftLayer_TestEntity\","
            + "    \"bar\": \"child string\""
            + "},"
            + "\"moreChildren\": ["
            + "    { \"complexType\": \"SoftLayer_TestEntity\", \"bar\": \"child 1\" },"
            + "    { \"complexType\": \"SoftLayer_TestEntity\", \"bar\": \"child 2\" }"
            + "],"
            + "\"testThing\": {\"complexType\": \"SoftLayer_TestThing\", \"id\": 123}"
            + "}");
    assertEquals(TestEntity.class, entity.getClass());
    TestEntity obj = (TestEntity) entity;
    assertEquals("some string", obj.getFoo());
    assertEquals(2, obj.getUnknownProperties().size());
    assertEquals("another string", obj.getUnknownProperties().get("foo"));
    assertNull(obj.getBaz());
    assertTrue(obj.isBazSpecified());
    GregorianCalendar expectedDate = new GregorianCalendar(1984, Calendar.FEBRUARY, 25, 20, 15, 25);
    expectedDate.setTimeZone(TimeZone.getTimeZone("GMT-06:00"));
    assertEquals(expectedDate.getTimeInMillis(), obj.getDate().getTimeInMillis());
    assertNull(obj.getNotApiProperty());
    assertEquals("bad value", obj.getUnknownProperties().get("notApiProperty"));
    assertEquals("child string", obj.getChild().getFoo());
    assertNull(obj.getChild().getBaz());
    assertEquals(0, obj.getChild().getUnknownProperties().size());
    assertFalse(obj.getChild().isBazSpecified());
    assertEquals(2, obj.getMoreChildren().size());
    assertEquals("child 1", obj.getMoreChildren().get(0).getFoo());
    assertEquals("child 2", obj.getMoreChildren().get(1).getFoo());
    assertEquals(TestThing.class, obj.getTestThing().getClass());
    assertEquals(123, obj.getTestThing().getId().intValue());
}
 
Example 17
Source Project: Birdays   File: Utils.java    License: 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 18
Source Project: tddl5   File: Monthname.java    License: 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 19
Source Project: Birdays   File: AllFragment.java    License: 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 20
@Test(expected = IllegalArgumentException.class)
public void shouldRejectInvalidGregorianValue() {
    GregorianCalendar gCal = new GregorianCalendar(1930, Calendar.FEBRUARY, 12);
    Calendar uCal = new UmmalquraCalendar();
    uCal.setTime(gCal.getTime());
}