Example usage for java.util Calendar JANUARY

List of usage examples for java.util Calendar JANUARY

Introduction

In this page you can find the example usage for java.util Calendar JANUARY.

Prototype

int JANUARY

To view the source code for java.util Calendar JANUARY.

Click Source Link

Document

Value of the #MONTH field indicating the first month of the year in the Gregorian and Julian calendars.

Usage

From source file:org.jfree.data.time.Week.java

/**
 * 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//from  ww  w . ja va 2 s. c o  m
 */
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);
}

From source file:com.clustercontrol.systemlog.bean.SyslogMessage.java

/**
 * ??/*from ww w .j av a  2s  . c om*/
 * ?(String)Calendar?(int)???
 * 
 * @param month 
 * @return Calendar?
 */
private static int editCalendarMonth(String month) {

    switch (month.toUpperCase()) {
    case "JAN":
        return Calendar.JANUARY;
    case "FEB":
        return Calendar.FEBRUARY;
    case "MAR":
        return Calendar.MARCH;
    case "APR":
        return Calendar.APRIL;
    case "MAY":
        return Calendar.MAY;
    case "JUN":
        return Calendar.JUNE;
    case "JUL":
        return Calendar.JULY;
    case "AUG":
        return Calendar.AUGUST;
    case "SEP":
        return Calendar.SEPTEMBER;
    case "OCT":
        return Calendar.OCTOBER;
    case "NOV":
        return Calendar.NOVEMBER;
    case "DEC":
        return Calendar.DECEMBER;
    }
    return Calendar.UNDECIMBER;
}

From source file:com.liferay.portal.service.impl.UserLocalServiceImpl.java

public User addDefaultAdminUser(long companyId, String screenName, String emailAddress, Locale locale,
        String firstName, String middleName, String lastName) throws PortalException, SystemException {

    long creatorUserId = 0;
    boolean autoPassword = false;
    String password1 = PropsValues.DEFAULT_ADMIN_PASSWORD;
    String password2 = password1;
    boolean autoScreenName = false;

    screenName = getScreenName(screenName);

    for (int i = 1;; i++) {
        User screenNameUser = userPersistence.fetchByC_SN(companyId, screenName);

        if (screenNameUser == null) {
            break;
        }//ww  w.j  av a  2  s.  c om

        screenName = screenName + i;
    }

    long facebookId = 0;
    String openId = StringPool.BLANK;
    int prefixId = 0;
    int suffixId = 0;
    boolean male = true;
    int birthdayMonth = Calendar.JANUARY;
    int birthdayDay = 1;
    int birthdayYear = 1970;
    String jobTitle = StringPool.BLANK;

    Group guestGroup = groupLocalService.getGroup(companyId, GroupConstants.GUEST);

    long[] groupIds = { guestGroup.getGroupId() };

    long[] organizationIds = null;

    Role adminRole = roleLocalService.getRole(companyId, RoleConstants.ADMINISTRATOR);

    Role powerUserRole = roleLocalService.getRole(companyId, RoleConstants.POWER_USER);

    long[] roleIds = { adminRole.getRoleId(), powerUserRole.getRoleId() };

    long[] userGroupIds = null;
    boolean sendEmail = false;
    ServiceContext serviceContext = new ServiceContext();

    User defaultAdminUser = addUser(creatorUserId, companyId, autoPassword, password1, password2,
            autoScreenName, screenName, emailAddress, facebookId, openId, locale, firstName, middleName,
            lastName, prefixId, suffixId, male, birthdayMonth, birthdayDay, birthdayYear, jobTitle, groupIds,
            organizationIds, roleIds, userGroupIds, sendEmail, serviceContext);

    updateEmailAddressVerified(defaultAdminUser.getUserId(), true);

    updateLastLogin(defaultAdminUser.getUserId(), defaultAdminUser.getLoginIP());

    updatePasswordReset(defaultAdminUser.getUserId(), false);

    return defaultAdminUser;
}

From source file:org.kuali.kfs.module.endow.businessobject.lookup.CalculateProcessDateUsingFrequencyCodeService.java

/**
 * This method will check the current month and set the calendar to that month
 * @param month month to set the calendar
 * @return calendar calendar is set to the month selected
 *///from   w w  w .  ja va  2  s  . c  om
