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:com.microsoft.tfs.util.datetime.LenientDateTimeParser.java

private void computeFormats() {
    /*/*from  ww w. ja  v a  2  s .  co m*/
     * The expander takes pattern strings (and expands them) or takes
     * already created DateFormat instances and keeps them in the correct
     * order with the expanded strings.
     */
    final LenientDateTimeParserExpander expander = new LenientDateTimeParserExpander(false, locale);

    /*
     * Fill in the default locale date time formats. The indexes (0,1,2,3)
     * correspond to SimpleDateFormat.FULL, LONG, MEDIUM, and SHORT. We go
     * from FULL (0) to MEDIUM (2) with dates to prevent 2-digit date
     * matching (matches way too early). We go from FULL (0) to SHORT (3)
     * with times.
     *
     * Using the integers directly is a hack, but this whole parser is a
     * hack, so I don't feel too bad.
     */
    for (int i = 0; i <= 2; i++) {
        for (int j = 0; j <= 3; j++) {
            final DateFormat df = SimpleDateFormat.getDateTimeInstance(i, j, locale);
            df.setLenient(false);
            expander.add(df, true, true);
        }
    }

    /*
     * We can detect whether this parser's configured locale likes day
     * before month or month before day in its strings by instantiating a
     * short date formatter, passing a different month and day, and seeing
     * which appears first. We use the short date formatter so we don't get
     * (possibly localized) month names.
     */

    final Calendar c = new GregorianCalendar(timeZone, locale);
    c.clear();
    c.set(Calendar.MONTH, Calendar.JANUARY);
    c.set(Calendar.DATE, 5);
    c.set(Calendar.YEAR, 9999);
    final String defaultFormattedDate = SimpleDateFormat.getDateInstance(SimpleDateFormat.SHORT, locale)
            .format(c.getTime());

    final int monthIndex = defaultFormattedDate.indexOf("1"); //$NON-NLS-1$
    final int dateIndex = defaultFormattedDate.indexOf("5"); //$NON-NLS-1$

    // ISO goes next.
    expander.addExpanded(isoDateTimeFormats);

    if (dateIndex > monthIndex) {
        /*
         * Month-before-day. Use US before EU.
         */
        expander.addExpanded(usDateFormats);
        expander.addExpanded(euDateFormats);
    } else {
        /*
         * Day-before-month. Use EU before US.
         */
        expander.addExpanded(euDateFormats);
        expander.addExpanded(usDateFormats);
    }

    // Add just the default local date instances.
    for (int i = 0; i <= 2; i++) {
        final DateFormat df = SimpleDateFormat.getDateInstance(i, locale);
        df.setLenient(false);
        expander.add(df, true, false);
    }

    // Add just the default local time instances.
    for (int i = 0; i <= 3; i++) {
        final DateFormat df = SimpleDateFormat.getTimeInstance(i, locale);
        df.setLenient(false);
        expander.add(df, false, true);
    }

    // Generic time goes last.
    expander.addExpanded(genericTimeFormats);

    expandedFormats = expander.getSortedResults();
}

From source file:org.mifos.framework.util.helpers.DateUtils.java

public static Calendar getFistDayOfYearAfterNextYear() {
    Calendar cal = getCurrentDateCalendar();
    cal.set(Calendar.MONTH, Calendar.JANUARY);
    cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DATE));
    Calendar cal1 = getCurrentDateCalendar();
    cal1.set(cal.get(Calendar.YEAR) + 2, cal.get(Calendar.MONTH), cal.get(Calendar.DATE), 0, 0, 0);
    return cal1;//  ww  w . ja  v a 2  s.  c o m
}

From source file:com.wanikani.androidnotifier.graph.TYPlot.java

/**
 * Draws the grinds on the canvas. Since they are "over" the plot, this
 * method should be called last/*from ww w .  j av  a2s . c  o  m*/
 * @param canvas the canvas
 */
