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:org.obm.caldav.obmsync.service.impl.CalendarService.java

private List<DavComponent> getAllLastUpdate(CalDavToken token, String compUrl, DavComponentType componant,
        CompFilter cf) throws Exception {
    Date start = null;//from  w  ww. ja  va 2 s  .c o  m
    Date end = null;

    if (cf.getTimeRange() != null
            && (cf.getTimeRange().getStart() != null || cf.getTimeRange().getEnd() != null)) {
        start = cf.getTimeRange().getStart();
        end = cf.getTimeRange().getEnd();
        if (start == null) {
            GregorianCalendar gc = new GregorianCalendar();
            gc.set(Calendar.YEAR, gc.get(Calendar.YEAR) - 1);
            start = gc.getTime();
        }

        if (end == null) {
            GregorianCalendar gc = new GregorianCalendar();
            gc.set(Calendar.YEAR, gc.get(Calendar.YEAR) + 1);
            end = gc.getTime();
        }
    } else {
        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
        cal.setTimeInMillis(0);
        start = cal.getTime();
        end = null;
    }
    AbstractEventSyncClient obmClient = ObmSyncProviderFactory.getInstance().getClient(componant,
            token.getLoginAtDomain());
    AccessToken obmToken = login(obmClient, token);
    List<EventTimeUpdate> items = new ArrayList<EventTimeUpdate>(0);
    try {
        items = obmClient.getEventTimeUpdateNotRefusedFromIntervalDate(obmToken, token.getCalendarName(), start,
                end);
        for (Iterator<EventTimeUpdate> it = items.iterator(); it.hasNext();) {
            EventTimeUpdate ev = it.next();
            if (ev.getRecurrenceId() != null) {
                it.remove();
            }
        }
    } catch (Exception e) {
        throw new Exception();
    } finally {
        logout(obmClient, obmToken);
    }
    return EventConverter.convert(items, compUrl, componant);
}

From source file:com.datamountaineer.streamreactor.connect.json.SimpleJsonConverterTest.java

@Test
public void timestampToJson() throws IOException {
    GregorianCalendar calendar = new GregorianCalendar(1970, Calendar.JANUARY, 1, 0, 0, 0);
    calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
    calendar.add(Calendar.MILLISECOND, 2000000000);
    calendar.add(Calendar.MILLISECOND, 2000000000);
    java.util.Date date = calendar.getTime();

    JsonNode converted = converter.fromConnectData(Timestamp.SCHEMA, date);
    assertTrue(converted.isLong());//from ww  w  . j a v  a2 s .  c o m
    assertEquals(4000000000L, converted.longValue());
}

From source file:org.openmrs.module.kenyaui.KenyaUiUtilsTest.java

/**
 * @see KenyaUiUtils#formatDate(java.util.Date)
 * @verifies format date as a string without time information
 *//* www.  j a va  2 s .  co m*/
@Test
public void formatDate_shouldFormatDateWithoutTime() throws Exception {
    GregorianCalendar cal = new GregorianCalendar();
    cal.set(Calendar.YEAR, 1981);
    cal.set(Calendar.MONTH, Calendar.MAY);
    cal.set(Calendar.DAY_OF_MONTH, 28);
    cal.set(Calendar.HOUR, 7);
    cal.set(Calendar.MINUTE, 30);
    cal.set(Calendar.SECOND, 12);

    Assert.assertThat(kenyaUi.formatDate(cal.getTime()), is("28-May-1981"));
}

From source file:org.openmrs.module.kenyaui.KenyaUiUtilsTest.java

/**
 * @see KenyaUiUtils#formatDateParam(java.util.Date)
 * @verifies format null date as empty string
 *///from   w ww .  j a v a  2s  .  co m
