Java Code Examples for java.util.Date.after()

The following are Jave code examples for showing how to use after() of the java.util.Date class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: springboot-security-wechat   File: DateUtils.java   View Source Code Vote up 7 votes
/**
 * 计算两个Date之间的工作日时间差
 *
 * @param start 开始时间
 * @param end   结束时间
 * @return int 返回两天之间的工作日时间
 */
public static int countDutyday(Date start, Date end) {
    if (start == null || end == null) return 0;
    if (start.after(end)) return 0;
    Calendar c_start = Calendar.getInstance();
    Calendar c_end = Calendar.getInstance();
    c_start.setTime(start);
    c_end.setTime(end);
    //时分秒毫秒清零
    c_start.set(Calendar.HOUR_OF_DAY, 0);
    c_start.set(Calendar.MINUTE, 0);
    c_start.set(Calendar.SECOND, 0);
    c_start.set(Calendar.MILLISECOND, 0);
    c_end.set(Calendar.HOUR_OF_DAY, 0);
    c_end.set(Calendar.MINUTE, 0);
    c_end.set(Calendar.SECOND, 0);
    c_end.set(Calendar.MILLISECOND, 0);
    //初始化第二个日期,这里的天数可以随便的设置
    int dutyDay = 0;
    while (c_start.compareTo(c_end) < 0) {
        if (c_start.get(Calendar.DAY_OF_WEEK) != 1 && c_start.get(Calendar.DAY_OF_WEEK) != 7)
            dutyDay++;
        c_start.add(Calendar.DAY_OF_YEAR, 1);
    }
    return dutyDay;
}
 
Example 2
Project: fitnotifications   File: SimpleTimeZone.java   View Source Code Vote up 6 votes
/**
 * {@inheritDoc}
 * @stable ICU 3.8
 */
@Override
public TimeZoneTransition getPreviousTransition(long base, boolean inclusive) {
    if (!useDaylight) {
        return null;
    }

    initTransitionRules();
    long firstTransitionTime = firstTransition.getTime();
    if (base < firstTransitionTime || (!inclusive && base == firstTransitionTime)) {
        return null;
    }
    Date stdDate = stdRule.getPreviousStart(base, dstRule.getRawOffset(),
                                            dstRule.getDSTSavings(), inclusive);
    Date dstDate = dstRule.getPreviousStart(base, stdRule.getRawOffset(),
                                            stdRule.getDSTSavings(), inclusive);
    if (stdDate != null && (dstDate == null || stdDate.after(dstDate))) {
        return new TimeZoneTransition(stdDate.getTime(), dstRule, stdRule);
    }
    if (dstDate != null && (stdDate == null || dstDate.after(stdDate))) {
        return new TimeZoneTransition(dstDate.getTime(), stdRule, dstRule);
    }
    return null;
}
 
Example 3
Project: NoraUi   File: Step.java   View Source Code Vote up 6 votes
/**
 * Update a html input text value with a date.
 *
 * @param pageElement
 *            Is target element
 * @param dateType
 *            "any", "future", "today", "future_strict"
 * @param date
 *            Is the new data (date)
 * @throws TechnicalException
 *             is thrown if you have a technical error (format, configuration, datas, ...) in NoraUi.
 *             Exception with {@value com.github.noraui.utils.Messages#FAIL_MESSAGE_WRONG_DATE_FORMAT} message (no screenshot, no exception) or with
 *             {@value com.github.noraui.utils.Messages#FAIL_MESSAGE_UNEXPECTED_DATE} message
 *             (with screenshot, no exception)
 * @throws FailureException
 *             if the scenario encounters a functional error
 */
protected void updateDateValidated(PageElement pageElement, String dateType, String date) throws TechnicalException, FailureException {
    logger.debug("updateDateValidated with elementName={}, dateType={} and date={}", pageElement, dateType, date);
    DateFormat formatter = new SimpleDateFormat(Constants.DATE_FORMAT);
    Date today = Calendar.getInstance().getTime();
    try {
        Date valideDate = formatter.parse(date);
        if ("any".equals(dateType)) {
            logger.debug("update Date with any date: {}", date);
            updateText(pageElement, date);
        } else if (formatter.format(today).equals(date) && ("future".equals(dateType) || "today".equals(dateType))) {
            logger.debug("update Date with today");
            updateText(pageElement, date);
        } else if (valideDate.after(Calendar.getInstance().getTime()) && ("future".equals(dateType) || "future_strict".equals(dateType))) {
            logger.debug("update Date with a date after today: {}", date);
            updateText(pageElement, date);
        } else {
            new Result.Failure<>(date, Messages.format(Messages.getMessage(Messages.FAIL_MESSAGE_UNEXPECTED_DATE), Messages.getMessage(Messages.DATE_GREATER_THAN_TODAY)), true,
                    pageElement.getPage().getCallBack());
        }
    } catch (ParseException e) {
        new Result.Failure<>(e.getMessage(), Messages.format(Messages.getMessage(Messages.FAIL_MESSAGE_WRONG_DATE_FORMAT), pageElement, date), false, pageElement.getPage().getCallBack());
    }

}
 
