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:edu.mayo.informatics.lexgrid.convert.directConversions.UMLSHistoryFileToSQL.java

private Date getSystemReleaseDate(String releaseId) throws Exception {
    String sYear = releaseId.substring(0, 4);
    int year = new Integer(sYear).intValue();

    String sMonth = releaseId.substring(4);
    int mon = 0;/*from  ww w  . j av a  2  s. co  m*/

    Calendar cal = Calendar.getInstance();
    if ("AA".equalsIgnoreCase(sMonth)) {
        mon = Calendar.JANUARY;
    } else if ("AB".equalsIgnoreCase(sMonth)) {
        mon = Calendar.APRIL;
    } else if ("AC".equalsIgnoreCase(sMonth)) {
        mon = Calendar.JULY;
    } else if ("AD".equalsIgnoreCase(sMonth)) {
        mon = Calendar.OCTOBER;
    } else {
        try {
            int i = Integer.parseInt(sMonth);

            switch (i) {
            case 1:
                mon = Calendar.JANUARY;
                break;
            case 2:
                mon = Calendar.FEBRUARY;
                break;
            case 3:
                mon = Calendar.MARCH;
                break;
            case 4:
                mon = Calendar.APRIL;
                break;
            case 5:
                mon = Calendar.MAY;
                break;
            case 6:
                mon = Calendar.JUNE;
                break;
            case 7:
                mon = Calendar.JULY;
                break;
            case 8:
                mon = Calendar.AUGUST;
                break;
            case 9:
                mon = Calendar.SEPTEMBER;
                break;
            case 10:
                mon = Calendar.OCTOBER;
                break;
            case 11:
                mon = Calendar.NOVEMBER;
                break;
            case 12:
                mon = Calendar.DECEMBER;
                break;

            default:
                throw new Exception("Release ID is not in required format: " + sMonth);
            }
        } catch (NumberFormatException e) {
            throw new Exception("Release ID is not in required format." + sMonth);
        }

    }
    cal.set(year, mon, 01, 0, 0, 0);
    cal.set(Calendar.MILLISECOND, 0);

    return new Date(cal.getTimeInMillis());
}

From source file:org.richfaces.component.CalendarComponentTest.java

public void testPreloadRanges() throws Exception {
    UICalendar calendar = (UICalendar) application.createComponent(UICalendar.COMPONENT_TYPE);
    calendar.setLocale(Locale.FRENCH);
    Calendar calendarObject = Calendar.getInstance();
    calendarObject.clear();// ww w. j a  v a2  s  . c  om
    calendarObject.set(2007, Calendar.JUNE, 10);

    Calendar preloadRangeBegin = Calendar.getInstance();
    preloadRangeBegin.clear();
    preloadRangeBegin.setTime(calendar.getDefaultPreloadBegin(calendarObject.getTime()));
    assertEquals(2007, preloadRangeBegin.get(Calendar.YEAR));
    assertEquals(Calendar.JUNE, preloadRangeBegin.get(Calendar.MONTH));
    assertEquals(1, preloadRangeBegin.get(Calendar.DATE));

    Calendar preloadRangeEnd = Calendar.getInstance();
    preloadRangeEnd.clear();
    preloadRangeEnd.setTime(calendar.getDefaultPreloadEnd(calendarObject.getTime()));
    assertEquals(2007, preloadRangeEnd.get(Calendar.YEAR));
    assertEquals(Calendar.JUNE, preloadRangeEnd.get(Calendar.MONTH));
    assertEquals(30, preloadRangeEnd.get(Calendar.DATE));

    calendarObject.set(2007, Calendar.JANUARY, 1);
    preloadRangeBegin.setTime(calendar.getDefaultPreloadBegin(calendarObject.getTime()));
    assertEquals(2007, preloadRangeBegin.get(Calendar.YEAR));
    assertEquals(Calendar.JANUARY, preloadRangeBegin.get(Calendar.MONTH));
    assertEquals(1, preloadRangeBegin.get(Calendar.DATE));

    calendarObject.set(2007, Calendar.JUNE, 10);
    calendar.setLocale(Locale.US);

    preloadRangeBegin.setTime(calendar.getDefaultPreloadBegin(calendarObject.getTime()));
    assertEquals(2007, preloadRangeBegin.get(Calendar.YEAR));
    assertEquals(Calendar.JUNE, preloadRangeBegin.get(Calendar.MONTH));
    assertEquals(1, preloadRangeBegin.get(Calendar.DATE));

    preloadRangeEnd.setTime(calendar.getDefaultPreloadEnd(calendarObject.getTime()));
    assertEquals(2007, preloadRangeEnd.get(Calendar.YEAR));
    assertEquals(Calendar.JUNE, preloadRangeEnd.get(Calendar.MONTH));
    assertEquals(30, preloadRangeEnd.get(Calendar.DATE));
}

