List of usage examples for java.util Calendar DECEMBER
int DECEMBER
To view the source code for java.util Calendar DECEMBER.
Click Source Link
From source file:name.martingeisse.common.util.Month.java
/** * @param value the constant used in {@link GregorianCalendar} * @return the corresponding month/*from ww w. j a v a2s .c o 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:Main.java
/** * Get a set of holidays for a given year. * * @param year//from ww w.ja v a 2 s . c o m * 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.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 w w w . j a v a2 s . c om*/ 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:net.audumla.astronomy.SeasonTest.java
@Test public void testWinterStart() throws Exception { SeasonalEvent event = new SeasonalEvent(SeasonalEvent.WINTERSTART, Geolocation.newGeoLocation(30, 0, 0)); Date et = event.calculateEventFrom(new Date()); assert DateUtils.toCalendar(et).get(Calendar.MONTH) == Calendar.DECEMBER; event = new SeasonalEvent(SeasonalEvent.WINTERSTART, Geolocation.newGeoLocation(-30, 0, 0)); et = event.calculateEventFrom(new Date()); assert DateUtils.toCalendar(et).get(Calendar.MONTH) == Calendar.JUNE; }
From source file:org.lieuofs.extraction.etatpays.ExtractionGeTaX.java
public void extraire() throws IOException { EtatCritere critere = new EtatCritere(); Calendar cal = Calendar.getInstance(); cal.set(2012, Calendar.DECEMBER, 31); critere.setReconnuSuisseALaDate(cal.getTime()); Set<IEtat> etats = gestionnaire.rechercher(critere); List<IEtat> listeEtat = new ArrayList<IEtat>(etats); Collections.sort(listeEtat, new Comparator<IEtat>() { @Override//from w w w . j ava 2 s .co m public int compare(IEtat o1, IEtat o2) { return o1.getNumeroOFS() - o2.getNumeroOFS(); } }); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(new File("ExtractionEtatGETaX2012.csv")), Charset.forName("ISO8859-1"))); for (IEtat etat : listeEtat) { writer.write(String.valueOf(etat.getNumeroOFS())); writer.write(";"); writer.write(etat.getFormeCourte("fr")); writer.newLine(); } writer.close(); }
From source file:ch.cyberduck.core.ftp.parser.MicrosoftFTPEntryParserTest.java
@Test public void testParse() throws Exception { FTPFile parsed;// w w w . ja va 2 s. com // #3701 parsed = parser.parseFTPEntry("12-04-06 12:43PM 65335 fon1.kucuk.jpg"); assertNotNull(parsed); assertEquals("fon1.kucuk.jpg", parsed.getName()); assertEquals(FTPFile.FILE_TYPE, parsed.getType()); assertEquals(65335, parsed.getSize()); assertEquals(2006, parsed.getTimestamp().get(Calendar.YEAR)); assertEquals(Calendar.DECEMBER, parsed.getTimestamp().get(Calendar.MONTH)); assertEquals(4, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH)); }
From source file:com.chadekin.jadys.commons.expression.SqlValueFormatterFactoryTest.java
@Test public void shouldFormatDateValue() { // Arrange// w w w . java 2 s. c om Calendar calendar = new GregorianCalendar(2016, Calendar.DECEMBER, 24); Object value = calendar.getTime(); // Act String result = SqlValueFormatterFactory.format(value).build(); // Assert assertThat(result, is("'2016-12-24'")); }
From source file:ch.cyberduck.core.ftp.parser.UnixFTPEntryParserTest.java
@Test public void testParseTimestamp() { FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX"); FTPFile parsed;//from w ww. j av a2s .c o m parsed = parser .parseFTPEntry("drw-rw-rw- 1 user ftp 0 DEC 11 20:56 ADMIN_Documentation"); assertNotNull(parsed); assertNotNull(parsed.getTimestamp()); assertEquals(Calendar.DECEMBER, parsed.getTimestamp().get(Calendar.MONTH)); assertEquals(11, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH)); assertEquals(20, parsed.getTimestamp().get(Calendar.HOUR_OF_DAY)); assertEquals(56, parsed.getTimestamp().get(Calendar.MINUTE)); parsed = parser.parseFTPEntry("drwxr-xr-x 3 ftp ftp 512 Mar 15 2004 doc"); assertNotNull(parsed); assertNotNull(parsed.getTimestamp()); assertEquals(2004, parsed.getTimestamp().get(Calendar.YEAR)); assertEquals(Calendar.MARCH, parsed.getTimestamp().get(Calendar.MONTH)); assertEquals(15, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH)); parsed = parser.parseFTPEntry("drwxrwxr-x 2 ftp ftp 512 Oct 23 2007 aurox"); assertNotNull(parsed); assertNotNull(parsed.getTimestamp()); assertEquals(2007, parsed.getTimestamp().get(Calendar.YEAR)); assertEquals(Calendar.OCTOBER, parsed.getTimestamp().get(Calendar.MONTH)); assertEquals(23, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH)); }
From source file:ch.cyberduck.core.ftp.parser.WebstarFTPEntryParserTest.java
@Test public void testParse() throws Exception { FTPFile parsed;/* w w w. j av a 2s . co m*/ parsed = parser.parseFTPEntry("-rwx------ 17 332 640 Dec 20 08:54 file 1"); assertNotNull(parsed); assertEquals("file 1", parsed.getName()); assertEquals(FTPFile.FILE_TYPE, parsed.getType()); assertEquals(640, parsed.getSize()); parsed = parser.parseFTPEntry("drwx------ folder 2 Dec 20 08:55 folder1"); assertNotNull(parsed); assertEquals("folder1", parsed.getName()); assertEquals(FTPFile.DIRECTORY_TYPE, parsed.getType()); assertEquals(Calendar.DECEMBER, parsed.getTimestamp().get(Calendar.MONTH)); assertEquals(20, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH)); assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION)); assertFalse(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION)); assertFalse(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION)); assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION)); assertFalse(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION)); assertFalse(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION)); assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION)); assertFalse(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION)); assertFalse(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION)); }
From source file:au.com.jwatmuff.eventmanager.Main.java
/** * Main method./*from w w w. j a v a 2 s. co m*/ */ public static void main(String args[]) { LogUtils.setupUncaughtExceptionHandler(); /* Set timeout for RMI connections - TODO: move to external file */ System.setProperty("sun.rmi.transport.tcp.handshakeTimeout", "2000"); updateRmiHostName(); /* * Set up menu bar for Mac */ System.setProperty("apple.laf.useScreenMenuBar", "true"); System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Event Manager"); /* * Set look and feel to 'system' style */ try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { log.info("Failed to set system look and feel"); } /* * Set workingDir to a writable folder for storing competitions, settings etc. */ String applicationData = System.getenv("APPDATA"); if (applicationData != null) { workingDir = new File(applicationData, "EventManager"); if (workingDir.exists() || workingDir.mkdirs()) { // redirect logging to writable folder LogUtils.reconfigureFileAppenders("log4j.properties", workingDir); } else { workingDir = new File("."); } } // log version for debugging log.info("Running version: " + VISIBLE_VERSION + " (Internal: " + VERSION + ")"); /* * Copy license if necessary */ File license1 = new File("license.lic"); File license2 = new File(workingDir, "license.lic"); if (license1.exists() && !license2.exists()) { try { FileUtils.copyFile(license1, license2); } catch (IOException e) { log.warn("Failed to copy license from " + license1 + " to " + license2, e); } } if (license1.exists() && license2.exists()) { if (license1.lastModified() > license2.lastModified()) { try { FileUtils.copyFile(license1, license2); } catch (IOException e) { log.warn("Failed to copy license from " + license1 + " to " + license2, e); } } } /* * Check if run lock exists, if so ask user if it is ok to continue */ if (!obtainRunLock(false)) { int response = JOptionPane.showConfirmDialog(null, "Unable to obtain run-lock.\nPlease ensure that no other instances of EventManager are running before continuing.\nDo you wish to continue?", "Run-lock detected", JOptionPane.YES_NO_OPTION); if (response == JOptionPane.YES_OPTION) obtainRunLock(true); else System.exit(0); } try { LoadWindow loadWindow = new LoadWindow(); loadWindow.setVisible(true); loadWindow.addMessage("Reading settings.."); /* * Read properties from file */ final Properties props = new Properties(); try { Properties defaultProps = PropertiesLoaderUtils .loadProperties(new ClassPathResource("eventmanager.properties")); props.putAll(defaultProps); } catch (IOException ex) { log.error(ex); } props.putAll(System.getProperties()); File databaseStore = new File(workingDir, "comps"); int rmiPort = Integer.parseInt(props.getProperty("eventmanager.rmi.port")); loadWindow.addMessage("Loading Peer Manager.."); log.info("Loading Peer Manager"); ManualDiscoveryService manualDiscoveryService = new ManualDiscoveryService(); JmDNSRMIPeerManager peerManager = new JmDNSRMIPeerManager(rmiPort, new File(workingDir, "peerid.dat")); peerManager.addDiscoveryService(manualDiscoveryService); monitorNetworkInterfaceChanges(peerManager); loadWindow.addMessage("Loading Database Manager.."); log.info("Loading Database Manager"); DatabaseManager databaseManager = new SQLiteDatabaseManager(databaseStore, peerManager); LicenseManager licenseManager = new LicenseManager(workingDir); loadWindow.addMessage("Loading Load Competition Dialog.."); log.info("Loading Load Competition Dialog"); LoadCompetitionWindow loadCompetitionWindow = new LoadCompetitionWindow(databaseManager, licenseManager, peerManager); loadCompetitionWindow.setTitle(WINDOW_TITLE); loadWindow.dispose(); log.info("Starting Load Competition Dialog"); while (true) { // reset permission checker to use our license licenseManager.updatePermissionChecker(); GUIUtils.runModalJFrame(loadCompetitionWindow); if (loadCompetitionWindow.getSuccess()) { DatabaseInfo info = loadCompetitionWindow.getSelectedDatabaseInfo(); if (!databaseManager.checkLock(info.id)) { String message = "EventManager did not shut down correctly the last time this competition was open. To avoid potential data corruption, you are advised to take the following steps:\n" + "1) Do NOT open this competition\n" + "2) Create a backup of this competition\n" + "3) Delete the competition from this computer\n" + "4) If possible, reload this competition from another computer on the network\n" + "5) Alternatively, you may manually load the backup onto all computers on the network, ensuring the 'Preserve competition ID' option is checked."; String title = "WARNING: Potential Data Corruption Detected"; int status = JOptionPane.showOptionDialog(null, message, title, JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE, null, new Object[] { "Cancel (recommended)", "Open anyway" }, "Cancel (recommended)"); if (status == 0) continue; // return to load competition window } SynchronizingWindow syncWindow = new SynchronizingWindow(); syncWindow.setVisible(true); long t = System.nanoTime(); DistributedDatabase database = databaseManager.activateDatabase(info.id, info.passwordHash); long dt = System.nanoTime() - t; log.debug(String.format("Initial sync in %dms", TimeUnit.MILLISECONDS.convert(dt, TimeUnit.NANOSECONDS))); syncWindow.dispose(); if (loadCompetitionWindow.isNewDatabase()) { GregorianCalendar calendar = new GregorianCalendar(); Date today = calendar.getTime(); calendar.set(Calendar.MONTH, Calendar.DECEMBER); calendar.set(Calendar.DAY_OF_MONTH, 31); Date endOfYear = new java.sql.Date(calendar.getTimeInMillis()); CompetitionInfo ci = new CompetitionInfo(); ci.setName(info.name); ci.setStartDate(today); ci.setEndDate(today); ci.setAgeThresholdDate(endOfYear); //ci.setPasswordHash(info.passwordHash); License license = licenseManager.getLicense(); if (license != null) { ci.setLicenseName(license.getName()); ci.setLicenseType(license.getType().toString()); ci.setLicenseContact(license.getContactPhoneNumber()); } database.add(ci); } // Set PermissionChecker to use database's license type String competitionLicenseType = database.get(CompetitionInfo.class, null).getLicenseType(); PermissionChecker.setLicenseType(LicenseType.valueOf(competitionLicenseType)); TransactionNotifier notifier = new TransactionNotifier(); database.setListener(notifier); MainWindow mainWindow = new MainWindow(); mainWindow.setDatabase(database); mainWindow.setNotifier(notifier); mainWindow.setPeerManager(peerManager); mainWindow.setLicenseManager(licenseManager); mainWindow.setManualDiscoveryService(manualDiscoveryService); mainWindow.setTitle(WINDOW_TITLE); mainWindow.afterPropertiesSet(); TestUtil.setActivatedDatabase(database); // show main window (modally) GUIUtils.runModalJFrame(mainWindow); // shutdown procedures // System.exit(); database.shutdown(); databaseManager.deactivateDatabase(1500); if (mainWindow.getDeleteOnExit()) { for (File file : info.localDirectory.listFiles()) if (!file.isDirectory()) file.delete(); info.localDirectory.deleteOnExit(); } } else { // This can cause an RuntimeException - Peer is disconnected peerManager.stop(); System.exit(0); } } } catch (Throwable e) { log.error("Error in main function", e); String message = e.getMessage(); if (message == null) message = ""; if (message.length() > 100) message = message.substring(0, 97) + "..."; GUIUtils.displayError(null, "An unexpected error has occured.\n\n" + e.getClass().getSimpleName() + "\n" + message); System.exit(0); } }