Example 4
Project: date-helper   File: Zeitraum.java   View Source Code Vote up 5 votes
/**
 * Erstellt einen neuen Zeitraum.
 *
 * @param von Datum von wann an der Zeitraum gilt (inklusive), ohne Zeitinformation
 * @param bis Datum bis wann der Zeitraum gilt (inklusive), ohne Zeitinformation
 */
public Zeitraum(Date von, Date bis) {
	if (von == null) {
		throw new IllegalArgumentException("von ist null");
	}
	if (bis == null) {
		throw new IllegalArgumentException("bis ist null");
	}
	if (von.after(bis)) {
		throw new IllegalArgumentException("von (" + von + ") muss gleich oder vor bis (" + bis
			+ ") sein!");
	}
	this.von = von;
	this.bis = bis;
}
 
Example 5
Project: Reer   File: NotMostRecentlyUsedDaemonExpirationStrategy.java   View Source Code Vote up 5 votes
private boolean isMostRecentlyUsed(Collection<DaemonInfo> daemonInfos, DaemonContext thisDaemonContext) {
    String mruUid = null;
    Date mruTimestamp = new Date(Long.MIN_VALUE);
    for (DaemonInfo daemonInfo : daemonInfos) {
        Date daemonAccessTime = daemonInfo.getLastBusy();
        if (daemonAccessTime.after(mruTimestamp)) {
            mruUid = daemonInfo.getUid();
            mruTimestamp = daemonAccessTime;
        }
    }
    return thisDaemonContext.getUid().equals(mruUid);
}
 
Example 6
Project: lams   File: Authenticator.java   View Source Code Vote up 5 votes
/**
    * Checks hash for LoginRequest calls. Differs from the method above in a way that datetime is expected to contain
    * real value and it must be quite recent one.
    *
    * @param map
    * @param datetime
    * @param username
    * @param method
    * @param lsid
    *            this parameter provided only if coming from learnerStrictAuth
    * @param hashValue
    * @throws AuthenticationException
    */
   public static void authenticateLoginRequest(ExtServer map, String datetime, String username, String method,
    String lsid, String hashValue) throws AuthenticationException {

if (map == null) {
    throw new AuthenticationException("The third party server is not configured on LAMS server");
}
if (map.getDisabled()) {
    throw new AuthenticationException("The third party server is disabled");
}

// check if there is datetime check and if so if it isn't too old
if (map.getTimeToLiveLoginRequestEnabled()) {
    long datetimeParam;
    try {
	datetimeParam = Long.parseLong(datetime);
    } catch (NumberFormatException e) {
	throw new AuthenticationException(
		"The third party server provided wrong format of datetime, datetime = " + datetime, e);
    }

    int timeToLiveLoginRequest = map.getTimeToLiveLoginRequest();
    // sum up request time and maximum allowed request's time to live
    Date requestTimePlusTimeToLive = new Date(datetimeParam + timeToLiveLoginRequest * 60 * 1000);
    Date requestTimeMinusTimeToLive = new Date(datetimeParam - timeToLiveLoginRequest * 60 * 1000);
    Date now = new Date();
    if (requestTimePlusTimeToLive.before(now) || requestTimeMinusTimeToLive.after(now)) {
	throw new AuthenticationException("Request is not in the time range of " + timeToLiveLoginRequest
		+ " minutes. Please, contact sysadmin.");
    }
}

//learnerStrictAuth hash [ts + uid + method + lsid + serverID + serverKey]
//otherwise [ts + uid + method + serverID + serverKey]
String plaintext = datetime.toLowerCase().trim() + username.toLowerCase().trim() + method.toLowerCase().trim()
	+ ("learnerStrictAuth".equals(method) ? lsid.toLowerCase().trim() : "")
	+ map.getServerid().toLowerCase().trim() + map.getServerkey().toLowerCase().trim();
Authenticator.checkHash(plaintext, hashValue);
   }
 