protected Calendar setCaledarWithMonth(String month, Date currentDate) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(currentDate);
    int calendarMonth = 1;

    if (EndowConstants.FrequencyMonths.JANUARY.equalsIgnoreCase(month)) {
        calendarMonth = Calendar.JANUARY;
    } else if (EndowConstants.FrequencyMonths.FEBRUARY.equalsIgnoreCase(month)) {
        calendarMonth = Calendar.FEBRUARY;
    } else if (EndowConstants.FrequencyMonths.MARCH.equalsIgnoreCase(month)) {
        calendarMonth = Calendar.MARCH;
    } else if (EndowConstants.FrequencyMonths.APRIL.equalsIgnoreCase(month)) {
        calendarMonth = Calendar.APRIL;
    } else if (EndowConstants.FrequencyMonths.MAY.equalsIgnoreCase(month)) {
        calendarMonth = Calendar.MAY;
    } else if (EndowConstants.FrequencyMonths.JUNE.equalsIgnoreCase(month)) {
        calendarMonth = Calendar.JUNE;
    } else if (EndowConstants.FrequencyMonths.JULY.equalsIgnoreCase(month)) {
        calendarMonth = Calendar.JULY;
    } else if (EndowConstants.FrequencyMonths.AUGUST.equalsIgnoreCase(month)) {
        calendarMonth = Calendar.AUGUST;
    } else if (EndowConstants.FrequencyMonths.SEPTEMBER.equalsIgnoreCase(month)) {
        calendarMonth = Calendar.SEPTEMBER;
    } else if (EndowConstants.FrequencyMonths.OCTOBER.equalsIgnoreCase(month)) {
        calendarMonth = Calendar.OCTOBER;
    } else if (EndowConstants.FrequencyMonths.NOVEMBER.equalsIgnoreCase(month)) {
        calendarMonth = Calendar.NOVEMBER;
    } else if (EndowConstants.FrequencyMonths.DECEMBER.equalsIgnoreCase(month)) {
        calendarMonth = Calendar.DECEMBER;
    }

    calendar.set(Calendar.MONTH, calendarMonth);

    return calendar;
}

From source file:ch.puzzle.itc.mobiliar.business.generator.control.extracted.ResourceDependencyResolverServiceTest.java

@Test
public void findExactOrClosestPastReleaseShouldReturnClosestPastRelease() {
    // given/* ww w  .  ja  v  a2 s  .c  o  m*/
    SortedSet<ReleaseEntity> releases = new TreeSet<>();
    releases.add(release1);
    releases.add(release2);
    releases.add(release3);
    releases.add(release4);

    Calendar cal = new GregorianCalendar();
    cal.set(2002, Calendar.JANUARY, 5);
    Date relevantDate = new Date(cal.getTimeInMillis());

    // when
    ReleaseEntity mostRelevantRelease = service.findExactOrClosestPastRelease(releases, relevantDate);

    // then
    assertThat(release2, is(mostRelevantRelease));
}

From source file:com.microsoft.tfs.core.clients.versioncontrol.internal.localworkspace.LocalItemExclusionCache.java

/**
 * Returns the last time we called the server to determine the default
 * exclusions.// w ww.  ja  v  a  2s  . c o  m
 *
 *
 * @param serverInfo
 * @return
 */
public Calendar getLastDefaultExclusionUpdate(final InternalServerInfo serverInfo) {
    Check.notNull(serverInfo, "serverInfo"); //$NON-NLS-1$

    ensureDiskCacheLoaded();

    try {
        dataManagementLock.readLock().lock();

        final ExclusionSet exclusionSet = exclusions.get(serverInfo);
        if (exclusionSet != null) {
            return exclusionSet.getLastDefaultExclusionUpdate();
        }

        // Nothing found, return that we have never done this.
        final Calendar ret = Calendar.getInstance(TimeZone.getTimeZone("UTC")); //$NON-NLS-1$
        ret.set(1, Calendar.JANUARY, 1, 0, 0, 0);
        ret.set(Calendar.MILLISECOND, 0);
        return ret;
    } finally {
        dataManagementLock.readLock().unlock();
    }
}

From source file:com.liferay.portal.security.auth.LombardyAutoLogin.java