@Test
public void formatDateParam_shouldFormatDateAsISO8601() throws Exception {
    GregorianCalendar cal = new GregorianCalendar();
    cal.set(Calendar.YEAR, 1981);
    cal.set(Calendar.MONTH, Calendar.MAY);
    cal.set(Calendar.DAY_OF_MONTH, 28);
    cal.set(Calendar.HOUR, 7);
    cal.set(Calendar.MINUTE, 30);
    cal.set(Calendar.SECOND, 12);

    Assert.assertThat(kenyaUi.formatDateParam(cal.getTime()), is("1981-05-28"));
}

From source file:ru.apertum.qsystem.server.model.calendar.CalendarTableModel.java

/**
 *  ? ? /*from  w  ww  . j  a v  a2  s. co  m*/
 * @param year
 */
public void checkSaturday(int year) {
    QLog.l().logger().debug(" ? ?");
    final GregorianCalendar gc = new GregorianCalendar();
    gc.set(GregorianCalendar.YEAR, year);
    final int ye = year % 4 == 0 ? 366 : 365;
    for (int d = 1; d <= ye; d++) {
        gc.set(GregorianCalendar.DAY_OF_YEAR, d);
        if (gc.get(GregorianCalendar.DAY_OF_WEEK) == 7) {
            addDay(gc.getTime(), true);
        }
    }
    fireTableDataChanged();
}

From source file:ru.apertum.qsystem.server.model.calendar.CalendarTableModel.java

/**
 *  ? ??? //www  .  jav  a2  s  .  com
 * @param year
 */
public void checkSunday(int year) {
    QLog.l().logger().debug(" ? ???");
    final GregorianCalendar gc = new GregorianCalendar();
    gc.set(GregorianCalendar.YEAR, year);
    final int ye = year % 4 == 0 ? 366 : 365;
    for (int d = 1; d <= ye; d++) {
        gc.set(GregorianCalendar.DAY_OF_YEAR, d);
        if (gc.get(GregorianCalendar.DAY_OF_WEEK) == 1) {
            addDay(gc.getTime(), true);
        }
    }
    fireTableDataChanged();
}

From source file:org.hyperic.hq.bizapp.server.session.EmailManagerImpl.java

private void scheduleJob(Integer platId) throws SchedulerException {
    // Create new job name with the appId
    String name = EmailFilterJob.class.getName() + platId + "Job";

    Scheduler scheduler = Bootstrap.getBean(Scheduler.class);

    synchronized (SCHEDULER_LOCK) {

        Trigger[] triggers = scheduler.getTriggersOfJob(name, JOB_GROUP);
        if (triggers.length == 0) {
            JobDetail jobDetail = new JobDetail(name, JOB_GROUP, EmailFilterJob.class);

            String appIdStr = platId.toString();

            jobDetail.getJobDataMap().put(EmailFilterJob.APP_ID, appIdStr);

            // XXX: Make this time configurable?
            GregorianCalendar next = new GregorianCalendar();
            next.add(GregorianCalendar.MINUTE, 5);
            SimpleTrigger t = new SimpleTrigger(name + "Trigger", JOB_GROUP, next.getTime());

            Date nextfire = scheduler.scheduleJob(jobDetail, t);
            log.debug("Will queue alerts for platform " + platId + " until " + nextfire);
        } else {/*from  w ww. ja  v  a  2s.  co  m*/
            // Already scheduled, there will only be a single trigger.
            log.debug("Already queing alerts for platform " + platId + ", will fire at "
                    + triggers[0].getNextFireTime());
        }
    }
}

From source file:RolloverFileOutputStream.java