From source file:ISO8601DateTimeFormat.java

/**
 * Write century, year, and months.//from  w  w w . j av  a2  s.  c om
 * @param sbuf The buffer to append the string.
 */
protected final void writeCCYYMM(StringBuffer sbuf) {
    int year = calendar.get(Calendar.YEAR);
    appendInt(sbuf, year, 4);

    String month;
    switch (calendar.get(Calendar.MONTH)) {
    case Calendar.JANUARY:
        month = "-01-";
        break;
    case Calendar.FEBRUARY:
        month = "-02-";
        break;
    case Calendar.MARCH:
        month = "-03-";
        break;
    case Calendar.APRIL:
        month = "-04-";
        break;
    case Calendar.MAY:
        month = "-05-";
        break;
    case Calendar.JUNE:
        month = "-06-";
        break;
    case Calendar.JULY:
        month = "-07-";
        break;
    case Calendar.AUGUST:
        month = "-08-";
        break;
    case Calendar.SEPTEMBER:
        month = "-09-";
        break;
    case Calendar.OCTOBER:
        month = "-10-";
        break;
    case Calendar.NOVEMBER:
        month = "-11-";
        break;
    case Calendar.DECEMBER:
        month = "-12-";
        break;
    default:
        month = "-NA-";
        break;
    }
    sbuf.append(month);

    int day = calendar.get(Calendar.DAY_OF_MONTH);
    appendInt(sbuf, day, 2);
}

From source file:com.mb.framework.util.DateTimeUtil.java

/**
 * This method is used for getting month long description
 * //from  w w  w  .ja v a  2  s . co  m
 * @param mthNum
 * @return
 */
public static String getMonthLongDesc(int mthNum) {
    String mthLongDesc;

    switch (mthNum) {
    case Calendar.JANUARY: {
        mthLongDesc = DateTimeConstants.JANUARY;
        break;
    }
    case Calendar.FEBRUARY: {
        mthLongDesc = DateTimeConstants.FEBRUARY;
        break;
    }
    case Calendar.MARCH: {
        mthLongDesc = DateTimeConstants.MARCH;
        break;
    }
    case Calendar.APRIL: {
        mthLongDesc = DateTimeConstants.APRIL;
        break;
    }
    case Calendar.MAY: {
        mthLongDesc = DateTimeConstants.MAY;
        break;
    }
    case Calendar.JUNE: {
        mthLongDesc = DateTimeConstants.JUNE;
        break;
    }
    case Calendar.JULY: {
        mthLongDesc = DateTimeConstants.JULY;
        break;
    }
    case Calendar.AUGUST: {
        mthLongDesc = DateTimeConstants.AUGUST;
        break;
    }
    case Calendar.SEPTEMBER: {
        mthLongDesc = DateTimeConstants.SEPTEMBER;
        break;
    }
    case Calendar.OCTOBER: {
        mthLongDesc = DateTimeConstants.OCTOBER;
        break;
    }
    case Calendar.NOVEMBER: {
        mthLongDesc = DateTimeConstants.NOVEMBER;
        break;
    }
    case Calendar.DECEMBER: {
        mthLongDesc = DateTimeConstants.DECEMBER;
        break;
    }
    default: {
        mthLongDesc = "";
        break;
    }
    }

    return mthLongDesc;
}

From source file:moviemanager.backend.RelationshipManagerTest.java

@Test
public void removePersonFromMovie() {
    log.info("Testing removing person from movie...");

    String personName = "Jack London (RemoveFromMovie)";
    String movieTitle = "Remove From Movie";

    //create movie
    Movie movie = new Movie();
    movie.setTitle(movieTitle);//  ww w  .jav  a2 s  . c  o  m
    movie.setYear(1906);
    movie.setLength(150);
    movieManager.createMovie(movie);
    assertNotNull(movie);

    //create person
    Calendar calendar = new GregorianCalendar(1876, Calendar.JANUARY, 12);
    Person person = new Person(personName, calendar);
    personManager.createPerson(person);
    assertNotNull(person);

    // add to relationship dtb and check it was added
    relationManager.addPersonToRole(person, movie, "writer");
    assertTrue(relationManager.checkRole(person, movie, Consts.WRITER));

    // remove person from movie relationship
    relationManager.removeRelationship(person, movie, Consts.WRITER);

    // check if relationship between given movie and person no longer exist
    assertTrue(relationManager.personsOfMovie(movie).isEmpty());
    assertTrue(relationManager.moviesOfPerson(person).isEmpty());
}

