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:myorg.relex.One2OneTest.java

/**
 * This test provides a demonstration of creating a one-to-one, uni-directional
 * relationship to a parent class that uses a composite primary key mapped thru and 
 * @EmbeddedId//  w w w  .j av a2 s.c  o m
 */
@Test
public void testOne2OneUniEmbeddedId() {
    log.info("*** testOne2OneUniEmbedded ***");
    Date showDate = new GregorianCalendar(1975 + new Random().nextInt(100), Calendar.JANUARY, 1).getTime();
    Date showTime = new GregorianCalendar(0, 0, 0, 0, 0, 0).getTime();
    ShowEvent show = new ShowEvent(showDate, showTime);
    show.setName("Rocky Horror");
    BoxOffice boxOffice = new BoxOffice(show);
    boxOffice.setTicketsLeft(500);
    em.persist(show);
    em.persist(boxOffice); //provider auto propagates parent.cid to dependent.FK mapped to dependent.cid 

    //flush commands to database, clear cache, and pull back new instance
    em.flush();
    em.clear();
    BoxOffice boxOffice2 = em.find(BoxOffice.class, new ShowEventPK(boxOffice.getDate(), boxOffice.getTime()));
    log.info("calling parent...");
    assertEquals("unexpected name", boxOffice.getShow().getName(), boxOffice2.getShow().getName());

    //verify the contents of the database tables, columns, and relationships
    Object[] cols = (Object[]) em.createNativeQuery("select show.date show_date, show.time show_time, "
            + "tickets.show_date ticket_date, tickets.show_time ticket_time, tickets.tickets "
            + "from RELATIONEX_SHOWEVENT show "
            + "join RELATIONEX_BOXOFFICE tickets on show.date = tickets.show_date and show.time = tickets.show_time "
            + "where tickets.show_date = ?1 and tickets.show_time = ?2")
            .setParameter(1, boxOffice.getShow().getDate(), TemporalType.DATE)
            .setParameter(2, boxOffice.getShow().getTime(), TemporalType.TIME).getSingleResult();
    log.info("row=" + Arrays.toString(cols));
    assertEquals("unexpected show_date", boxOffice2.getShow().getDate(), (Date) cols[0]);
    assertEquals("unexpected show_time", boxOffice2.getShow().getTime(), (Date) cols[1]);
    assertEquals("unexpected ticket_date", boxOffice2.getDate(), (Date) cols[2]);
    assertEquals("unexpected ticket_time", boxOffice2.getTime(), (Date) cols[3]);
    assertEquals("unexpected ticketsLeft", boxOffice2.getTicketsLeft(), ((Number) cols[4]).intValue());

    //remove the objects and flush commands to the database
    em.remove(boxOffice2);
    em.remove(boxOffice2.getShow());
    em.flush();
    assertNull("tickets not deleted",
            em.find(ShowEvent.class, new ShowEventPK(show.getDate(), show.getTime())));
    assertNull("show not deleted",
            em.find(BoxOffice.class, new ShowEventPK(boxOffice.getDate(), boxOffice.getTime())));
}

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

/**
 * Some checks for the getStart() method.
 *///from   ww w. j  a  v  a  2s.c o m
@Test
public void testGetStart() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.ITALY);
    Calendar cal = Calendar.getInstance(Locale.ITALY);
    cal.set(2006, Calendar.JANUARY, 16, 0, 0, 0);
    cal.set(Calendar.MILLISECOND, 0);
    Week w = new Week(3, 2006);
    assertEquals(cal.getTime(), w.getStart());
    Locale.setDefault(saved);
}

From source file:weka.server.JSONProtocol.java

/**
 * Convert a schedule object to a map (ready for encoding to a json string)
 *
 * @param schedule the schedule to convert
 * @return a map/* w  w w .  j  a  va 2  s. co m*/
 */
