Example usage for java.util GregorianCalendar getTime

List of usage examples for java.util GregorianCalendar getTime

Introduction

In this page you can find the example usage for java.util GregorianCalendar getTime.

Prototype

public final Date getTime() 

Source Link

Document

Returns a Date object representing this Calendar's time value (millisecond offset from the Epoch").

Usage

From source file:MainClass.java

public static void main(String[] args) throws ParseException {
    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
    GregorianCalendar gc = new GregorianCalendar();
    java.util.Date d = sdf.parse("12/12/2003");
    gc.setTime(d);/* w w  w .  j  a v a 2 s .c om*/
    System.out.println("Input Date = " + sdf.format(d));
    int dayBefore = gc.get(Calendar.DAY_OF_YEAR);
    gc.roll(Calendar.DAY_OF_YEAR, -1);
    int dayAfter = gc.get(Calendar.DAY_OF_YEAR);
    if (dayAfter > dayBefore) {
        gc.roll(Calendar.YEAR, -1);
    }
    gc.get(Calendar.DATE);
    java.util.Date yesterday = gc.getTime();
    System.out.println("Yesterdays Date = " + sdf.format(yesterday));

}

From source file:org.dspace.checker.DailyReportEmailer.java

/**
 * Allows users to have email sent to them. The default is to send all
 * reports in one email/*from w w w .ja v a  2s.  c o m*/
 * 
 * @param args
 *            <dl>
 *            <dt>-h</dt>
 *            <dd>help</dd>
 *            <dt>-d</dt>
 *            <dd>Select deleted bitstreams</dd>
 *            <dt>-m</dt>
 *            <dd>Bitstreams missing from assetstore</dd>
 *            <dt>-c</dt>
 *            <dd>Bitstreams whose checksums were changed</dd>
 *            <dt>-n</dt>
 *            <dd>Bitstreams whose checksums were changed</dd>
 *            <dt>-a</dt>
 *            <dd>Send all reports in one email</dd>
 *            </dl>
 * 
 */