public RolloverFileOutputStream(String filename, boolean append, int retainDays, TimeZone zone)
        throws IOException {
    super(null);/*from  w  w  w  .  j  a va 2s.c  o  m*/

    _fileBackupFormat.setTimeZone(zone);
    _fileDateFormat.setTimeZone(zone);

    if (filename != null) {
        filename = filename.trim();
        if (filename.length() == 0)
            filename = null;
    }
    if (filename == null)
        throw new IllegalArgumentException("Invalid filename");

    _filename = filename;
    _append = append;
    _retainDays = retainDays;
    setFile();

    synchronized (RolloverFileOutputStream.class) {
        if (__rollover == null)
            __rollover = new Timer();

        _rollTask = new RollTask();

        Calendar now = Calendar.getInstance();
        now.setTimeZone(zone);

        GregorianCalendar midnight = new GregorianCalendar(now.get(Calendar.YEAR), now.get(Calendar.MONTH),
                now.get(Calendar.DAY_OF_MONTH), 23, 0);
        midnight.setTimeZone(zone);
        midnight.add(Calendar.HOUR, 1);
        __rollover.scheduleAtFixedRate(_rollTask, midnight.getTime(), 1000L * 60 * 60 * 24);
    }
}

From source file:be.e_contract.eid.applet.service.impl.handler.IdentityDataMessageHandler.java

@Override
public Object handleMessage(IdentityDataMessage message, Map<String, String> httpHeaders,
        HttpServletRequest request, HttpSession session) throws ServletException {
    LOG.debug("handle identity");

    X509Certificate rrnCertificate = getCertificate(message.rrnCertFile);
    X509Certificate rootCertificate = getCertificate(message.rootCertFile);
    List<X509Certificate> rrnCertificateChain = new LinkedList<X509Certificate>();
    rrnCertificateChain.add(rrnCertificate);
    rrnCertificateChain.add(rootCertificate);

    IdentificationEvent identificationEvent = new IdentificationEvent(rrnCertificateChain);
    BeIDContextQualifier contextQualifier = new BeIDContextQualifier(request);
    try {/*  w  ww  .j  a  v a  2 s.co  m*/
        this.identificationEvent.select(contextQualifier).fire(identificationEvent);
    } catch (ExpiredCertificateSecurityException e) {
        return new FinishedMessage(ErrorCode.CERTIFICATE_EXPIRED);
    } catch (RevokedCertificateSecurityException e) {
        return new FinishedMessage(ErrorCode.CERTIFICATE_REVOKED);
    } catch (TrustCertificateSecurityException e) {
        return new FinishedMessage(ErrorCode.CERTIFICATE_NOT_TRUSTED);
    } catch (CertificateSecurityException e) {
        return new FinishedMessage(ErrorCode.CERTIFICATE);
    }
    if (false == identificationEvent.isValid()) {
        SecurityAuditEvent securityAuditEvent = new SecurityAuditEvent(Incident.TRUST, rrnCertificate);
        this.securityAuditEvent.select(contextQualifier).fire(securityAuditEvent);
        throw new SecurityException("invalid national registry certificate chain");
    }

    verifySignature(contextQualifier, rrnCertificate.getSigAlgName(), message.identitySignatureFile,
            rrnCertificate, request, message.idFile);

    Identity identity = TlvParser.parse(message.idFile, Identity.class);

    if (null != message.photoFile) {
        LOG.debug("photo file size: " + message.photoFile.length);
        /*
         * Photo integrity check.
         */
        byte[] expectedPhotoDigest = identity.photoDigest;
        byte[] actualPhotoDigest = digestPhoto(getDigestAlgo(expectedPhotoDigest.length), message.photoFile);
        if (false == Arrays.equals(expectedPhotoDigest, actualPhotoDigest)) {
            SecurityAuditEvent securityAuditEvent = new SecurityAuditEvent(Incident.DATA_INTEGRITY,
                    message.photoFile);
            this.securityAuditEvent.select(contextQualifier).fire(securityAuditEvent);
            throw new ServletException("photo digest incorrect");
        }
    }

    Address address;
    if (null != message.addressFile) {
        byte[] addressFile = trimRight(message.addressFile);
        verifySignature(contextQualifier, rrnCertificate.getSigAlgName(), message.addressSignatureFile,
                rrnCertificate, request, addressFile, message.identitySignatureFile);
        address = TlvParser.parse(message.addressFile, Address.class);
    } else {
        address = null;
    }

    /*
     * Check the validity of the identity data as good as possible.
     */
    GregorianCalendar cardValidityDateEndGregorianCalendar = identity.getCardValidityDateEnd();
    if (null != cardValidityDateEndGregorianCalendar) {
        Date now = new Date();
        Date cardValidityDateEndDate = cardValidityDateEndGregorianCalendar.getTime();
        if (now.after(cardValidityDateEndDate)) {
            SecurityAuditEvent securityAuditEvent = new SecurityAuditEvent(Incident.DATA_INTEGRITY,
                    message.idFile);
            this.securityAuditEvent.select(contextQualifier).fire(securityAuditEvent);
            throw new SecurityException("eID card has expired");
        }
    }

    this.identityEvent.select(contextQualifier).fire(new IdentityEvent(identity, address, message.photoFile));
    return new FinishedMessage();
}

