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:Main.java
public static int getDaysInMonth(int month, int year) { switch (month) { case Calendar.JANUARY: case Calendar.MARCH: case Calendar.MAY: case Calendar.JULY: case Calendar.AUGUST: case Calendar.OCTOBER: case Calendar.DECEMBER: return 31; case Calendar.APRIL: case Calendar.JUNE: case Calendar.SEPTEMBER: case Calendar.NOVEMBER: return 30; case Calendar.FEBRUARY: return ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) ? 28 : 29; default:/*from ww w . j a va 2 s. c o m*/ throw new IllegalArgumentException("Invalid Month"); } }
From source file:org.hibersap.util.DateUtil.java
public static Date stripDate(final Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date);//from ww w . j a v a 2s. c o m cal.set(1970, Calendar.JANUARY, 1); return cal.getTime(); }
From source file:Main.java
/** * Get a set of holidays for a given year. * * @param year/* w w w. j a v a 2s. c om*/ * The year to get holidays for. * @return The set of dates. */ private static Set<Date> getHolidaySet(int year) { if (holidays == null) { holidays = new HashMap<Integer, Set<Date>>(); } if (!holidays.containsKey(year)) { Set<Date> yearSet = new HashSet<Date>(); // Add set holidays. yearSet.add(getDate(1, Calendar.JANUARY, year)); yearSet.add(getDate(1, Calendar.MAY, year)); yearSet.add(getDate(17, Calendar.MAY, year)); yearSet.add(getDate(25, Calendar.DECEMBER, year)); yearSet.add(getDate(26, Calendar.DECEMBER, year)); // Add movable holidays - based on easter day. Calendar easterDay = dateToCalendar(getEasterDay(year)); // Sunday before easter. yearSet.add(rollGetDate(easterDay, -7)); // Thurday before easter. yearSet.add(rollGetDate(easterDay, -3)); // Friday before easter. yearSet.add(rollGetDate(easterDay, -2)); // Easter day. yearSet.add(easterDay.getTime()); // Second easter day. yearSet.add(rollGetDate(easterDay, 1)); // "Kristi himmelfart" day. yearSet.add(rollGetDate(easterDay, 39)); // "Pinse" day. yearSet.add(rollGetDate(easterDay, 49)); // Second "Pinse" day. yearSet.add(rollGetDate(easterDay, 50)); holidays.put(year, yearSet); } return holidays.get(year); }
From source file:org.jiemamy.utils.DateUtil.java
/** * {@link java.util.Date}{@link java.sql.Time}??? * // ww w . ja v a 2 s. c o m * @param date {@link java.util.Date} * @return {@link java.sql.Time} * @throws IllegalArgumentException ?{@code null}??? */ public static java.sql.Time toSqlTime(java.util.Date date) { Validate.notNull(date); Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.set(Calendar.YEAR, UNIX_EPOCH); cal.set(Calendar.MONTH, Calendar.JANUARY); cal.set(Calendar.DATE, 1); return new java.sql.Time(cal.getTimeInMillis()); }
From source file:name.martingeisse.common.util.Month.java
/** * @param value the constant used in {@link GregorianCalendar} * @return the corresponding month/*from www .jav a 2 s . co m*/ */ public static Month fromGregorianCalendarValue(int value) { if (value < Calendar.JANUARY || value > Calendar.DECEMBER) { throw new IllegalArgumentException("invalid argument value: " + value); } return values()[value - Calendar.JANUARY]; }
From source file:ch.wscr.management.WscrManagementApplicationTests.java
@Test public void storeMemberTest() { Member memberToSave = new Member(); memberToSave.setFirstName("Marco"); memberToSave.setLastName("Nitschke"); memberToSave.setBirthDate(new Date(new GregorianCalendar(1977, Calendar.JANUARY, 20).getTimeInMillis())); memberToSave.setAdrStreet("Rilkeweg 9"); memberToSave.setAdrPostalCode("70771"); memberToSave.setAdrCity("Echterdingen"); memberToSave.setDriverLicense(true); memberToSave.setAdrCountry(Country.DE); Member memberSaved = memberRepository.save(memberToSave); assertThat(memberSaved.getMemberId(), is(1)); }
From source file:org.lieuofs.extraction.commune.ExtractionGeTax.java
public void extraire() throws IOException { CommuneCritere critere = new CommuneCritere(); Calendar cal = Calendar.getInstance(); cal.set(2012, Calendar.JANUARY, 1); critere.setDateValiditeApres(cal.getTime()); cal.set(2012, Calendar.DECEMBER, 31); critere.setDateValiditeAvant(cal.getTime()); List<ICommuneSuisse> communes = gestionnaire.rechercher(critere); Collections.sort(communes, new Comparator<ICommuneSuisse>() { @Override/*from ww w. j a va2 s . c o m*/ public int compare(ICommuneSuisse o1, ICommuneSuisse o2) { return o1.getNumeroOFS() - o2.getNumeroOFS(); } }); // Attention, le fichier est une iste historise des communes. // Une commune peut donc figurer 2 fois dans le fichier Set<Integer> numOFS = new HashSet<Integer>(3000); int nbreCommune = 0; BufferedWriter writer = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(new File("ExtractionCommuneGETaX2012.csv")), Charset.forName("ISO8859-1"))); for (ICommuneSuisse commune : communes) { if (!numOFS.contains(commune.getNumeroOFS())) { nbreCommune++; numOFS.add(commune.getNumeroOFS()); writer.write(String.valueOf(commune.getNumeroOFS())); writer.write(";"); writer.write(commune.getNomCourt()); writer.write(";"); writer.write(commune.getCanton().getCodeIso2()); writer.newLine(); System.out.println(commune.getNumeroOFS() + " " + commune.getNomCourt()); } } writer.close(); System.out.println("Nbre commune : " + nbreCommune); }
From source file:org.jasig.schedassist.impl.relationship.advising.TermCalculator.java
/** * Calculate the term number for the specified date time (as a {@link Calendar}). * This uses a rough formula to determine Fall/Spring/Summer semesters: <pre>/* w ww .jav a2 s. c o m*/ if the month is between January and May (inclusive), the term is Spring. if the month is between June and August (inclusive), the term is Summer. if the month is between September and December (inclusive), the term is Fall. </pre> * * This is only approximate. * * @param calendar * @return */ public static String calculateTerm(final Calendar calendar) { StringBuilder term = new StringBuilder(); int month = calendar.get(Calendar.MONTH); String monthDigit; if (month >= Calendar.JANUARY && month <= Calendar.MAY) { monthDigit = "4"; } else if (month >= Calendar.JUNE && month <= Calendar.AUGUST) { monthDigit = "6"; } else { monthDigit = "2"; } int year = calendar.get(Calendar.YEAR); if ("2".equals(monthDigit)) { // increment year by one for fall semester year++; } String centuryDigit = "0"; if (year >= 2000) { centuryDigit = "1"; } int twoDigitYear = year % 100; String yearDigit = StringUtils.leftPad(Integer.toString(twoDigitYear), 2, "0"); term.append(centuryDigit); term.append(yearDigit); term.append(monthDigit); return term.toString(); }
From source file:ru.retbansk.utils.marshaller.Jaxb2MarshallerTest.java
@BeforeClass public static void beforeClass() { TaskReport taskReport = new TaskReport(); Date date = new Date(); Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT")); calendar.clear();/*from w w w .ja va 2 s. com*/ calendar.set(Calendar.DATE, 1); calendar.set(Calendar.MONTH, Calendar.JANUARY); calendar.set(Calendar.YEAR, 1981); date = calendar.getTime(); taskReport.setDate(date); taskReport.setElapsedTime(4); taskReport.setStatus(STATUS); taskReport.setWorkDescription(WORK_DESCRIPTION); list = new ArrayList<TaskReport>(); list.add(taskReport); }
From source file:ch.silviowangler.dox.LoadIntegrationTest.java
@Before public void setUp() throws Exception { loginAsTestRoot();/* w ww .j a v a 2s . c o m*/ Calendar calendar = new GregorianCalendar(2013, Calendar.JANUARY, 1); Map<String, SortedSet<Attribute>> cache = new HashMap<>(); for (int i = 1; i <= TOTAL_AMOUNT_OF_FILES; i++) { Map<TranslatableKey, DescriptiveIndex> indices = new HashMap<>(); SortedSet<Attribute> attributes; if (!cache.containsKey("INVOICE")) { attributes = documentService.findAttributes(new DocumentClass("INVOICE")); cache.put("INVOICE", attributes); } else { attributes = cache.get("INVOICE"); } for (Attribute attribute : attributes) { if (!attribute.isOptional()) { Object o; switch (attribute.getDataType()) { case SHORT: case LONG: case DOUBLE: case STRING: case INTEGER: o = Integer.toString(i); break; case BOOLEAN: o = (i % 2 == 0); break; case DATE: calendar.add(Calendar.DAY_OF_YEAR, 1); o = calendar.getTime(); break; case CURRENCY: o = "CHF " + i; break; default: throw new IllegalArgumentException("Unknown attribute type: " + attribute.getDataType()); } indices.put(new TranslatableKey(attribute.getShortName()), new DescriptiveIndex(o)); } } importFile(i + ".txt", Integer.toString(i), "INVOICE", indices); } loginAsTestRoot(); }