From source file:org.pentaho.metaverse.api.MetaverseLogicalIdGeneratorTest.java

@Test
public void testGenerateLogicalId_nullValue() throws Exception {
    when(node.getProperty("name")).thenReturn("john doe");
    when(node.getProperty("age")).thenReturn(null);
    when(node.getProperty("address")).thenReturn("1234 Pentaho Way Orlando, FL 12345");
    Calendar cal = GregorianCalendar.getInstance();
    cal.set(1976, Calendar.JANUARY, 1, 0, 0, 0);
    when(node.getProperty("birthday")).thenReturn(cal.getTime());
    when(node.getPropertyKeys()).thenReturn(new HashSet<String>() {
        {/* w  w w  .j ava  2s .co  m*/
            add("address");
            add("age");
            add("birthday");
            add("name");
        }
    });

    String logicalId = idGenerator.generateId(node);

    // it should come out in alphabetical order by key
    assertEquals("{\"address\":\"1234 Pentaho Way "
            + "Orlando, FL 12345\",\"age\":\"\",\"birthday\":\"1976-01-01 00:00:00\",\"name\":\"john doe\"}",
            logicalId);

    // make sure a call was made to add the logical id as a property
    verify(node).setProperty(DictionaryConst.PROPERTY_LOGICAL_ID, logicalId);
}

From source file:com.tr4android.support.extension.picker.date.DayPickerView.java

public DayPickerView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    mAccessibilityManager = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DatePickerDialog, defStyleAttr, 0); //TODO: add default style res

    final int firstDayOfWeek = a.getInt(R.styleable.DatePickerDialog_firstDayOfWeek,
            Calendar.getInstance(Locale.getDefault()).getFirstDayOfWeek());

    final String minDate = a.getString(R.styleable.DatePickerDialog_minDate);
    final String maxDate = a.getString(R.styleable.DatePickerDialog_maxDate);

    final int monthTextAppearanceResId = a.getResourceId(R.styleable.DatePickerDialog_monthTextAppearance,
            R.style.TextAppearance_Material_Widget_Calendar_Month);
    final int dayOfWeekTextAppearanceResId = a.getResourceId(R.styleable.DatePickerDialog_weekDayTextAppearance,
            R.style.TextAppearance_Material_Widget_Calendar_DayOfWeek);
    final int dayTextAppearanceResId = a.getResourceId(R.styleable.DatePickerDialog_dateTextAppearance,
            R.style.TextAppearance_Material_Widget_Calendar_Day);

    // Set up day selected color, if available.
    final ColorStateList daySelectorColor;
    if (a.hasValue(R.styleable.DatePickerDialog_daySelectorColor)) {
        daySelectorColor = a.getColorStateList(R.styleable.DatePickerDialog_daySelectorColor);
    } else {//  w  w w.ja v  a 2s .  c o m
        final TypedArray ta = context.obtainStyledAttributes(new int[] { R.attr.colorControlActivated });
        daySelectorColor = ta.getColorStateList(0);
        ta.recycle();
    }

    // Set up day highlight color, if available.
    final ColorStateList dayHighlightColor;
    if (a.hasValue(R.styleable.DatePickerDialog_dayHighlightColor)) {
        dayHighlightColor = a.getColorStateList(R.styleable.DatePickerDialog_dayHighlightColor);
    } else {
        final TypedArray ta = context.obtainStyledAttributes(new int[] { R.attr.colorControlHighlight });
        dayHighlightColor = ta.getColorStateList(0);
        ta.recycle();
    }

    a.recycle();

    // Set up adapter.
    mAdapter = new DayPickerPagerAdapter(context, R.layout.day_picker_month_item_material, R.id.month_view);
    mAdapter.setMonthTextAppearance(monthTextAppearanceResId);
    mAdapter.setDayOfWeekTextAppearance(dayOfWeekTextAppearanceResId);
    mAdapter.setDayTextAppearance(dayTextAppearanceResId);
    mAdapter.setDaySelectorColor(daySelectorColor);
    mAdapter.setDayHighlightColor(dayHighlightColor);

    final LayoutInflater inflater = LayoutInflater.from(context);
    final ViewGroup content = (ViewGroup) inflater.inflate(DEFAULT_LAYOUT, this, false);

    // Transfer all children from content to here.
    while (content.getChildCount() > 0) {
        final View child = content.getChildAt(0);
        content.removeViewAt(0);
        addView(child);
    }

    mPrevButton = (ImageButton) findViewById(R.id.prev);
    mPrevButton.setOnClickListener(mOnClickListener);

    mNextButton = (ImageButton) findViewById(R.id.next);
    mNextButton.setOnClickListener(mOnClickListener);

    mViewPager = (ViewPager) findViewById(R.id.day_picker_view_pager);
    mViewPager.setAdapter(mAdapter);
    mViewPager.addOnPageChangeListener(mOnPageChangedListener);

    // Set up background of the previous and next buttons.
    ViewCompatUtils.setBackground(mPrevButton, PickerThemeUtils.getNavButtonBackground(context));
    ViewCompatUtils.setBackground(mNextButton, PickerThemeUtils.getNavButtonBackground(context));

    // Set up min and max dates.
    final Calendar tempDate = Calendar.getInstance();
    if (!parseDate(minDate, tempDate)) {
        tempDate.set(DEFAULT_START_YEAR, Calendar.JANUARY, 1);
    }
    final long minDateMillis = tempDate.getTimeInMillis();

    if (!parseDate(maxDate, tempDate)) {
        tempDate.set(DEFAULT_END_YEAR, Calendar.DECEMBER, 31);
    }
    final long maxDateMillis = tempDate.getTimeInMillis();

    if (maxDateMillis < minDateMillis) {
        throw new IllegalArgumentException("maxDate must be >= minDate");
    }

    final long setDateMillis = MathUtils.constrain(System.currentTimeMillis(), minDateMillis, maxDateMillis);

    setFirstDayOfWeek(firstDayOfWeek);
    setMinDate(minDateMillis);
    setMaxDate(maxDateMillis);
    setDate(setDateMillis, false);

    // Proxy selection callbacks to our own listener.
    mAdapter.setOnDaySelectedListener(new DayPickerPagerAdapter.OnDaySelectedListener() {
        @Override
        public void onDaySelected(DayPickerPagerAdapter adapter, Calendar day) {
            if (mOnDaySelectedListener != null) {
                mOnDaySelectedListener.onDaySelected(DayPickerView.this, day);
            }
        }
    });
}