Example 7
Project: openjdk-jdk10   File: Bug8135055.java   View Source Code Vote up 5 votes
public static void main(String[] args) throws InterruptedException {
    for (int i = 0; i < 1000; i++) {
        Date d = new Date();
        Timestamp ts = new Timestamp(d.getTime());
        if (d.after(ts)) {
            throw new RuntimeException("date with time " + d.getTime()
                    + " should not be after TimeStamp , Nanos component of "
                            + "TimeStamp is " +ts.getNanos());
        }
        Thread.sleep(1);
    }
}
 
Example 8
Project: boohee_v5.6   File: bt.java   View Source Code Vote up 5 votes
public static int a(Date date, Date date2) {
    if (!date.after(date2)) {
        Date date3 = date2;
        date2 = date;
        date = date3;
    }
    return (int) ((date.getTime() - date2.getTime()) / 1000);
}
 
Example 9
Project: boohee_v5.6   File: a.java   View Source Code Vote up 5 votes
a a(Date date, Date date2) {
    if (date.after(date2)) {
        this.c = this.a.format(date2);
        this.d = this.a.format(date);
    } else {
        this.c = this.a.format(date);
        this.d = this.a.format(date2);
    }
    return this;
}
 
Example 10
Project: Equella   File: HttpServiceImpl.java   View Source Code Vote up 5 votes
public boolean hasExpired()
{
	if( expires == null )
	{
		return false;
	}
	Date now = new Date();
	return now.after(expires);
}
 
Example 11
Project: Proyecto2017Seguros   File: PolizaIntegralComercioMenu.java   View Source Code Vote up 5 votes
public String validateCrear(final String polizaNumero, final Persona polizaCliente, final Compania polizaCompania,
		final Date polizaFechaEmision, final Date polizaFechaVigencia, final Date polizaFechaVencimiento,
		final TipoPago polizaTipoDePago, final DetalleTipoPago polizaPago, final double polizaImporteTotal,
		final float riesgoIntegralComercioRobo, final float riesgoIntegralComercioCristales,
		final float riesgoIntegralComercioIncendioEdificio, final float riesgoIntegralComercioIncendioContenido,
		final float riesgoIntegralComercioRc, final float riesgoIntegralComercioRcl,
		final float riesgoIntegralComercioDanioPorAgua, final float riesgoIntegralComercioRCC,
		final String riesgoIntegralComercioOtrosNombre, final double riesgoIntegralComercioOtrosMonto) {
	if (polizaFechaVigencia.after(polizaFechaVencimiento)) {
		return "La fecha de vigencia es mayor a la de vencimiento";
	}
	return "";
}
 
Example 12
Project: SER316-Munich   File: EventsScheduler.java   View Source Code Vote up 5 votes
public static void init() {
    cancelAll();
    //changeDateTimer.cancel();
    Vector events = (Vector)EventsManager.getActiveEvents();
    _timers = new Vector();
    /*DEBUG*/System.out.println("----------");
    for (int i = 0; i < events.size(); i++) {
        Event ev = (Event)events.get(i);
        Date evTime = ev.getTime();
    /*DEBUG*/System.out.println((Calendar.getInstance()).getTime());
      //  if (evTime.after(new Date())) {
   if (evTime.after((Calendar.getInstance()).getTime())) {	
            EventTimer t = new EventTimer(ev);
            t.schedule(new NotifyTask(t), ev.getTime());                
            _timers.add(t);
            /*DEBUG*/System.out.println(ev.getTimeString());
        }
    }
    /*DEBUG*/System.out.println("----------");
    Date midnight = getMidnight();
    changeDateTimer.schedule(new TimerTask() {
            public void run() {
                init();
                this.cancel();
            }
    }, midnight);
    notifyChanged();
}
 
Example 13
Project: zombot-java   File: DateUtils.java   View Source Code Vote up 5 votes
/**
 * Returns the maximum of two dates. A null date is treated as being less
 * than any non-null date.
 */
public static Date max(Date d1, Date d2) {
    if (d1 == null && d2 == null) return null;
    if (d1 == null) return d2;
    if (d2 == null) return d1;
    return (d1.after(d2)) ? d1 : d2;
}
 