From source file:com.quartz.AmazonQuartzJob.java

public void execute(JobExecutionContext context) throws JobExecutionException {
    String error = "No error";
    SimpleDateFormat out = new SimpleDateFormat("hh:mm a");
    System.out.println(":::>>>Amazon Job Time Check @ " + out.format(new Date()));

    settingsHM = TextFileReadWrite.readSettings(file);

    String onoff = settingsHM.get("onoff"), emails = settingsHM.get("emails"),
            lastUpdate = settingsHM.get("lastUpdate");
    ArrayList<String> time = new ArrayList(Arrays.asList(settingsHM.get("time").split(";")));

    if (emails == null) {
        emails = ";";
    }//from  ww  w .  ja  v  a  2  s .c o  m
    Date lastDate;
    try {
        lastDate = out1.parse(lastUpdate);
    } catch (ParseException ex) {
        GregorianCalendar now = new GregorianCalendar();
        now.set(Calendar.DAY_OF_YEAR, -1);
        lastDate = now.getTime();
    }

    String[] emailArr = emails.replace(";;", ";").replace(";", " ").trim().split(" ");
    if (onoff.equalsIgnoreCase("checked")) {
        for (String e : time) {
            Date dScheduled, dNow;
            try {
                dScheduled = out.parse(e);
                dNow = out.parse(out.format(new Date()));
                if (dScheduled.getTime() == dNow.getTime()) {
                    System.out.println("\t---> Amazon task launch");

                    XMLOrderConfirmationFeedBuilder.generateShipConfirmXML();

                    try {
                        this.submitFeed();
                    } catch (IOException ex) {
                        System.out.println("Error occured in submitFeed method");
                        error += "Cannot submit feed.";
                    }

                    try {
                        if (emails != null && emails.length() > 0) {
                            for (String recipient : emailArr) {
                                InternetAddress.parse(recipient);
                                if (recipient.indexOf("@") > 0 && recipient.indexOf(".") > 0) {
                                    String subject = "Auto notification from AMZ order update application server";
                                    String msg = "Scheduled Amazon orders update executed.\nError/s: " + error
                                            + "\n\n Update contents:\n\n"
                                            + XML.toJSONObject(TextFileReadWrite
                                                    .readFile(new File("AMZ_Orders_Tracking_Feed.xml"))[0])
                                                    .toString(3);
                                    Emailer.Send(AKC_Creds.ANH_EMAIL, AKC_Creds.ANH_EMAIL_PWD, recipient,
                                            subject, msg);
                                }
                            }
                        }
                        System.out.println("===[email notifications send]===");
                        writeUpdateTimestamp();
                    } catch (MessagingException ex) {
                        System.out.println(ex.getMessage());
                    }

                } else {
                    //System.out.println("\txxx> AMZ task time not match | Scheduled: " + out.format(dScheduled) + " Now: " + out.format(dNow));
                }
            } catch (ParseException ex) {
                //System.out.println(ex.getMessage());
                error += " Cannot create XML feed.";
            }
        }
    }

}