public static void main(String[] args) {
    // set up command line parser
    CommandLineParser parser = new PosixParser();
    CommandLine line = null;

    // create an options object and populate it
    Options options = new Options();

    options.addOption("h", "help", false, "Help");
    options.addOption("d", "Deleted", false, "Send E-mail report for all bitstreams set as deleted for today");
    options.addOption("m", "Missing", false,
            "Send E-mail report for all bitstreams not found in assetstore for today");
    options.addOption("c", "Changed", false,
            "Send E-mail report for all bitstreams where checksum has been changed for today");
    options.addOption("a", "All", false, "Send all E-mail reports");

    options.addOption("u", "Unchecked", false, "Send the Unchecked bitstream report");

    options.addOption("n", "Not Processed", false,
            "Send E-mail report for all bitstreams set to longer be processed for today");

    try {
        line = parser.parse(options, args);
    } catch (ParseException e) {
        log.fatal(e);
        System.exit(1);
    }

    // user asks for help
    if (line.hasOption('h')) {
        HelpFormatter myhelp = new HelpFormatter();

        myhelp.printHelp("Checksum Reporter\n", options);
        System.out.println("\nSend Deleted bitstream email report: DailyReportEmailer -d");
        System.out.println("\nSend Missing bitstreams email report: DailyReportEmailer -m");
        System.out.println("\nSend Checksum Changed email report: DailyReportEmailer -c");

        System.out.println("\nSend bitstream not to be processed email report: DailyReportEmailer -n");

        System.out.println("\nSend Un-checked bitstream report: DailyReportEmailer -u");

        System.out.println("\nSend All email reports: DailyReportEmailer");
        System.exit(0);
    }

    // create a new simple reporter
    SimpleReporter reporter = new SimpleReporterImpl();

    DailyReportEmailer emailer = new DailyReportEmailer();

    // get dates for yesterday and tomorrow
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.add(GregorianCalendar.DAY_OF_YEAR, -1);

    Date yesterday = calendar.getTime();
    calendar.add(GregorianCalendar.DAY_OF_YEAR, 2);

    Date tomorrow = calendar.getTime();

    File report = null;
    FileWriter writer = null;

    try {
        // the number of bitstreams in report
        int numBitstreams = 0;

        // create a temporary file in the log directory
        String dirLocation = ConfigurationManager.getProperty("log.dir");
        File directory = new File(dirLocation);

        if (directory.exists() && directory.isDirectory()) {
            report = File.createTempFile("checker_report", ".txt", directory);
        } else {
            throw new IllegalStateException("directory :" + dirLocation + " does not exist");
        }

        writer = new FileWriter(report);

        if ((line.hasOption("a")) || (line.getOptions().length == 0)) {
            writer.write("\n--------------------------------- Begin Reporting ------------------------\n\n");
            numBitstreams += reporter.getDeletedBitstreamReport(yesterday, tomorrow, writer);
            writer.write("\n--------------------------------- Report Spacer ---------------------------\n\n");
            numBitstreams += reporter.getChangedChecksumReport(yesterday, tomorrow, writer);
            writer.write("\n--------------------------------- Report Spacer ---------------------------\n\n");
            numBitstreams += reporter.getBitstreamNotFoundReport(yesterday, tomorrow, writer);
            writer.write("\n--------------------------------- Report Spacer ---------------------------\n\n");
            numBitstreams += reporter.getNotToBeProcessedReport(yesterday, tomorrow, writer);
            writer.write("\n--------------------------------- Report Spacer ---------------------------\n\n");
            numBitstreams += reporter.getUncheckedBitstreamsReport(writer);
            writer.write("\n--------------------------------- End Report ---------------------------\n\n");
            writer.flush();
            writer.close();
            emailer.sendReport(report, numBitstreams);
        } else {
            if (line.hasOption("d")) {
                writer.write(
                        "\n--------------------------------- Begin Reporting ------------------------\n\n");
                numBitstreams += reporter.getDeletedBitstreamReport(yesterday, tomorrow, writer);
                writer.flush();
                writer.close();
                emailer.sendReport(report, numBitstreams);
            }

            if (line.hasOption("m")) {
                writer.write(
                        "\n--------------------------------- Begin Reporting ------------------------\n\n");
                numBitstreams += reporter.getBitstreamNotFoundReport(yesterday, tomorrow, writer);
                writer.flush();
                writer.close();
                emailer.sendReport(report, numBitstreams);
            }

            if (line.hasOption("c")) {
                writer.write(
                        "\n--------------------------------- Begin Reporting ------------------------\n\n");
                numBitstreams += reporter.getChangedChecksumReport(yesterday, tomorrow, writer);
                writer.flush();
                writer.close();
                emailer.sendReport(report, numBitstreams);
            }

            if (line.hasOption("n")) {
                writer.write(
                        "\n--------------------------------- Begin Reporting ------------------------\n\n");
                numBitstreams += reporter.getNotToBeProcessedReport(yesterday, tomorrow, writer);
                writer.flush();
                writer.close();
                emailer.sendReport(report, numBitstreams);
            }

            if (line.hasOption("u")) {
                writer.write(
                        "\n--------------------------------- Begin Reporting ------------------------\n\n");
                numBitstreams += reporter.getUncheckedBitstreamsReport(writer);
                writer.flush();
                writer.close();
                emailer.sendReport(report, numBitstreams);
            }
        }
    } catch (MessagingException e) {
        log.fatal(e);
    } catch (IOException e) {
        log.fatal(e);
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (Exception e) {
                log.fatal("Could not close writer", e);
            }
        }

        if (report != null && report.exists()) {
            if (!report.delete()) {
                log.error("Unable to delete report file");
            }
        }
    }
}

From source file:au.com.jwatmuff.eventmanager.Main.java