protected static Map<String, Object> scheduleToJsonMap(Schedule schedule) {
    Map<String, Object> scheduleMap = new HashMap<String, Object>();

    scheduleMap.put(SCHEDULE_DATE_FORMAT_KEY, schedule.m_dateFormat);
    SimpleDateFormat sdf = new SimpleDateFormat(schedule.m_dateFormat);
    if (schedule.getStartDate() != null) {
        scheduleMap.put(SCHEDULE_START_DATE_KEY, sdf.format(schedule.getStartDate()));
    }
    if (schedule.getEndDate() != null) {
        scheduleMap.put(SCHEDULE_END_DATE_KEY, sdf.format(schedule.getEndDate()));
    }

    scheduleMap.put(SCHEDULE_REPEAT_UNIT_KEY, schedule.getRepeatUnit());
    scheduleMap.put(SCHEDULE_REPEAT_VALUE_KEY, schedule.getRepeatValue());
    if (schedule.getDayOfTheWeek() != null && schedule.getDayOfTheWeek().size() > 0) {
        String dowList = "";
        for (int dow : schedule.getDayOfTheWeek()) {
            dowList += "," + Schedule.calendarDOWToString(dow);
        }
        dowList = dowList.substring(1);
        scheduleMap.put(SCHEDULE_DAY_OF_WEEK_KEY, dowList);
    }

    if (schedule.getMonthOfTheYear() >= Calendar.JANUARY && schedule.getMonthOfTheYear() <= Calendar.DECEMBER) {
        scheduleMap.put(SCHEDULE_MONTH_OF_YEAR_KEY,
                Schedule.calendarMonthToString(schedule.getMonthOfTheYear()));
    }

    scheduleMap.put(SCHEDULE_DAY_OF_MONTH_KEY, schedule.getDayOfTheMonth());
    if (schedule.getOccurrenceWithinMonth() != null) {
        scheduleMap.put(SCHEDULE_OCCURRENCE_KEY, schedule.getOccurrenceWithinMonth().toString());
    }

    return scheduleMap;
}

From source file:com.feilong.core.date.DateUtil.java