Example 14
Project: Equella   File: BasicCookieHandler.java   View Source Code Vote up 5 votes
public boolean hasExpired()
{
	if( expires == null )
	{
		return false;
	}
	Date now = new Date();
	return now.after(expires);
}
 
Example 15
Project: fresco_floodlight   File: FlowReconcileManager.java   View Source Code Vote up 5 votes
/**
 * Add to-be-reconciled flow to the queue.
 *
 * @param ofmRcIn the ofm rc in
 */
@Override
public void reconcileFlow(OFMatchReconcile ofmRcIn, EventPriority priority) {
	if (ofmRcIn == null) return;

	// Make a copy before putting on the queue.
	OFMatchReconcile myOfmRc = new OFMatchReconcile(ofmRcIn);

	flowQueue.offer(myOfmRc, priority);
	ctrFlowReconcileRequest.increment();

	Date currTime = new Date();
	long delay = 0;

	/** schedule reconcile task immidiately if it has been more than 1 sec
	 *  since the last run. Otherwise, schedule the reconcile task in
	 *  DELAY_MILLISEC.
	 */
	if (currTime.after(new Date(lastReconcileTime.getTime() + 1000))) {
		delay = 0;
	} else {
		delay = FLOW_RECONCILE_DELAY_MILLISEC;
	}
	flowReconcileTask.reschedule(delay, TimeUnit.MILLISECONDS);

	if (logger.isTraceEnabled()) {
		logger.trace("Reconciling flow: {}, total: {}",
				myOfmRc.toString(), flowQueue.size());
	}
}
 
Example 16
Project: javaOIDCMsg   File: VerificationAndAssertion.java   View Source Code Vote up 4 votes
private static void assertDateIsFuture(Date date, long leeway, Date today) {
    today.setTime(today.getTime() - leeway * 1000);
    if (date != null && today.after(date)) {
        throw new TokenExpiredException(String.format("The Token has expired on %s.", date));
    }
}
 
Example 17
Project: OpenDiabetes   File: VaultCsvExporter.java   View Source Code Vote up 4 votes
@Override
protected List<ExportEntry> prepareData(List<VaultEntry> data) {
    List<ExportEntry> returnValues = new ArrayList<>();

    List<VaultEntry> tmpValues = queryData();
    if (tmpValues == null || tmpValues.isEmpty()) {
        return null;
    }

    // list is ordered by timestamp from database (or should be ordered otherwise)
    Date fromTimestamp = tmpValues.get(0).getTimestamp();
    Date toTimestamp = tmpValues.get(tmpValues.size() - 1).getTimestamp();

    if (!tmpValues.isEmpty()) {
        int i = 0;
        delayBuffer = new ArrayList<>();
        while (!fromTimestamp.after(toTimestamp)) {
            // start new timeslot (1m slots)
            VaultCsvEntry tmpCsvEntry = new VaultCsvEntry();
            tmpCsvEntry.setTimestamp(fromTimestamp);

            // add delayed items
            if (!delayBuffer.isEmpty()) {
                // need to copy the buffer since the loop may create new entries
                VaultEntry[] delayedEntries = delayBuffer.toArray(new VaultEntry[]{});
                delayBuffer.clear();
                for (VaultEntry delayedItem : delayedEntries) {
                    tmpCsvEntry = processVaultEntry(tmpCsvEntry, delayedItem);

                }
            }

            // search and add vault entries for this time slot
            VaultEntry tmpEntry;
            while (fromTimestamp.equals((tmpEntry = tmpValues.get(i)).getTimestamp())) {
                if (i < tmpValues.size() - 1) {
                    i++;
                } else {
                    i--;
                    break;
                }
                tmpCsvEntry = processVaultEntry(tmpCsvEntry, tmpEntry);
            }

            // save entry if not empty
            if (!tmpCsvEntry.isEmpty()) {
                returnValues.add(tmpCsvEntry);
                LOG.log(Level.FINE, "Export entry: {0}", tmpCsvEntry.toCsvString());
            }

            // add 1 minute to timestamp for next timeslot
            fromTimestamp = TimestampUtils.addMinutesToTimestamp(fromTimestamp, 1);
        }
    }
    return returnValues;
}
 