/**
 * Main method./*from  www  .ja v a  2 s  .c o 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);
    }
}

From source file:RelativeDateFormat.java

/**
 * Some test code./*from  w ww. j a  v  a 2 s. c o  m*/
 *
 * @param args  ignored.
 */
public static void main(String[] args) {
    GregorianCalendar c0 = new GregorianCalendar(2006, 10, 1, 0, 0, 0);
    GregorianCalendar c1 = new GregorianCalendar(2006, 10, 1, 11, 37, 43);
    c1.set(Calendar.MILLISECOND, 123);

    System.out.println("Default: ");
    RelativeDateFormat rdf = new RelativeDateFormat(c0.getTime().getTime());
    System.out.println(rdf.format(c1.getTime()));
    System.out.println();

    System.out.println("Hide milliseconds: ");
    rdf.setSecondFormatter(new DecimalFormat("0"));
    System.out.println(rdf.format(c1.getTime()));
    System.out.println();

    System.out.println("Show zero day output: ");
    rdf.setShowZeroDays(true);
    System.out.println(rdf.format(c1.getTime()));
    System.out.println();

    System.out.println("Alternative suffixes: ");
    rdf.setShowZeroDays(false);
    rdf.setDaySuffix(":");
    rdf.setHourSuffix(":");
    rdf.setMinuteSuffix(":");
    rdf.setSecondSuffix("");
    System.out.println(rdf.format(c1.getTime()));
    System.out.println();
}

From source file:io.pcp.parfait.dxm.PcpMmvWriter.java

public static void main(String[] args) throws IOException {
    PcpMmvWriter bridge;/*w w  w . j  a  v  a2 s. c  o m*/

    if (args.length == 0) {
        // use $PCP_PMDAS_DIR/mmv/mmvdump (no args) as diagnostic tool
        bridge = new PcpMmvWriter("test", IdentifierSourceSet.DEFAULT_SET);
    } else {
        bridge = new PcpMmvWriter(new File(args[0]), IdentifierSourceSet.DEFAULT_SET);
    }

    // Automatically uses default int handler
    bridge.addMetric(MetricName.parse("sheep[baabaablack].bagsfull.count"), Semantics.COUNTER,
            ONE.multiply(1000), 3);

    // Automatically uses default boolean-to-int handler
    bridge.addMetric(MetricName.parse("sheep[baabaablack].bagsfull.haveany"), Semantics.INSTANT, null,
            new AtomicBoolean(true));
    bridge.addMetric(MetricName.parse("sheep[limpy].bagsfull.haveany"), Semantics.INSTANT, null,
            new AtomicBoolean(false));

    // Automatically uses default long handler
    bridge.addMetric(MetricName.parse("sheep[insomniac].jumps"), Semantics.COUNTER, ONE, 12345678901234L);

    // Automatically uses default double handler
    bridge.addMetric(MetricName.parse("sheep[limpy].legs.available"), Semantics.DISCRETE, ONE, 0.75);

    // Uses this class' custom String handler
    bridge.addMetric(MetricName.parse("sheep[limpy].jumpitem"), Semantics.DISCRETE, null, "fence");

    // addMetric(GregorianCalendar) would fail, as there's no handler registered by default for
    // GregorianCalendars; use a custom one which puts the year as an int
    bridge.addMetric(MetricName.parse("sheep[insomniac].lastjumped"), Semantics.INSTANT, null,
            new GregorianCalendar(), new AbstractTypeHandler<GregorianCalendar>(MmvMetricType.I32, 4) {
                public void putBytes(ByteBuffer buffer, GregorianCalendar value) {
                    buffer.putInt(value.get(GregorianCalendar.YEAR));
                }
            });

    // addMetric(Date) would fail, as there's no handler registered; register one for all date
    // types from now on
    bridge.registerType(Date.class, new AbstractTypeHandler<Date>(MmvMetricType.I64, 8) {
        public void putBytes(ByteBuffer buffer, Date value) {
            buffer.putLong(value.getTime());
        }
    });
    // These will both use the handler we just registered
    bridge.addMetric(MetricName.parse("cow.how.now"), Semantics.INSTANT, null, new Date());
    bridge.addMetric(MetricName.parse("cow.how.then"), Semantics.INSTANT, null,
            new GregorianCalendar(1990, 1, 1, 12, 34, 56).getTime());

    // Uses units
    bridge.addMetric(MetricName.parse("cow.bytes.total"), Semantics.COUNTER, BYTE, 10000001);
    bridge.addMetric(MetricName.parse("cow.bytes.rate"), Semantics.INSTANT, BYTE.multiply(1024).divide(SECOND),
            new Date());
    bridge.addMetric(MetricName.parse("cow.bytes.chewtime"), Semantics.INSTANT, HOUR.divide(BYTE), 7);
    bridge.addMetric(MetricName.parse("cow.bytes.jawmotion"), Semantics.INSTANT, KILO(HERTZ), 0.5);

    // Set up some help text
    bridge.setInstanceDomainHelpText("sheep", "sheep in the paddock",
            "List of all the sheep in the paddock. Includes 'baabaablack', 'insomniac' (who likes to jump fences), and 'limpy' the three-legged wonder sheep.");
    bridge.setMetricHelpText("sheep.jumps", "# of jumps done",
            "Number of times the sheep has jumped over its jumpitem");

    // All the metrics are added; write the file
    bridge.start();
    // Metrics are visible to the agent from this point on

    // Sold a bag! Better update the count
    bridge.updateMetric(MetricName.parse("sheep[baabaablack].bagsfull.count"), 2);
    // The fence broke! Need something new to jump over
    bridge.updateMetric(MetricName.parse("sheep[limpy].jumpitem"), "Honda Civic");
    // Values will be reflected in the agent immediately
}

