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:org.openlmis.core.repository.mapper.FacilityMapperIT.java
@Test public void shouldInsertFacilityWithSuppliedModifiedDateIfNotNull() throws Exception { Facility facility = make(a(defaultFacility)); facility.setLatitude(123.45678);//from ww w .j a va 2 s . co m facility.setLongitude(-321.87654); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.MONTH, Calendar.JANUARY); facility.setModifiedDate(calendar.getTime()); mapper.insert(facility); Facility resultFacility = mapper.getById(facility.getId()); assertThat(resultFacility.getCode(), is("F10010")); assertThat(resultFacility.getModifiedDate(), is(calendar.getTime())); }
From source file:org.kuali.kfs.module.endow.document.service.impl.FrequencyDatesServiceImpl.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 ww w .j a v a2 s .c o m*/ protected Calendar setCalendarWithMonth(String month, Date currentDate) { Calendar calendar = Calendar.getInstance(); calendar.setTime(currentDate); int calendarMonth = Calendar.JANUARY; 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:com.feilong.commons.core.date.DateUtil.java
/** * ,<code>00:00:00.000</code> . * /*from w ww . j a va2s. c o m*/ * <pre> * 2012-10-11 17:10:30.701, * * return 2012-01-01 00:00:00 * </pre> * * @param date * * @return date * @see #toCalendar(Date) * @see Calendar#set(int, int) * @see #dayBegin(Calendar) * @see Calendar#getTime() * @since 1.0 */ public static final Date getFirstDateOfThisYear(Date date) { Calendar calendar = toCalendar(date); calendar.set(Calendar.MONTH, Calendar.JANUARY); calendar.set(Calendar.DAY_OF_MONTH, 1); dayBegin(calendar); return calendar.getTime(); }
From source file:com.stratelia.webactiv.util.DateUtilTest.java
@Test public void testGetFirstDateOfYear() { Date dateTest = DateUtil.getFirstDateOfYear(java.sql.Date.valueOf("2013-04-20")); Calendar cal = DateUtil.convert(dateTest); assertThat(cal.get(Calendar.YEAR), is(2013)); assertThat(cal.get(Calendar.MONTH), is(Calendar.JANUARY)); assertThat(cal.get(Calendar.DAY_OF_MONTH), is(1)); assertThat(cal.get(Calendar.HOUR_OF_DAY), is(0)); assertThat(cal.get(Calendar.MINUTE), is(0)); assertThat(cal.get(Calendar.SECOND), is(0)); assertThat(cal.get(Calendar.MILLISECOND), is(0)); }
From source file:org.jfree.data.time.SecondTest.java
/** * Some checks for the getEnd() method./* w ww.ja v a2 s. c o m*/ */ @Test public void testGetEnd() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.JANUARY, 16, 3, 47, 55); cal.set(Calendar.MILLISECOND, 999); Second s = new Second(55, 47, 3, 16, 1, 2006); assertEquals(cal.getTime(), s.getEnd()); Locale.setDefault(saved); }
From source file:edu.stanford.muse.email.CalendarUtil.java
/** cool method to convert a pair of <yy, mm, dd> specs per Gregorian calendar to a date range. * Note: startM, endM are 0-based, startD, endD are 1-based. * startY/endY must be valid (>= 0), otherwise a null is returned for start / end dates. * Note: all months are 0-based, but days-of-month start from 1. * startM/endM/startD/endD can be invalid (< 0, or also > 11 in the case of months) in which case they are treated as "*". * i.e. put to their min values for start, or to max values for end. * if startM is invalid, startD is ignored and also considered invalid. likewise for endM/endD. * no handling of time zone, default TZ is assumed. * *///from w w w .ja v a 2 s.c om public static Pair<Date, Date> getDateRange(int startY, int startM, int startD, int endY, int endM, int endD) { Date startDate = null; // Calendar.JANUARY is 0, and Calendar.DECEMBER is 11 if (startY >= 0) { // check startM if (startM < Calendar.JANUARY || startM > Calendar.DECEMBER) { // invalid startM, assign M and D to Jan 1 startM = Calendar.JANUARY; startD = 1; } else { if (startD <= 0) // invalid startD startD = 1; } startDate = convertYYMMDDToDate(startY, startM, startD, true); } // endM/endD will be set to be BEYOND the end of the desired day/month/year. // e.g. if the end y/m/d params are 2001/-1/<whatever>, we want end y/m/d to correspond to 2002 1st Jan // and we'll compute endDate back to EOD 2001 31st Dec. // if the end y/m/d params are 2001/5/-1, we want y/m/d to become correspond to 2001, 1st June and we'll set endDate back to // EOD on 2001, 31st May. Date endDate = null; if (endY >= 0) { if (endM < Calendar.JANUARY || endM > Calendar.DECEMBER) { // invalid endM (and endD), therefore set to end endM = Calendar.JANUARY; endD = 1; endY++; } else { if (endD <= 0) { // no date provided, so just bump month. endD = 1; endM++; if (endM > Calendar.DECEMBER) { // obviously account for rollovers. so 2001/11/-1 sets end y/m/d to 2002/0/1 endY++; endM = Calendar.JANUARY; } } else { endD++; // bump day, but need to check if its more than the allowed days for that month. misery! // http://stackoverflow.com/questions/8940438/number-of-days-in-particular-month-of-particular-year Calendar tmp = new GregorianCalendar(endY, endM, 1); int maxDays = tmp.getActualMaximum(Calendar.DAY_OF_MONTH); if (endD > maxDays) { endD = 1; // bump month endM++; if (endM > Calendar.DECEMBER) { // obviously account for rollovers. so 2001/11/-1 sets end y/m/d to 2002/0/1 endY++; endM = Calendar.JANUARY; } } } } Date beyond_end = convertYYMMDDToDate(endY, endM, endD, true); endDate = new Date(beyond_end.getTime() - 1001L); } log.info("date range: " + startDate + "-" + endDate); return new Pair<Date, Date>(startDate, endDate); }
From source file:ch.ralscha.extdirectspring.controller.RouterControllerFormLoadTest.java
private static void checkFormLoadResult(ExtDirectResponse resp, double back, int tid) { assertThat(resp.getAction()).isEqualTo("remoteProviderFormLoad"); assertThat(resp.getMethod()).isEqualTo("method1"); assertThat(resp.getTid()).isEqualTo(tid); assertThat(resp.getType()).isEqualTo("rpc"); assertThat(resp.getWhere()).isNull(); assertThat(resp.getMessage()).isNull(); assertThat(resp.getResult()).isNotNull(); ExtDirectFormLoadResult wrapper = ControllerUtil.convertValue(resp.getResult(), ExtDirectFormLoadResult.class); assertThat(wrapper.isSuccess()).isTrue(); assertThat(wrapper.getData()).isNotNull(); FormInfo info = ControllerUtil.convertValue(wrapper.getData(), FormInfo.class); assertThat(Double.compare(back, info.getBack()) == 0).isTrue(); assertThat(info.isAdmin()).isEqualTo(true); assertThat(info.getAge()).isEqualTo(31); assertThat(info.getName()).isEqualTo("Bob"); assertThat(info.getSalary()).isEqualTo(new BigDecimal("10000.55")); assertThat(info.getBirthday()).isEqualTo(new GregorianCalendar(1980, Calendar.JANUARY, 15).getTime()); }
From source file:org.jfree.data.time.MinuteTest.java
/** * Some checks for the getEnd() method.//from w w w .j av a 2 s . c o m */ @Test public void testGetEnd() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/Rome")); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.JANUARY, 16, 3, 47, 59); cal.set(Calendar.MILLISECOND, 999); Minute m = new Minute(47, 3, 16, 1, 2006); assertEquals(cal.getTime(), m.getEnd()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); }
From source file:se.technipelago.weather.chart.Generator.java
public String[] generateYearlyCharts(int year) { init();/* ww w.j av a2 s . c o m*/ List<String> files = new ArrayList<String>(); try { // Historical data. Calendar cal = Calendar.getInstance(); int currentYear = cal.get(Calendar.YEAR); int currentMonth = cal.get(Calendar.MONTH); cal.set(Calendar.YEAR, year); cal.set(Calendar.MILLISECOND, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.MONTH, Calendar.JANUARY); Date start = cal.getTime(); if (year < currentYear) { cal.set(Calendar.MONTH, Calendar.DECEMBER); } else { cal.set(Calendar.MONTH, currentMonth); } cal.add(Calendar.MONTH, 1); cal.add(Calendar.MILLISECOND, -1); Date stop = cal.getTime(); Timespan period = new Timespan(start, stop); createHistoryChart(period, "temp_out", "Temperatur", "\u00B0Celcius", "temperature_" + year + ".png"); files.add("temperature_" + year + ".png"); createHistoryChart(period, "barometer", "Barometer", "Millibar", "barometer_" + year + ".png"); files.add("barometer_" + year + ".png"); createHistoryChart(period, "hum_out", "Luftfuktighet", "Procent", "humidity_" + year + ".png"); files.add("humidity_" + year + ".png"); createHistoryChart(period, "wind_avg", "Vindhastighet", "m/s", "wind_" + year + ".png"); files.add("wind_" + year + ".png"); createHistoryChart(period, "solar", "Solstr\u00e5lning", "W/m\u00B2", "solar_" + year + ".png"); files.add("solar_" + year + ".png"); createHistoryChart(period, "uv", "UV-index", "UV", "uv_" + year + ".png"); files.add("uv_" + year + ".png"); createRainHistoryChart(period, "rain_" + year + ".png"); files.add("rain_" + year + ".png"); } catch (IOException e) { log.log(Level.SEVERE, "I/O Error", e); } return files.toArray(new String[files.size()]); }
From source file:com.discovery.darchrow.date.DateUtil.java
/** * <span style="color:red"></span>,<code>00:00:00.000</code> . * /*w ww .j a v a2 s . c o m*/ * <pre> * 2012-10-11 17:10:30.701, * return 2012-01-01 00:00:00 * </pre> * * @param date * * @return date * @see #toCalendar(Date) * @see Calendar#set(int, int) * @see CalendarUtil#resetDayBegin(Calendar) * @see Calendar#getTime() */ public static Date getFirstDateOfThisYear(Date date) { Calendar calendar = toCalendar(date); calendar.set(Calendar.MONTH, Calendar.JANUARY); calendar.set(Calendar.DAY_OF_MONTH, 1); CalendarUtil.resetDayBegin(calendar); return CalendarUtil.toDate(calendar); }