Example 18
Project: Java-Air-Reservation   File: Editdetails.java   View Source Code Vote up 4 votes
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    String fname = jTextField8.getText();
    String lname = jTextField2.getText();
    String address = jTextField3.getText();
    String contact = jTextField1.getText();
    Date dob = jXDatePicker1.getDate();
    boolean validity = true;
    
    String pattern1 = "[A-z\\s]*";
        
    if (!fname.matches(pattern1) || fname.isEmpty()) {
        v1.setVisible(true);
        validity = false;
    }

    if (!lname.matches(pattern1) || lname.isEmpty()) {
        v2.setVisible(true);
        validity = false;
    }

    if (!address.matches(pattern1) || address.isEmpty()) {
        v3.setVisible(true);
        validity = false;
    }
    if(contact.length()!=10|| contact.isEmpty()){
        validity = false;
        v4.setVisible(true);
    }
        
    if(dob == null || dob.after(new Date())){
        validity = false;
        v5.setVisible(true);
    }
    
    if(validity == true){
            Passenger p1 = new Passenger();
            p1.setFname(fname);
            p1.setLname(lname);
            p1.setPaddress(address);
            p1.setTel(contact);
            p1.setDob(dob);
            p1.setPass_no(customer.getPass_no());
            p1.setPassword(customer.getPassword());
            p1.setActive(true);
        
            p1.save();
            if(p1.save())
            {
                System.out.println("Updated Successfully");
                JOptionPane.showMessageDialog(rootPane, "Data saved successfully!");
                JDesktopPane desktopPane = getDesktopPane();
                Customerlogin cl = new Customerlogin(customer.getPass_no());
                desktopPane.add(cl);
                cl.setVisible(true);   
                this.dispose();
            }
        }
}
 
Example 19
Project: Java-Air-Reservation   File: Managecustomer.java   View Source Code Vote up 4 votes
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    // TODO add your handling code here:
    int d = JOptionPane.showConfirmDialog(null, "Press Yes to update");

    if (d == 0) {

        int row = jTable1.getSelectedRow();
        if (row == -1) {
            JOptionPane.showMessageDialog(rootPane, "Error: no row selected");
            return;
        }
        Passenger p1 = new Passenger((String) jTable1.getValueAt(row, 4));
        String fname = tfname.getText();
        String lname = tlname.getText();
        String address = taddress.getText();
        String contact = ttel.getText();
        
        String pass_no = tpassno.getText();
        Date datedob = ddate.getDate();
        boolean validity = true;
        boolean status = chckbox.isSelected();
        String pattern= "[N]{1}[0-9]{9}";
        String pattern1 = "[A-z\\s]*";
        
        if(!fname.matches(pattern1)||fname.isEmpty()){
            v1.setVisible(true);
            validity = false;
        }
        
        if(!lname.matches(pattern1)||lname.isEmpty()){
            v2.setVisible(true);
            validity = false;
        }
        
        if(!address.matches(pattern1)||address.isEmpty()){
            v3.setVisible(true);
            validity = false;
        }
        if(contact.length()!=10|| contact.isEmpty()){
            validity = false;
            v4.setVisible(true);
        }
        
        if(datedob == null || datedob.after(new Date())){
            validity = false;
            v5.setVisible(true);
        }
        
        if(!pass_no.matches(pattern)||pass_no.isEmpty()){
            validity = false;
            v6.setVisible(true);
        }
        
        if(validity == true){
            p1.setFname(fname);
            p1.setLname(lname);
            p1.setPaddress(address);
            p1.setTel(contact);
            p1.setDob(datedob);
            p1.setPass_no(pass_no);
            p1.setActive(status);
        
            if(p1.save())
            {
                System.out.println("Saved Successfully");
                JOptionPane.showMessageDialog(rootPane, "Data saved successfully!");
                resetFields();
                tableload();
            }
            else{
                JOptionPane.showMessageDialog(rootPane, "Data saved successfully!");
            }
        }

    }
}
 
Example 20
Project: springboot-shiro-cas-mybatis   File: CertUtils.java   View Source Code Vote up 2 votes
/**
 * Determines whether the given CRL is expired by comparing the nextUpdate field
 * with a given date.
 *
 * @param crl CRL to examine.
 * @param reference Reference date for comparison.
 *
 * @return True if reference date is after CRL next update, false otherwise.
 */
public static boolean isExpired(final X509CRL crl, final Date reference) {
    return reference.after(crl.getNextUpdate());
}