protected void drawGrid(Canvas canvas) {
    float f, dateLabelBaseline, levelupBaseline;
    Map<Integer, Pager.Marker> markers;
    Pager.Marker marker;
    int d, lo, hi, ascent;
    DateFormat df;
    String s;
    Calendar cal;

    canvas.drawLine(meas.plotArea.left, meas.plotArea.bottom, meas.plotArea.right, meas.plotArea.bottom,
            pas.axisPaint);
    f = vp.getRelPosition(0);
    lo = vp.leftmostDay();
    hi = vp.rightmostDay();
    cal = taxis.dayToCalendar(lo);

    markers = pager.dsource.getMarkers();

    ascent = (int) pas.dateLabels.getFontMetrics().ascent;

    dateLabelBaseline = meas.plotArea.bottom - ascent + meas.tickSize / 2;
    levelupBaseline = meas.plotArea.top - meas.tickSize / 2;

    for (d = meas.yaxisGrid; vp.getY(d) >= meas.plotArea.top; d += meas.yaxisGrid)
        canvas.drawLine(meas.plotArea.left, vp.getY(d), meas.plotArea.right, vp.getY(d), pas.gridPaint);

    for (d = lo; d <= hi; d++) {
        f = vp.getRelPosition(d);

        if (d == 0 || d == taxis.today)
            canvas.drawLine(f, meas.plotArea.top, f, meas.plotArea.bottom, pas.axisPaint);
        else if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY)
            canvas.drawLine(f, meas.plotArea.top, f, meas.plotArea.bottom, pas.gridPaint);

        if (cal.get(Calendar.DAY_OF_MONTH) == 1) {
            df = cal.get(Calendar.MONTH) == Calendar.JANUARY ? janf : datef;
            s = df.format(cal.getTime());
            canvas.drawLine(f, meas.plotArea.bottom - meas.tickSize / 2, f,
                    meas.plotArea.bottom + meas.tickSize / 2, pas.axisPaint);
            canvas.drawText(s, f, dateLabelBaseline, pas.dateLabels);
        }

        marker = markers.get(d);
        if (marker != null) {
            pas.levelup.setColor(marker.color);
            canvas.drawLine(f, meas.plotArea.top, f, meas.plotArea.bottom, pas.levelup);
            canvas.drawText(marker.name, f, levelupBaseline, pas.levelup);
        }

        cal.add(Calendar.DATE, 1);
    }
}

From source file:com.appeaser.sublimepickerlibrary.datepicker.SimpleMonthView.java

private static boolean isValidMonth(int month) {
    return month >= Calendar.JANUARY && month <= Calendar.DECEMBER;
}

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

/**
 * @see RadiologyOrderFormController#postDiscontinueRadiologyOrder(HttpServletRequest,
 *      HttpServletResponse, Order, String, Date)
 *//*ww w .  j a va 2 s.c  o  m*/