/**
 *  <code>date</code> <code>week</code>.
 * /*from ww  w  .j a  v a 2  s . c om*/
 * <pre class="code">
 *  2015-7-29 14:08
 * DateUtil.getFirstWeekOfSpecifyDateYear(NOW, Calendar.FRIDAY) =2015-01-02 00:00:00.000
 * DateUtil.getFirstWeekOfSpecifyDateYear(NOW, Calendar.MONDAY) =2015-01-05 00:00:00.000
 * </pre>
 * 
 * <p>
 * {@link Calendar#DAY_OF_WEEK_IN_MONTH} ?. DAY_OF_WEEK ,???.<br>
 *  {@link Calendar#WEEK_OF_MONTH}  {@link Calendar#WEEK_OF_YEAR} ??,?? {@link Calendar#getFirstDayOfWeek()} 
 * {@link Calendar#getMinimalDaysInFirstWeek()}.
 * </p>
 * 
 * <p>
 * DAY_OF_MONTH 1  7  DAY_OF_WEEK_IN_MONTH 1;<br>
 * 8  14  DAY_OF_WEEK_IN_MONTH 2,?.<br>
 * DAY_OF_WEEK_IN_MONTH 0  DAY_OF_WEEK_IN_MONTH 1 ?.<br>
 * ?,,? DAY_OF_WEEK = SUNDAY, DAY_OF_WEEK_IN_MONTH = -1.<br>
 * ?,????.<br>
 * , 31 , DAY_OF_WEEK_IN_MONTH -1  DAY_OF_WEEK_IN_MONTH 5  DAY_OF_WEEK_IN_MONTH 4 ??
 * </p>
 * 
 * @param date
 *            
 * @param week
 *             1 ?2 3 4 5 6 7, ? {@link Calendar#SUNDAY}, {@link Calendar#MONDAY}, {@link Calendar#TUESDAY},
 *            {@link Calendar#WEDNESDAY}, {@link Calendar#THURSDAY}, {@link Calendar#FRIDAY}, {@link Calendar#SATURDAY}
 * @return  <code>date</code> null, {@link NullPointerException}
 * @see Calendar#SUNDAY
 * @see Calendar#MONDAY
 * @see Calendar#TUESDAY
 * @see Calendar#WEDNESDAY
 * @see Calendar#THURSDAY
 * @see Calendar#FRIDAY
 * @see Calendar#SATURDAY
 * @since 1.3.0
 */
public static Date getFirstWeekOfSpecifyDateYear(Date date, int week) {
    Calendar calendar = toCalendar(date);
    calendar.clear();
    calendar.set(Calendar.YEAR, getYear(date));
    calendar.set(Calendar.MONTH, Calendar.JANUARY);
    calendar.set(Calendar.DAY_OF_WEEK_IN_MONTH, 1);
    calendar.set(Calendar.DAY_OF_WEEK, week);
    return CalendarUtil.toDate(calendar);
}

From source file:org.hawkular.alerts.api.model.action.TimeConstraint.java

private int month(String sMonth) {
    if (isEmpty(sMonth)) {
        return -1;
    }//from  ww  w  . j a  v a2 s .  co  m
    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;
    }
}

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

/**
 * Some checks for the getEnd() method./*from  w w  w.  j ava  2 s .c om*/
 */
@Test
public void testGetEnd() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.ITALY);
    Calendar cal = Calendar.getInstance(Locale.ITALY);
    cal.set(2006, Calendar.JANUARY, 8, 23, 59, 59);
    cal.set(Calendar.MILLISECOND, 999);
    Week w = new Week(1, 2006);
    assertEquals(cal.getTime(), w.getEnd());
    Locale.setDefault(saved);
}

From source file:de.gebatzens.sia.SIAApp.java

public String getSeasonTheme() {
    int m = Calendar.getInstance().get(Calendar.MONTH);
    switch (m) {/* www  .j  a  v  a2s .c o m*/
    case Calendar.OCTOBER:
    case Calendar.NOVEMBER:
    case Calendar.DECEMBER:
    case Calendar.JANUARY:
    case Calendar.FEBRUARY:
    case Calendar.MARCH:
        return "Winter";
    default:
        return "Summer";
    }
}

From source file:gov.medicaid.screening.dao.impl.MedicalPracticeLicenseDAOBean.java

/**
 * Parse the License information.// w  w  w.  j  a va  2  s  .  com
 *
 * @param city the license provider city
 * @param details the details page
 * @return the parsed license
 */
private License parseLicense(String city, Document details) {
    License license = new License();
    license.setCity(city);

    ProviderProfile profile = new ProviderProfile();
    license.setProfile(profile);

    String fullName = details.select("#_ctl7_lblName").text();
    User user = new User();
    String[] nameParts = fullName.split(",");
    if (nameParts.length > 0) {
        user.setLastName(nameParts[0].trim());
    }
    if (nameParts.length > 1) {
        user.setFirstName(nameParts[1].trim());
    }
    profile.setUser(user);

    String licenseType = details.select("#_ctl7_ProfileInfoLicense_lblLicType").text();
    LicenseType licType = new LicenseType();
    licType.setName(licenseType);
    license.setType(licType);

    String licenseNo = details.select("#_ctl7_ProfileInfoLicense_lblLicNbr").text();
    license.setLicenseNumber(licenseNo);

    String licensureAddress1 = details.select("#_ctl7_ProfileInfoPublic_lblAddress").text();
    String licensureAddress2 = details.select("#_ctl7_ProfileInfoPublic_lblAddress2").text();
    String licensureCityState = details.select("#_ctl7_ProfileInfoPublic_lblCity").text();
    Address address = new Address();
    address.setLocation(licensureAddress1 + " " + licensureAddress2);
    setCityStateZip(address, licensureCityState);

    String email = details.select("#_ctl7_ProfileInfoPublic_lblEmail").text();
    profile.setContactEmail(email);
    String birthYear = details.select("#_ctl7_ProfileInfoPublic_lblBirthYear").text();
    if (Util.isNotBlank(birthYear)) {
        profile.setDob(new GregorianCalendar(Integer.parseInt(birthYear), Calendar.JANUARY, 1).getTime());
    }

    String gender = details.select("#_ctl7_ProfileInfoPublic_lblGender").text();
    if ("Male".equals(gender)) {
        profile.setSex(Sex.MALE);
    } else if ("Female".equals(gender)) {
        profile.setSex(Sex.FEMALE);
    }

    String expirationDate = details.select("#_ctl7_ProfileInfoLicense_lblExpDate").text();
    String originalIssueDate = details.select("#_ctl7_ProfileInfoLicense_lblGrantDate").text();

    Date issueDate = parseDate(originalIssueDate, DATE_FORMAT);
    if (issueDate != null) {
        license.setOriginalIssueDate(issueDate);
    }

    Date expireDate = parseDate(expirationDate, DATE_FORMAT);
    if (expireDate != null) {
        license.setExpireDate(expireDate);
    }

    String licenseStatus = details.select("#_ctl7_ProfileInfoLicense_lblLicStatus").text();
    LicenseStatus status = new LicenseStatus();
    status.setName(licenseStatus);
    license.setStatus(status);

    String disciplinaryAction = details.select("#_ctl7_ProfileInfoLicense_lblDiscAction").text();
    String correctiveAction = details.select("#_ctl7_ProfileInfoLicense_lblCorrAction").text();

    license.setDiscipline(!"No".equals(disciplinaryAction.trim()));
    license.setCorrectiveAction(!"No".equals(correctiveAction.trim()));

    String medSchool = details.select("#_ctl7_ProfileInfoEducation_lblName").text();
    MedicalSchool medicalSchool = new MedicalSchool();
    medicalSchool.setName(medSchool);
    license.setMedicalSchool(medicalSchool);

    String degree = details.select("#_ctl7_ProfileInfoEducation_lblDegree").text();
    if ("PhD".equals(degree.trim())) {
        profile.setDegree(Degree.DOCTORATE);
    } else if (!Util.isBlank(degree)) {
        profile.setDegree(Degree.MASTER);
    }

    PrivatePractice privatePractice = new PrivatePractice();
    profile.setPrivatePractice(privatePractice);

    String primaryAddressName = details.select("#_ctl7_ProfileInfoPractices_lblPrimaryName").text();
    String primaryAddress1 = details.select("#_ctl7_ProfileInfoPractices_lblPrimaryAddress").text();
    String primaryCityState = details.select("#_ctl7_ProfileInfoPractices_lblPrimaryAddress2").text();
    String primaryPhone = details.select("#_ctl7_ProfileInfoPractices_lblPrimaryPhone").text();
    if (Util.isNotBlank(primaryAddressName) || Util.isNotBlank(primaryAddress1)
            || Util.isNotBlank(primaryCityState)) {
        Address primary = new Address();
        address.setLocation(primaryAddressName + " " + primaryAddress1);
        setCityStateZip(primary, primaryCityState);
        privatePractice.setOfficeAddress(primary);
    }
    privatePractice.setOfficePhoneNumber(primaryPhone);

    String secondaryAddressName = details.select("#_ctl7_ProfileInfoPractices_lblSecondaryName").text();
    String secondaryAddress1 = details.select("#_ctl7_ProfileInfoPractices_lblSecondaryAddress").text();
    String secondaryCityState = details.select("#_ctl7_ProfileInfoPractices_lblSecondaryAddress2").text();
    String secondaryPhone = details.select("#_ctl7_ProfileInfoPractices_lblSecondaryPhone").text();

    if (Util.isNotBlank(secondaryAddressName) || Util.isNotBlank(secondaryAddress1)
            || Util.isNotBlank(secondaryCityState)) {
        Address secondary = new Address();
        address.setLocation(secondaryAddressName + " " + secondaryAddress1);
        setCityStateZip(secondary, secondaryCityState);
        privatePractice.setSecondaryAddress(secondary);
    }

    privatePractice.setSecondaryPhoneNumber(secondaryPhone);

    Elements specialties = details.select("#_ctl7_ProfileInfoSpecialty_dgSpecialty tr:gt(0)");
    List<Specialty> sps = new ArrayList<Specialty>();
    for (Element element : specialties) {
        Specialty sp = new Specialty();
        SpecialtyType spt = new SpecialtyType();
        spt.setName(element.select("td:eq(0)").text());
        sp.setType(spt);
        sp.setName(element.select("td:eq(1)").text());
        sps.add(sp);
    }
    profile.setSpecialties(sps);
    return license;
}

From source file:ru.runa.wfe.extension.handler.var.FormulaActionHandlerOperations.java

public Object translate(Object o, Class<?> c) {
    if (c == String.class && Date.class.isInstance(o)) {
        Date date = (Date) o;
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);//w  ww.java 2  s .c  o  m
        if (calendar.get(Calendar.YEAR) == 1970 && calendar.get(Calendar.MONTH) == Calendar.JANUARY
                && calendar.get(Calendar.DAY_OF_MONTH) == 1) {
            return CalendarUtil.format(date, CalendarUtil.HOURS_MINUTES_FORMAT);
        }
        if (calendar.get(Calendar.HOUR) == 0 && calendar.get(Calendar.MINUTE) == 0
                && calendar.get(Calendar.SECOND) == 0) {
            return CalendarUtil.format(date, CalendarUtil.DATE_WITHOUT_TIME_FORMAT);
        }
        return CalendarUtil.format(date, CalendarUtil.DATE_WITH_HOUR_MINUTES_FORMAT);
    }
    if (Date.class.isAssignableFrom(c) && Date.class.isInstance(o)) {
        return o;
    }
    return TypeConversionUtil.convertTo(c, o);
}

From source file:org.openmrs.module.radiology.web.controller.PortletsControllerTest.java

/**
 * @see PortletsController#isEndDateBeforeStartDate(Date, Date)
 * @verifies return true if end date is after start date
 *//*from w  w w  . j  a v  a2  s.  c om*/
@Test
public void isEndDateBeforeStartDate_shouldReturnTrueIfEndDateIsAfterStartDate() throws Exception {

    Method isEndDateBeforeStartDateMethod = portletsController.getClass().getDeclaredMethod(
            "isEndDateBeforeStartDate", new Class[] { java.util.Date.class, java.util.Date.class });
    isEndDateBeforeStartDateMethod.setAccessible(true);

    Date startDate = new GregorianCalendar(2010, Calendar.OCTOBER, 10).getTime();
    Date endDate = new GregorianCalendar(2001, Calendar.JANUARY, 01).getTime();

    Boolean isEndDateBeforeStartDate = (Boolean) isEndDateBeforeStartDateMethod.invoke(portletsController,
            new Object[] { startDate, endDate });
    assertThat(isEndDateBeforeStartDate, is(true));
}