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:ch.puzzle.itc.mobiliar.business.generator.control.extracted.ResourceDependencyResolverServiceTest.java
@Test public void findExactOrClosestPastReleaseShouldReturnExactRelease() { // given/*from w ww.ja va 2s. c o m*/ SortedSet<ReleaseEntity> releases = new TreeSet<>(); releases.add(release1); releases.add(release2); releases.add(release3); releases.add(release4); Calendar cal = new GregorianCalendar(); cal.set(2002, Calendar.JANUARY, 1); Date relevantDate = new Date(cal.getTimeInMillis()); // when ReleaseEntity mostRelevantRelease = service.findExactOrClosestPastRelease(releases, relevantDate); // then assertThat(release2, is(mostRelevantRelease)); }
From source file:com.mb.framework.util.DateTimeUtil.java
/** * This method is used for getting calendar number of month by month * description/*from ww w . java 2 s . com*/ * * @param monthDescr * @return */ public static int getMonthNum(String monthDescr) { int numOfMonth = -1; if (DateTimeConstants.JANUARY.equals(monthDescr)) { numOfMonth = Calendar.JANUARY; } if (DateTimeConstants.FEBRUARY.equals(monthDescr)) { numOfMonth = Calendar.FEBRUARY; } if (DateTimeConstants.MARCH.equals(monthDescr)) { numOfMonth = Calendar.MARCH; } if (DateTimeConstants.APRIL.equals(monthDescr)) { numOfMonth = Calendar.APRIL; } if (DateTimeConstants.MAY.equals(monthDescr)) { numOfMonth = Calendar.MAY; } if (DateTimeConstants.JUNE.equals(monthDescr)) { numOfMonth = Calendar.JUNE; } if (DateTimeConstants.JULY.equals(monthDescr)) { numOfMonth = Calendar.JULY; } if (DateTimeConstants.AUGUST.equals(monthDescr)) { numOfMonth = Calendar.AUGUST; } if (DateTimeConstants.SEPTEMBER.equals(monthDescr)) { numOfMonth = Calendar.SEPTEMBER; } if (DateTimeConstants.OCTOBER.equals(monthDescr)) { numOfMonth = Calendar.OCTOBER; } if (DateTimeConstants.NOVEMBER.equals(monthDescr)) { numOfMonth = Calendar.NOVEMBER; } if (DateTimeConstants.DECEMBER.equals(monthDescr)) { numOfMonth = Calendar.DECEMBER; } return numOfMonth; }
From source file:Dates.java
/** * Given a date, a proper TimeZone, return the beginning date of the month of * the specified date and TimeZone. If TimeZone is null, meaning use default * TimeZone of the JVM./*from w w w. ja v a 2 s.co m*/ */ final public static Date beginOfYear(Date when, TimeZone tz) { if (tz == null) tz = TimeZones.getCurrent(); final Calendar cal = Calendar.getInstance(tz); cal.setTimeInMillis(when.getTime()); // don't call cal.setTime(Date) which // will reset the TimeZone. final int year = cal.get(Calendar.YEAR); cal.clear(); cal.set(year, Calendar.JANUARY, 1); return cal.getTime(); }
From source file:com.swiftcorp.portal.common.util.CalendarUtils.java
@Deprecated public static Calendar addMonthDayToCal(Calendar cal, int month, int day) { Date d = new Date(); int daysToAdd = 0; // Calendar cal = Calendar.getInstance(); int currentMonth = cal.get(2); long t = 0;//from www . j av a 2 s . com t = d.getTime(); if (month > 0) { // cal.get ( month ); for (int i = 0; i < month; i++) { if (currentMonth < 12) { if (currentMonth == Calendar.JANUARY) { cal.set(2, Calendar.JANUARY); daysToAdd += cal.getActualMaximum(Calendar.DAY_OF_MONTH); } else if (currentMonth == Calendar.FEBRUARY) { cal.set(2, Calendar.FEBRUARY); daysToAdd += cal.getActualMaximum(Calendar.DAY_OF_MONTH); } else if (currentMonth == Calendar.MARCH) { cal.set(2, Calendar.MARCH); daysToAdd += cal.getActualMaximum(Calendar.DAY_OF_MONTH); } else if (currentMonth == Calendar.APRIL) { cal.set(2, Calendar.APRIL); daysToAdd += cal.getActualMaximum(Calendar.DAY_OF_MONTH); } else if (currentMonth == Calendar.MAY) { cal.set(2, Calendar.MAY); daysToAdd += cal.getActualMaximum(Calendar.DAY_OF_MONTH); } else if (currentMonth == Calendar.JUNE) { cal.set(2, Calendar.JUNE); daysToAdd += cal.getActualMaximum(Calendar.DAY_OF_MONTH); } else if (currentMonth == Calendar.JULY) { cal.set(2, Calendar.JULY); daysToAdd += cal.getActualMaximum(Calendar.DAY_OF_MONTH); } else if (currentMonth == Calendar.AUGUST) { cal.set(2, Calendar.AUGUST); daysToAdd += cal.getActualMaximum(Calendar.DAY_OF_MONTH); } else if (currentMonth == Calendar.SEPTEMBER) { cal.set(2, Calendar.SEPTEMBER); daysToAdd += cal.getActualMaximum(Calendar.DAY_OF_MONTH); } else if (currentMonth == Calendar.OCTOBER) { cal.set(2, Calendar.OCTOBER); daysToAdd += cal.getActualMaximum(Calendar.DAY_OF_MONTH); } else if (currentMonth == Calendar.NOVEMBER) { cal.set(2, Calendar.NOVEMBER); daysToAdd += cal.getActualMaximum(Calendar.DAY_OF_MONTH); } else if (currentMonth == Calendar.DECEMBER) { cal.set(2, Calendar.DECEMBER); daysToAdd += cal.getActualMaximum(Calendar.DAY_OF_MONTH); } currentMonth++; } else { currentMonth = 0; i--; } } } daysToAdd += day; // add the desired number of days to the long value using milli seconds t += daysToAdd * MILLIS_PER_DAY; cal.setTime(new Date(t)); // and now you can format the date the way you want String result = Integer.toString(cal.get(Calendar.DAY_OF_MONTH)) + "-" + Integer.toString(cal.get(Calendar.MONTH) + 1) + "-" + Integer.toString(cal.get(Calendar.YEAR)); System.out.println("result month add::" + result); return cal; }
From source file:agency.AgentManagerImplTest.java
@Test public void testUpdateAgentValidLevel() { //create agents Agent agent = newAgent01();/* www. j a v a 2 s . c om*/ Agent agent02 = newAgent02(); manager.createAgent(agent); manager.createAgent(agent02); Agent reference = manager.findAgentById(agent.getId()); assertNotNull("Agent has not been added to the DB", reference); reference.setLevel(4); manager.updateAgent(reference); assertEquals("Error update of agent level", 4, reference.getLevel()); assertEquals("Error in name attribute while updating agent's level", "James Bond", reference.getName()); assertEquals("Error in born attribute while updating agent's name", new GregorianCalendar(1980, Calendar.JANUARY, 1).getTime(), reference.getBorn()); assertEquals("Error in note attribute while updating agent's name", "Best agent ever", reference.getNote()); // Check if updates didn't affect other records assertDeepEquals(agent02, manager.findAgentById(agent02.getId())); }
From source file:ch.cyberduck.core.ftp.FTPPathTest.java
@Test public void testTimestamp() { final AttributedList<Path> children = new AttributedList<Path>(); FTPPath path = (FTPPath) PathFactory.createPath( SessionFactory.createSession(new Host(Protocol.FTP, "localhost")), "/www", Path.DIRECTORY_TYPE); String[] replies = new String[] { "Type=dir;Modify=19990112033045; text" //yyyyMMddHHmmss };//from ww w . j a v a 2 s. c om boolean success = path.parseMlsdResponse(children, Arrays.asList(replies)); assertTrue(success); assertEquals(1, children.size()); Calendar date = Calendar.getInstance(TimeZone.getDefault()); date.set(1999, Calendar.JANUARY, 12, 3, 30, 45); date.set(Calendar.MILLISECOND, 0); assertEquals(date.getTime().getTime(), children.get(0).attributes().getModificationDate()); }
From source file:adalid.commons.util.TimeUtils.java
public static String defaultTemporalString(Object object) { java.util.Date date = object instanceof java.util.Date ? (java.util.Date) object : null; if (date == null) { return null; }/*from ww w . j ava 2 s . c o m*/ Calendar c = Calendar.getInstance(); c.setTimeInMillis(date.getTime()); int dd = c.get(Calendar.YEAR); int MM = c.get(Calendar.MONTH); int yy = c.get(Calendar.DAY_OF_MONTH); int hh = c.get(Calendar.HOUR_OF_DAY); int mm = c.get(Calendar.MINUTE); int ss = c.get(Calendar.SECOND); int ms = c.get(Calendar.MILLISECOND); boolean dateless = dd == 1 && MM == Calendar.JANUARY && yy == 1970; boolean timeless = hh + mm + ss + ms == 0; return timeless ? defaultDateString(date) : dateless ? defaultTimeString(date) : defaultTimestampString(date); }
From source file:com.health.openscale.gui.GraphFragment.java
private void generateColumnData() { int[] numOfMonth = openScale.getCountsOfMonth(calYears.get(Calendar.YEAR)); Calendar calMonths = Calendar.getInstance(); calMonths.set(Calendar.MONTH, Calendar.JANUARY); SimpleDateFormat month_date = new SimpleDateFormat("MMM", Locale.getDefault()); List<AxisValue> axisValues = new ArrayList<AxisValue>(); List<Column> columns = new ArrayList<Column>(); for (int i = 0; i < 12; i++) { String month_name = month_date.format(calMonths.getTime()); axisValues.add(new AxisValue(i, month_name.toCharArray())); List<ColumnValue> values = new ArrayList<ColumnValue>(); values.add(new ColumnValue(numOfMonth[i], Utils.COLORS[i % Utils.COLORS.length])); columns.add(new Column(values).setHasLabelsOnlyForSelected(true)); calMonths.add(Calendar.MONTH, 1); }//from w w w . j a v a 2 s .co m ColumnChartData columnData = new ColumnChartData(columns); columnData.setAxisXBottom(new Axis(axisValues).setHasLines(true).setTextColor(Color.BLACK)); chartBottom.setColumnChartData(columnData); chartBottom.setValueSelectionEnabled(true); chartBottom.setZoomEnabled(false); chartBottom.selectValue(new SelectedValue(calLastSelected.get(Calendar.MONTH), 0, 0)); generateLineData(calLastSelected); }
From source file:fi.vm.sade.organisaatio.business.impl.OrganisaatioTarjonta.java
/** * Tarkistaa onko annetulla organisaatiolla alkavia koulutuksia annetun * pivmrn jlkeen.//from w ww.j av a2 s .c o m * HUOM! Vain "KOPIOITU", "VALMIS", "LUONNOS" ja "JULKAISTU" tilaiset * alkavat koulutukset huomioidaan. * * @param oid * @param after * @return Boolean, joka kertoo onko alkavia koulutuksia vai ei. */ public boolean alkaviaKoulutuksia(String oid, Date after) { List<KoulutusHakutulosV1RDTO> koulutukset = haeKoulutukset(oid); // Ei alkavia koulutuksia tai after == null if (koulutukset.isEmpty() || after == null) { return false; } // Tarkistetaan onko alkavia koulutuksia annetun pivmrn jlkeen for (KoulutusHakutulosV1RDTO koulutus : koulutukset) { Date koulutuksenAlkamisPvmMax = koulutus.getKoulutuksenAlkamisPvmMax(); if (koulutuksenAlkamisPvmMax == null) { LOG.info("Missing 'kausi' (koulutuksenAlkamisPvmMax == null) for koulutus: " + koulutus.getOid()); Integer vuosi = koulutus.getVuosi(); if (vuosi == null) { // Koulutukselta puuttuu kausi ja vuosi --> "valmistava hakukohde" // eli se on sidottu johonkin toiseen koulutukseen. Ei est esim. // organisaation lakkauttamista. LOG.info("Missing 'kausi' and 'vuosi' for koulutus: " + koulutus.getOid()); continue; } else { Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, vuosi + 1); cal.set(Calendar.MONTH, Calendar.JANUARY); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); cal.add(Calendar.MILLISECOND, -1); koulutuksenAlkamisPvmMax = cal.getTime(); LOG.debug("oli vuosi, kytetn aikaa " + koulutuksenAlkamisPvmMax); } } if (koulutuksenAlkamisPvmMax.after(after) && (koulutus.getTila() == TarjontaTila.JULKAISTU || koulutus.getTila() == TarjontaTila.KOPIOITU || koulutus.getTila() == TarjontaTila.VALMIS || koulutus.getTila() == TarjontaTila.LUONNOS)) { return true; } } // Ei alkavia koulutuksia annetun pivmrn jlkeen return false; }
From source file:org.eobjects.datacleaner.monitor.server.SchedulingServiceImplTest.java
public void testToCronExpressionYearly() throws Exception { CronExpression dailyExpr = SchedulingServiceImpl.toCronExpression("@yearly"); Calendar cal = Calendar.getInstance(); cal.set(Calendar.MILLISECOND, 0); cal.set(Calendar.SECOND, 0);//w w w .j ava 2s . c o m cal.set(Calendar.MINUTE, 0); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.DATE, 1); cal.set(Calendar.MONTH, Calendar.JANUARY); cal.add(Calendar.YEAR, 1); assertEquals(cal.getTime(), dailyExpr.getNextValidTimeAfter(new Date())); }