@Test
@Verifies(value = "should not redirect if discontinuation failed in pacs", method = "postDiscontinueRadiologyOrder(HttpServletRequest, HttpServletResponse, Order, String, Date)")
public void postDiscontinueRadiologyOrder_shouldNotRedirectIfDiscontinuationFailedInPacs() throws Exception {
    //given
    RadiologyOrder mockRadiologyOrderToDiscontinue = RadiologyTestData.getMockRadiologyOrder1();
    mockRadiologyOrderToDiscontinue.getStudy().setMwlStatus(MwlStatus.DISCONTINUE_ERR);
    String discontinueReason = "Wrong Procedure";
    Date discontinueDate = new GregorianCalendar(2015, Calendar.JANUARY, 01).getTime();

    Order mockDiscontinuationOrder = new Order();
    mockDiscontinuationOrder.setOrderId(2);
    mockDiscontinuationOrder.setAction(Order.Action.DISCONTINUE);
    mockDiscontinuationOrder.setOrderer(mockRadiologyOrderToDiscontinue.getOrderer());
    mockDiscontinuationOrder.setOrderReasonNonCoded(discontinueReason);
    mockDiscontinuationOrder.setPreviousOrder(mockRadiologyOrderToDiscontinue);

    MockHttpServletRequest mockRequest = new MockHttpServletRequest();
    mockRequest.addParameter("discontinueOrder", "discontinueOrder");
    MockHttpSession mockSession = new MockHttpSession();
    mockRequest.setSession(mockSession);

    when(radiologyService.getRadiologyOrderByOrderId(mockRadiologyOrderToDiscontinue.getOrderId()))
            .thenReturn(mockRadiologyOrderToDiscontinue);
    when(orderService.discontinueOrder(mockRadiologyOrderToDiscontinue, discontinueReason, discontinueDate,
            mockRadiologyOrderToDiscontinue.getOrderer(), mockRadiologyOrderToDiscontinue.getEncounter()))
                    .thenReturn(mockDiscontinuationOrder);

    ModelAndView modelAndView = radiologyOrderFormController.postDiscontinueRadiologyOrder(mockRequest, null,
            mockRadiologyOrderToDiscontinue, mockDiscontinuationOrder);

    assertNotNull(modelAndView);
    assertThat(modelAndView.getViewName(), is("module/radiology/radiologyOrderForm"));

    assertThat(modelAndView.getModelMap(), hasKey("order"));
    Order order = (Order) modelAndView.getModelMap().get("order");
    assertThat(order, is((Order) mockRadiologyOrderToDiscontinue));

    assertThat(modelAndView.getModelMap(), hasKey("radiologyOrder"));
    RadiologyOrder radiologyOrder = (RadiologyOrder) modelAndView.getModelMap().get("radiologyOrder");
    assertThat(radiologyOrder, is(mockRadiologyOrderToDiscontinue));

    assertNotNull(mockSession.getAttribute(WebConstants.OPENMRS_ERROR_ATTR));
    assertThat((String) mockSession.getAttribute(WebConstants.OPENMRS_ERROR_ATTR),
            is("radiology.failWorklist"));
}

From source file:com.nextgis.mobile.activity.MainActivity.java

void testInsert() {
    //test sync//from   ww w.  j ava  2  s. c o  m
    IGISApplication application = (IGISApplication) getApplication();
    MapBase map = application.getMap();
    NGWVectorLayer ngwVectorLayer = null;
    for (int i = 0; i < map.getLayerCount(); i++) {
        ILayer layer = map.getLayer(i);
        if (layer instanceof NGWVectorLayer) {
            ngwVectorLayer = (NGWVectorLayer) layer;
        }
    }
    if (null != ngwVectorLayer) {
        Uri uri = Uri
                .parse("content://" + SettingsConstants.AUTHORITY + "/" + ngwVectorLayer.getPath().getName());
        ContentValues values = new ContentValues();
        //values.put(VectorLayer.FIELD_ID, 26);
        values.put("width", 1);
        values.put("azimuth", 2.0);
        values.put("status", "grot");
        values.put("temperatur", -13);
        values.put("name", "get");

        Calendar calendar = new GregorianCalendar(2015, Calendar.JANUARY, 23);
        values.put("datetime", calendar.getTimeInMillis());

        try {
            GeoPoint pt = new GeoPoint(37, 55);
            pt.setCRS(CRS_WGS84);
            pt.project(CRS_WEB_MERCATOR);
            GeoMultiPoint mpt = new GeoMultiPoint();
            mpt.add(pt);
            values.put(Constants.FIELD_GEOM, mpt.toBlob());
        } catch (IOException e) {
            e.printStackTrace();
        }
        Uri result = getContentResolver().insert(uri, values);
        if (Constants.DEBUG_MODE) {
            if (result == null) {
                Log.d(TAG, "insert failed");
            } else {
                Log.d(TAG, result.toString());
            }
        }
    }
}

From source file:com.stratelia.webactiv.util.DateUtil.java