From source file:com.zimbra.cs.mailbox.calendar.ZRecur.java

public static void main(String[] args) {
    ICalTimeZone tzUTC = ICalTimeZone.getUTC();
    TimeZoneMap tzmap = new TimeZoneMap(tzUTC);
    ParsedDateTime dtStart = null;//from  w ww .j a va2 s. c  om
    try {
        dtStart = ParsedDateTime.parse("20050101T123456", tzmap, tzUTC, tzUTC);
    } catch (ParseException e) {
        System.out.println("Caught ParseException at start: " + e);
    }

    Date rangeStart;
    Date rangeEnd;

    GregorianCalendar cal = new GregorianCalendar();
    cal.clear();
    cal.setTimeZone(tzUTC);

    cal.set(2005, 4, 15, 0, 0, 0);
    rangeStart = cal.getTime();

    cal.set(2006, 0, 1, 0, 0, 0);
    rangeEnd = cal.getTime();

    try {
        ZRecur test = new ZRecur("FREQ=DAILY;BYMONTH=5,6", tzmap);
        System.out.println("\n\n" + test.toString() + "\n-------------------------------------------------");
        List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime());
        for (Date d : dateList) {
            cal.setTime(d);
            cal.setTimeZone(tzUTC);
            System.out.printf("%tc\n", cal);
        }
    } catch (ServiceException e) {
        System.out.println("Caught ServiceException" + e);
        e.printStackTrace();
    }

    try {
        ZRecur test = new ZRecur("FREQ=DAILY;BYMONTH=5,6;BYDAY=TH,-1MO", tzmap);
        System.out.println("\n\n" + test.toString() + "\n-------------------------------------------------");
        List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime());
        for (Date d : dateList) {
            cal.setTime(d);
            cal.setTimeZone(tzUTC);
            System.out.printf("%tc\n", cal);
        }
    } catch (ServiceException e) {
        System.out.println("Caught ServiceException" + e);
        e.printStackTrace();
    }

    try {
        ZRecur test = new ZRecur("FREQ=DAILY;BYMONTH=5,6;BYMONTHDAY=1,3,5,7,9,31", tzmap);
        System.out.println("\n\n" + test.toString() + "\n-------------------------------------------------");
        List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime());
        for (Date d : dateList) {
            cal.setTime(d);
            System.out.printf("%tc\n", cal);
        }
    } catch (ServiceException e) {
        System.out.println("Caught ServiceException" + e);
        e.printStackTrace();
    }

    try {
        ZRecur test = new ZRecur("FREQ=DAILY;BYMONTH=5,6;BYMONTHDAY=1,3,5,7,9,31;BYDAY=SU,SA", tzmap);
        System.out.println(
                "\n\n" + test.toString() + "\n--------------------------------------------------------------");
        List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime());
        for (Date d : dateList) {
            cal.setTime(d);
            System.out.printf("%tc\n", cal);
        }
    } catch (ServiceException e) {
        System.out.println("Caught ServiceException" + e);
        e.printStackTrace();
    }

    try {
        ZRecur test = new ZRecur("FREQ=DAILY;BYMONTH=5,6;BYMONTHDAY=1,3,5,7,9,31;BYDAY=SU,SA;BYHOUR=21,0",
                tzmap);
        System.out.println(
                "\n\n" + test.toString() + "\n--------------------------------------------------------------");
        List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime());
        for (Date d : dateList) {
            cal.setTime(d);
            System.out.printf("%tc\n", cal);
        }
    } catch (ServiceException e) {
        System.out.println("Caught ServiceException" + e);
        e.printStackTrace();
    }

    try {
        ZRecur test = new ZRecur(
                "FREQ=DAILY;BYMONTH=5,6;BYMONTHDAY=1,3,5,7,9,31;BYDAY=SU;BYHOUR=21,0;BYMINUTE=23", tzmap);
        System.out.println(
                "\n\n" + test.toString() + "\n--------------------------------------------------------------");
        List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime());
        for (Date d : dateList) {
            cal.setTime(d);
            System.out.printf("%tc\n", cal);
        }
    } catch (ServiceException e) {
        System.out.println("Caught ServiceException" + e);
        e.printStackTrace();
    }

    try {
        ZRecur test = new ZRecur(
                "FREQ=DAILY;BYMONTH=5,6;BYMONTHDAY=1,3,5,7,9,31;BYDAY=SU;BYHOUR=1,21,0;BYSECOND=0,59", tzmap);
        System.out.println(
                "\n\n" + test.toString() + "\n--------------------------------------------------------------");
        List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime());
        for (Date d : dateList) {
            cal.setTime(d);
            System.out.printf("%tc\n", cal);
        }
    } catch (ServiceException e) {
        System.out.println("Caught ServiceException" + e);
        e.printStackTrace();
    }

    try {
        // parse error testing
        ZRecur test = new ZRecur(
                "FREQ=DAILY;BIYMONTH=5,6;BYMONTHDAY=1,3,5,7,9,31;BYDAY=SU;BYHOUR=1,21,0;BYSECOND=0,59;BYSETPOS=1,-1,3,1000,,-1000",
                tzmap);
        System.out.println(
                "\n\n" + test.toString() + "\n--------------------------------------------------------------");
        List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime());
        for (Date d : dateList) {
            cal.setTime(d);
            System.out.printf("%tc\n", cal);
        }
    } catch (ServiceException e) {
        System.out.println("Caught ServiceException" + e);
        e.printStackTrace();
    }

    try {
        ZRecur test = new ZRecur("FREQ=HOURLY;BIYMONTH=6;BYMONTHDAY=1,3;BYHOUR=2,14", tzmap);
        System.out.println(
                "\n\n" + test.toString() + "\n--------------------------------------------------------------");
        List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime());
        for (Date d : dateList) {
            cal.setTime(d);
            System.out.printf("%tc\n", cal);
        }
    } catch (ServiceException e) {
        System.out.println("Caught ServiceException" + e);
        e.printStackTrace();
    }

    try {
        ZRecur test = new ZRecur("FREQ=HOURLY;BIYMONTH=6;BYMONTHDAY=1;;BYMINUTE=10;BYSECOND=11,12", tzmap);
        System.out.println(
                "\n\n" + test.toString() + "\n--------------------------------------------------------------");
        List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime());
        for (Date d : dateList) {
            cal.setTime(d);
            System.out.printf("%tc\n", cal);
        }
    } catch (ServiceException e) {
        System.out.println("Caught ServiceException" + e);
        e.printStackTrace();
    }

    cal.set(2010, 0, 1, 0, 0, 0);
    rangeEnd = cal.getTime();

    try {
        ZRecur test = new ZRecur("FREQ=YEARLY", tzmap);
        System.out.println(
                "\n\n" + test.toString() + "\n--------------------------------------------------------------");
        List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime());
        for (Date d : dateList) {
            cal.setTime(d);
            System.out.printf("%tc\n", cal);
        }
    } catch (ServiceException e) {
        System.out.println("Caught ServiceException" + e);
        e.printStackTrace();
    }

    try {
        ZRecur test = new ZRecur("FREQ=YEARLY;BYYEARDAY=-1", tzmap);
        System.out.println(
                "\n\n" + test.toString() + "\n--------------------------------------------------------------");
        List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime());
        for (Date d : dateList) {
            cal.setTime(d);
            System.out.printf("%tc\n", cal);
        }
    } catch (ServiceException e) {
        System.out.println("Caught ServiceException" + e);
        e.printStackTrace();
    }

    try {
        ZRecur test = new ZRecur("FREQ=SECONDLY", tzmap);
        System.out.println(
                "\n\n" + test.toString() + "\n--------------------------------------------------------------");
        List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime());
        for (Date d : dateList) {
            cal.setTime(d);
            System.out.printf("%tc\n", cal);
        }
    } catch (ServiceException e) {
        System.out.println("Caught ServiceException" + e);
        e.printStackTrace();
    }

    try {
        ParsedDateTime myDtStart = ParsedDateTime.parse("16010101T020000", tzmap, tzUTC, tzUTC);
        ZRecur test = new ZRecur("FREQ=YEARLY;WKST=MO;INTERVAL=1;BYMONTH=12;BYDAY=-1SU", tzmap);
        System.out.println(
                "\n\n" + test.toString() + "\n--------------------------------------------------------------");
        List<Date> dateList = test.expandRecurrenceOverRange(myDtStart, rangeStart.getTime(),
                rangeEnd.getTime());
        for (Date d : dateList) {
            cal.setTime(d);
            System.out.printf("%tc\n", cal);
        }
    } catch (ParseException e) {
        System.out.println("Caught ParseException" + e);
        e.printStackTrace();
    } catch (ServiceException e) {
        System.out.println("Caught ServiceException" + e);
        e.printStackTrace();
    }

    cal.set(2010, 0, 1, 0, 0, 0);
    rangeEnd = cal.getTime();

    try {
        ZRecur test = new ZRecur("FREQ=YEARLY;BYMONTH=12;BYDAY=1WE", tzmap);
        System.out.println(
                "\n\n" + test.toString() + "\n--------------------------------------------------------------");
        List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime());
        for (Date d : dateList) {
            cal.setTime(d);
            System.out.printf("%tc\n", cal);
        }
    } catch (ServiceException e) {
        System.out.println("Caught ServiceException" + e);
        e.printStackTrace();
    }

}

From source file:Main.java

public static Date gregorian2Date(GregorianCalendar gc) {
    return gc.getTime();
}

From source file:Main.java

public static String getYear(GregorianCalendar cal) {
    return dfYear.format(cal.getTime());
}

From source file:Main.java

public static String getMese(GregorianCalendar cal) {
    return dfMese.format(cal.getTime());
}

From source file:Main.java

public static String getMeseN(GregorianCalendar cal) {
    return dfMeseN.format(cal.getTime());
}