From source file:com.datamountaineer.streamreactor.connect.json.SimpleJsonConverterTest.java

@Test
public void timeToJson() throws IOException {
    GregorianCalendar calendar = new GregorianCalendar(1970, Calendar.JANUARY, 1, 0, 0, 0);
    calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
    calendar.add(Calendar.MILLISECOND, 14400000);
    java.util.Date date = calendar.getTime();

    JsonNode converted = converter.fromConnectData(Time.SCHEMA, date);
    assertTrue(converted.isTextual());//from w ww. j  a v a2  s.  com
    assertEquals(SimpleJsonConverter.TIME_FORMAT.format(date), converted.textValue());
}

From source file:com.baidu.rigel.biplatform.tesseract.meta.impl.TimeDimensionMemberServiceImpl.java

/**
 * ???//  w ww .ja  v a  2s  .  co m
 * 
 * @param level
 * @param parentMember
 * @return
 */
private List<MiniCubeMember> genMembersWithDayParentForAll(Level level, Member parentMember) {
    List<MiniCubeMember> members = Lists.newArrayList();
    Calendar calNow = Calendar.getInstance();
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.MONTH, Calendar.JANUARY);
    cal.set(Calendar.DAY_OF_MONTH, 1);
    SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
    while (cal.before(calNow) || (cal.compareTo(calNow) == 0)) {
        String day = sf.format(cal.getTime());
        MiniCubeMember dayMember = new MiniCubeMember(day);
        dayMember.setCaption(day);
        dayMember.setLevel(level);
        dayMember.setParent(parentMember);
        dayMember.setName(day);
        dayMember.setVisible(true);
        dayMember.getQueryNodes().add(day);
        members.add(dayMember);
        cal.add(Calendar.DATE, 1);
    }
    return members;
}

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

/**
 * @return// www  .  j a  va 2  s .  co m
 */
private Criteria toXpathExpressionJavadocExampleCriteria() {
    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.contains("@title", "Lucky"))
            .add(Restrictions.eq("@petType", "dog")).add(Restrictions.betweenDates("@birthDate", begin, end))
            .addOrder(Order.desc("@title"));
    return criteria;
}