/**
 * Compute the date of the first day in the year of the specified date.
 * @param date the specified date.//from ww w.  j  a v  a  2s. com
 * @return a date for the first day of the year of the specified date.
 */
public static Date getFirstDateOfYear(Date date) {
    Calendar calendar = getInstance();
    calendar.setTime(date);
    calendar.set(MONTH, Calendar.JANUARY);
    calendar.set(DAY_OF_MONTH, 1);
    calendar.set(HOUR_OF_DAY, 0);
    calendar.set(MINUTE, 0);
    calendar.set(SECOND, 0);
    calendar.set(MILLISECOND, 0);
    return calendar.getTime();
}

From source file:cn.mljia.common.notify.utils.DateUtils.java

/**
 * ?//from w  w  w.j  a  va  2  s  .  com
 * 
 * @param date
 * @return
 */
public static Date[] getSeasonDate(Date date) {
    Date[] season = new Date[3];

    Calendar c = Calendar.getInstance();
    c.setTime(date);

    int nSeason = getSeason(date);
    if (nSeason == 1) {// 
        c.set(Calendar.MONTH, Calendar.JANUARY);
        season[0] = c.getTime();
        c.set(Calendar.MONTH, Calendar.FEBRUARY);
        season[1] = c.getTime();
        c.set(Calendar.MONTH, Calendar.MARCH);
        season[2] = c.getTime();
    } else if (nSeason == 2) {// 
        c.set(Calendar.MONTH, Calendar.APRIL);
        season[0] = c.getTime();
        c.set(Calendar.MONTH, Calendar.MAY);
        season[1] = c.getTime();
        c.set(Calendar.MONTH, Calendar.JUNE);
        season[2] = c.getTime();
    } else if (nSeason == 3) {// 
        c.set(Calendar.MONTH, Calendar.JULY);
        season[0] = c.getTime();
        c.set(Calendar.MONTH, Calendar.AUGUST);
        season[1] = c.getTime();
        c.set(Calendar.MONTH, Calendar.SEPTEMBER);
        season[2] = c.getTime();
    } else if (nSeason == 4) {// 
        c.set(Calendar.MONTH, Calendar.OCTOBER);
        season[0] = c.getTime();
        c.set(Calendar.MONTH, Calendar.NOVEMBER);
        season[1] = c.getTime();
        c.set(Calendar.MONTH, Calendar.DECEMBER);
        season[2] = c.getTime();
    }
    return season;
}

From source file:com.alkacon.opencms.calendar.CmsSerialDateWidget.java

/**
 * Returns the HTML for a select box for choosing the month.<p>
 * /*from   w  w  w  .j a v a2 s. com*/
 * @param name the name of the select box
 * @param parameters optional additional parameters
 * @param messages localized messages for localizing the options
 * @param selectedIndex the selected index of the month
 * @return the HTML for a select box for choosing the month
 */
protected String buildSelectMonth(String name, String parameters, CmsMessages messages, int selectedIndex) {

    SimpleDateFormat df = new SimpleDateFormat("MMMM", messages.getLocale());
    Calendar cal = new GregorianCalendar(messages.getLocale());
    cal.set(2000, Calendar.JANUARY, 1);
    List options = new ArrayList(12);
    List values = new ArrayList(12);
    for (int i = 0; i <= Calendar.DECEMBER; i++) {
        // iterate the months
        values.add(String.valueOf(cal.get(Calendar.MONTH)));
        options.add(df.format(cal.getTime()));
        cal.add(Calendar.MONTH, 1);
    }
    // add the name to the parameters
    if (CmsStringUtil.isNotEmpty(parameters)) {
        parameters += " ";
    }
    parameters += "name=\"" + name + "\"";
    return CmsWorkplace.buildSelect(parameters, options, values, selectedIndex, true);
}

From source file:cn.mljia.common.notify.utils.DateUtils.java

/**
 * /*  w w w  .jav  a 2 s.  co m*/
 * 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;
}