protected User addUser(long companyId, String firstName, String lastName, String emailAddress,
        String screenName, Locale locale) throws Exception {

    long creatorUserId = 0;
    boolean autoPassword = false;
    String password1 = PwdGenerator.getPassword();
    String password2 = password1;
    boolean autoScreenName = false;
    String middleName = StringPool.BLANK;
    int prefixId = 0;
    int suffixId = 0;
    boolean male = true;
    int birthdayMonth = Calendar.JANUARY;
    int birthdayDay = 1;
    int birthdayYear = 1970;
    String jobTitle = StringPool.BLANK;
    long organizationId = 0;
    long locationId = 0;
    boolean sendEmail = false;

    return UserLocalServiceUtil.addUser(creatorUserId, companyId, autoPassword, password1, password2,
            autoScreenName, screenName, emailAddress, locale, firstName, middleName, lastName, prefixId,
            suffixId, male, birthdayMonth, birthdayDay, birthdayYear, jobTitle, organizationId, locationId,
            sendEmail);//  w  ww  . j  ava 2s  .c om
}

From source file:Dates.java

/**
 * Given a date, a proper TimeZone, return the ending date of the month of the
 * specified date and TimeZone. If TimeZone is null, meaning use default
 * TimeZone of the JVM.//from   w ww .ja  va2s.  co m
 */
final public static Date endOfYear(Date when, TimeZone tz) {
    if (tz == null)
        tz = TimeZones.getCurrent();
    final Calendar cal = Calendar.getInstance(tz);
    cal.setTimeInMillis(when.getTime()); // don't call cal.setTime(Date) which
                                         // will reset the TimeZone.

    final int year = cal.get(Calendar.YEAR);
    cal.clear();
    cal.set(year + 1, Calendar.JANUARY, 1);
    cal.setTimeInMillis(cal.getTimeInMillis() - 1);
    return cal.getTime();
}

From source file:net.sourceforge.openutils.mgnlcriteria.jcr.query.CriteriaTest.java

/**
 * Tests pagination of results./*w w  w .  ja v  a2s. c  o m*/
 * @throws Exception
 */
@Test
public void testSetPaging() throws Exception {
    Calendar begin = Calendar.getInstance();
    begin.set(1999, Calendar.JANUARY, 1);
    Calendar end = Calendar.getInstance();
    end.set(2001, Calendar.DECEMBER, 31);

    Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(RepositoryConstants.WEBSITE)
            .setBasePath("/pets").add(Restrictions.betweenDates("@birthDate", begin, end))
            .addOrder(Order.asc("@birthDate")).setPaging(5, 2);

    AdvancedResult result = criteria.execute();
    // first page:
    // --- 9 (title=Lucky, petType=bird, birthDate=1999-08-06)
    // --- 6 (title=George, petType=snake, birthDate=2000-01-20)
    // --- 4 (title=Jewel, petType=dog, birthDate=2000-03-07)
    // --- 11 (title=Freddy, petType=bird, birthDate=2000-03-09)
    // --- 12 (title=Lucky, petType=dog, birthDate=2000-06-24)
    // second page:
    // --- 1 (title=Leo, petType=cat, birthDate=2000-09-07)
    // --- 5 (title=Iggy, petType=lizard, birthDate=2000-11-30)
    // --- 3 (title=Rosy, petType=dog, birthDate=2001-04-17)
    Assert.assertEquals(result.getTotalSize(), 8);

    ResultIterator<? extends Node> iterator = result.getItems();
    Assert.assertEquals(iterator.getSize(), 3);
    Assert.assertEquals(CriteriaTestUtils.name(iterator.next()), "1");
    Assert.assertEquals(CriteriaTestUtils.name(iterator.next()), "5");
    Assert.assertEquals(CriteriaTestUtils.name(iterator.next()), "3");
}

From source file:ch.cyberduck.core.ftp.parser.UnixFTPEntryParserTest.java

@Test
public void testLowerCaseMonths() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX");

    FTPFile parsed;//from w w  w.j  a  v a2s. co  m

    parsed = parser.parseFTPEntry("drwxrwxrwx    41 spinkb  spinkb      1394 jan 21 20:57 Desktop");
    assertNotNull(parsed);
    assertEquals("Desktop", parsed.getName());
    assertEquals(FTPFile.DIRECTORY_TYPE, parsed.getType());
    assertEquals("spinkb", parsed.getUser());
    assertEquals("spinkb", parsed.getGroup());
    assertNotNull(parsed.getTimestamp());
    assertEquals(Calendar.JANUARY, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(21, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
}