List of usage examples for java.util Calendar JANUARY
int JANUARY
To view the source code for java.util Calendar JANUARY.
Click Source Link
From source file:com.flattr4android.rest.FlattrRestClient.java
public ArrayList<Click> getMyClicks(Date startDate, Date stopDate) throws OAuthMessageSignerException, OAuthExpectationFailedException, OAuthCommunicationException, FlattrServerResponseException, FlattrRestException, IOException { ArrayList<Click> clicks = new ArrayList<Click>(); Calendar cal = Calendar.getInstance(); cal.setTime(startDate);/* w ww . j a v a 2 s.co m*/ int startYear = cal.get(Calendar.YEAR); int startMonth = cal.get(Calendar.MONTH); int startDay = cal.get(Calendar.DAY_OF_MONTH); cal.setTime(stopDate); int stopYear = cal.get(Calendar.YEAR); int stopMonth = cal.get(Calendar.MONTH); int stopDay = cal.get(Calendar.DAY_OF_MONTH); int currentYear = startYear; int currentMonth = startMonth; Calendar currentClickDate = Calendar.getInstance(); while ((currentYear < stopYear) || ((currentYear == stopYear) && (currentMonth <= stopMonth))) { String period = Integer.toString(currentYear * 100 + (currentMonth + 1)); ArrayList<Click> current = getMyClicks(period); // If we are in the first month of the interval, // be careful not to add clicks too early in the month. boolean checkLow = ((currentYear == startYear) && (currentMonth == startMonth)); boolean checkHigh = ((currentYear == stopYear) && (currentMonth == stopMonth)); if ((!checkLow) && (!checkHigh)) { // Clicks in the middle of the interval: add all! clicks.addAll(current); } else { // Check one by one for (Click click : current) { currentClickDate.setTime(click.getDate()); int currentDay = currentClickDate.get(Calendar.DAY_OF_MONTH); if (((!checkLow) || (currentDay >= startDay)) && ((!checkHigh) || (currentDay <= stopDay))) { clicks.add(click); } } } currentMonth++; if (currentMonth > Calendar.DECEMBER) { currentMonth = Calendar.JANUARY; currentYear++; } } return clicks; }
From source file:org.jfree.data.time.junit.MonthTest.java
/** * Some checks for the getEnd() method.//from w ww . ja va 2 s . c om */ public void testGetEnd() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.JANUARY, 31, 23, 59, 59); cal.set(Calendar.MILLISECOND, 999); Month m = new Month(1, 2006); assertEquals(cal.getTime(), m.getEnd()); Locale.setDefault(saved); }
From source file:Time.java
/** * Testing this class.//from w w w . j ava2s .c om * * @param args * Not used. */ public static void main(String[] args) { // This proves that there are 912 days between the two major // terrorist attacks, not 911 as is common knowledge. Day september11 = new Day(2001, Calendar.SEPTEMBER, 11); Day march11 = new Day(2004, Calendar.MARCH, 11); System.out.println(september11.daysBetween(march11)); // This proves that Kennedy was president for 1037 days, // not 1000 as is the popular belief nor 1036 which is the // bluffers reply. Nerds knows when to add one... Day precidency = new Day(1961, Calendar.JANUARY, 20); Day assasination = new Day(1963, Calendar.NOVEMBER, 22); System.out.println(precidency.daysBetween(assasination) + 1); // Niel Armstrong walked the moon on a Sunday Day nielOnMoon = new Day(1969, Calendar.JULY, 20); System.out.println(nielOnMoon.getDayNumberOfWeek()); // Find last tuesdays for 2005 for (int i = 0; i < 12; i++) { Day tuesday = Day.getLastOfMonth(Calendar.TUESDAY, i, 2005); System.out.println(tuesday); } }
From source file:org.teiid.resource.adapter.google.dataprotocol.GoogleDataProtocolAPI.java
static Object convertValue(Calendar cal, Object object, SpreadsheetColumnType type) { switch (type) { case DATE:// w w w . ja v a 2 s .c o m case DATETIME: if (object instanceof String) { String stringVal = (String) object; if (stringVal.startsWith("Date(") && stringVal.endsWith(")")) { //$NON-NLS-1$ //$NON-NLS-2$ String[] parts = stringVal.substring(5, stringVal.length() - 1).split(","); //$NON-NLS-1$ if (cal == null) { cal = Calendar.getInstance(); } cal.clear(); if (type == SpreadsheetColumnType.DATETIME) { cal.set(Integer.valueOf(parts[0]), Integer.valueOf(parts[1]), Integer.valueOf(parts[2]), Integer.valueOf(parts[3]), Integer.valueOf(parts[4]), Integer.valueOf(parts[5])); object = new Timestamp(cal.getTimeInMillis()); } else { cal.set(Integer.valueOf(parts[0]), Integer.valueOf(parts[1]), Integer.valueOf(parts[2])); object = new Date(cal.getTimeInMillis()); } } } break; case TIMEOFDAY: if (object instanceof List<?>) { List<Double> doubleVals = (List<Double>) object; if (cal == null) { cal = Calendar.getInstance(); } cal.clear(); cal.set(Calendar.YEAR, 1970); cal.set(Calendar.MONTH, Calendar.JANUARY); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.MILLISECOND, 0); cal.set(Calendar.HOUR, doubleVals.get(0).intValue()); cal.set(Calendar.MINUTE, doubleVals.get(1).intValue()); cal.set(Calendar.SECOND, doubleVals.get(2).intValue()); //TODO: it's not proper to convey the millis on a time value cal.set(Calendar.MILLISECOND, doubleVals.get(3).intValue()); object = new Time(cal.getTimeInMillis()); } break; } return object; }
From source file:Time.java
/** * Return the 1-based month number of the month of this day. 1 = January, 2 = * February and so on./*www . j av a 2s. c om*/ * * @return Month number of this month */ public int getMonthNo() { // It is tempting to return getMonth() + 1 but this is conceptually // wrong, as Calendar month is an enumeration and the values are tags // only and can be anything. switch (getMonth()) { case Calendar.JANUARY: return 1; case Calendar.FEBRUARY: return 2; case Calendar.MARCH: return 3; case Calendar.APRIL: return 4; case Calendar.MAY: return 5; case Calendar.JUNE: return 6; case Calendar.JULY: return 7; case Calendar.AUGUST: return 8; case Calendar.SEPTEMBER: return 9; case Calendar.OCTOBER: return 10; case Calendar.NOVEMBER: return 11; case Calendar.DECEMBER: return 12; } // This will never happen return 0; }
From source file:com.baidu.rigel.biplatform.ac.util.DataModelUtils.java
/** * caption??caption//w w w. j a v a2 s.c o m * * @param startDay * @param pattern ? * @return caption * @throws ParseException */ public static String parseToEntireWeekCaption(String startDay, String pattern) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat(pattern); Calendar calendar = new GregorianCalendar(2012, Calendar.JANUARY, 1); calendar.setTime(sdf.parse(startDay)); calendar.add(Calendar.DAY_OF_MONTH, 6); String endDay = sdf.format(calendar.getTime()); return startDay + "~" + endDay; }
From source file:org.apache.james.protocols.imap.utils.DecoderUtilsTest.java
@Test public void testDecodeMonth() throws Exception { assertEquals(Calendar.JANUARY, DecoderUtils.decodeMonth('J', 'A', 'N')); assertEquals(Calendar.JANUARY, DecoderUtils.decodeMonth('j', 'a', 'n')); assertEquals(Calendar.FEBRUARY, DecoderUtils.decodeMonth('F', 'E', 'B')); assertEquals(Calendar.FEBRUARY, DecoderUtils.decodeMonth('f', 'e', 'b')); assertEquals(Calendar.MARCH, DecoderUtils.decodeMonth('M', 'A', 'R')); assertEquals(Calendar.MARCH, DecoderUtils.decodeMonth('m', 'a', 'r')); assertEquals(Calendar.APRIL, DecoderUtils.decodeMonth('A', 'P', 'R')); assertEquals(Calendar.APRIL, DecoderUtils.decodeMonth('a', 'p', 'r')); assertEquals(Calendar.MAY, DecoderUtils.decodeMonth('M', 'A', 'Y')); assertEquals(Calendar.MAY, DecoderUtils.decodeMonth('m', 'a', 'y')); assertEquals(Calendar.JUNE, DecoderUtils.decodeMonth('J', 'U', 'N')); assertEquals(Calendar.JUNE, DecoderUtils.decodeMonth('j', 'u', 'n')); assertEquals(Calendar.JULY, DecoderUtils.decodeMonth('J', 'U', 'L')); assertEquals(Calendar.JULY, DecoderUtils.decodeMonth('j', 'u', 'l')); assertEquals(Calendar.AUGUST, DecoderUtils.decodeMonth('A', 'U', 'G')); assertEquals(Calendar.AUGUST, DecoderUtils.decodeMonth('a', 'u', 'g')); assertEquals(Calendar.SEPTEMBER, DecoderUtils.decodeMonth('S', 'E', 'P')); assertEquals(Calendar.SEPTEMBER, DecoderUtils.decodeMonth('s', 'e', 'p')); assertEquals(Calendar.OCTOBER, DecoderUtils.decodeMonth('O', 'C', 'T')); assertEquals(Calendar.OCTOBER, DecoderUtils.decodeMonth('o', 'c', 't')); assertEquals(Calendar.NOVEMBER, DecoderUtils.decodeMonth('N', 'O', 'V')); assertEquals(Calendar.NOVEMBER, DecoderUtils.decodeMonth('n', 'o', 'v')); assertEquals(Calendar.DECEMBER, DecoderUtils.decodeMonth('D', 'E', 'C')); assertEquals(Calendar.DECEMBER, DecoderUtils.decodeMonth('d', 'e', 'c')); }
From source file:org.mifos.customers.client.persistence.ClientPersistenceIntegrationTest.java
public void testShouldReturnFalseForDuplicacyCheckOnGovtIdIfClientWithNullGovtIdInClosedState() throws Exception { setUpClients();/*from www .j av a 2 s. c om*/ localTestClient = createClosedClient(this.getClass().getSimpleName() + " Closed Client", DateUtils.getDate(1983, Calendar.JANUARY, 1), null); Assert.assertFalse(clientPersistence.checkForDuplicacyOnGovtIdForClosedClients(null)); }
From source file:com.money.manager.ex.reports.IncomeVsExpensesListFragment.java
private void initializeListView() { setEmptyText(getString(R.string.no_data)); // add header and footer try {//from www .ja v a2 s .c om setListAdapter(null); addListViewHeader(); mFooterListView = addListViewFooter(); } catch (Exception e) { Timber.e(e, "adding header and footer in income vs expense report"); } getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Object positionObj = parent.getItemAtPosition(position); Cursor cursor = (Cursor) positionObj; if (cursor == null) return; // i.e. footer row. IncomeVsExpenseReportEntity entity = IncomeVsExpenseReportEntity.from(cursor); SearchParameters params = new SearchParameters(); // show the details for the selected month/year. MmxDate dateTime = new MmxDate(); dateTime.setYear(entity.getYear()); int month = entity.getMonth(); if (month != IncomeVsExpensesActivity.SUBTOTAL_MONTH) { dateTime.setMonth(entity.getMonth() - 1); } else { // full year dateTime.setMonth(Calendar.JANUARY); } dateTime.firstDayOfMonth(); params.dateFrom = dateTime.toDate(); if (month == IncomeVsExpensesActivity.SUBTOTAL_MONTH) { dateTime.setMonth(Calendar.DECEMBER); } dateTime.lastDayOfMonth(); params.dateTo = dateTime.toDate(); Intent intent = IntentFactory.getSearchIntent(getActivity(), params); startActivity(intent); } }); }
From source file:org.mifos.customers.client.persistence.ClientPersistenceIntegrationTest.java
public void testShouldReturnFalseForDuplicacyCheckOnGovtIdIfClientWithEmptyGovtIdInClosedState() throws Exception { setUpClients();/*from w w w .ja va 2 s . c o m*/ localTestClient = createClosedClient(this.getClass().getSimpleName() + " Closed Client", DateUtils.getDate(1983, Calendar.JANUARY, 1), StringUtils.EMPTY); Assert.assertFalse(clientPersistence.checkForDuplicacyOnGovtIdForClosedClients(StringUtils.EMPTY)); }