Example usage for org.apache.commons.lang.time DateUtils MILLIS_PER_DAY

List of usage examples for org.apache.commons.lang.time DateUtils MILLIS_PER_DAY

Introduction

In this page you can find the example usage for org.apache.commons.lang.time DateUtils MILLIS_PER_DAY.

Prototype

long MILLIS_PER_DAY

To view the source code for org.apache.commons.lang.time DateUtils MILLIS_PER_DAY.

Click Source Link

Document

Number of milliseconds in a standard day.

Usage

From source file:br.com.nordestefomento.jrimum.utilix.DateUtil.java

/**
 * <p>//  w  w  w. j  a  va2 s . com
 * Calcula a diferena de dias entre duas datas. O resultado  modular, ou
 * seja, maior ou igual a zero, logo a data final no precisa ser
 * necessariamente maior que a data inicial.
 * </p>
 * 
 * @param dataInicial
 *            - data inicial do intervalo.
 * @param dataFinal
 *            - data final do intervalo.
 * @return nmero(mdulo) de dias entre as datas.
 * 
 * @throws IllegalArgumentException
 *             Caso pelo menos uma das duas datas seja <code>null</code>.
 * @since 0.2
 */
public static long calculeDiferencaEmDias(final Date dataInicial, final Date dataFinal) {

    long fator = 0;
    Date dataInicialTruncada, dataFinalTruncada;

    if (isNotNull(dataInicial) && isNotNull(dataFinal)) {

        dataInicialTruncada = DateUtils.truncate(dataInicial, Calendar.DATE);
        dataFinalTruncada = DateUtils.truncate(dataFinal, Calendar.DATE);

        fator = ((dataFinalTruncada.getTime() - dataInicialTruncada.getTime()) / DateUtils.MILLIS_PER_DAY);

        if (fator < 0) {
            fator *= -1;
        }
    } else {
        throw new IllegalArgumentException("A data inicial [" + dataInicial + "] e a data final [" + dataFinal
                + "] " + "no podem ter valor 'null'.");
    }

    return fator;
}

From source file:mitm.djigzo.web.services.AppModule.java

public static void contributeFactoryDefaults(MappedConfiguration<String, String> configuration) {
    /*// w ww.j a va2 s  .c  om
     * djigzo home defaults to current user directory
     */
    configuration.add(DJIGZO_HOME_PARAMETER, System.getProperty("user.dir"));

    configuration.add("djigzo.https.all", "true");
    configuration.add("djigzo.ws.server.host", "127.0.0.1");
    configuration.add("djigzo.ws.server.port", "9000");
    configuration.add("djigzo.ws.server.protocol", "http");
    configuration.add("djigzo.restart.delay", "45");
    configuration.add("protected.system.password", "djigzo");
    configuration.add("soap.username", "admin");
    configuration.add("soap.password", "password");
    configuration.add("soap.authentication-failed-page", "accessdenied");
    configuration.add("access-denied-page", "accessdenied");
    configuration.add("csrf.length", "6");
    configuration.add("csrf.redirectTo", "accessdenied");
    configuration.add("hmac.algorithm", "HmacSHA1");
    configuration.add("hmac.redirectTo", "accessdenied");
    /*
     * When an email is viewed it will not be larger than email.max-size size (prevent DOS)
     */
    configuration.add("email.max-size", "65535");
    configuration.add("email.attachment.max-size", Integer.toString(5 * SizeUtils.MB));
    /*
     * Maximum time an uploaded attachment (by external user) may live
     */
    configuration.add("upload.max-stale-time", Long.toString(DateUtils.MILLIS_PER_MINUTE * 30));
    configuration.add("upload.max-attachments", "3");

    /*
     * the maximum number of concurrent sessions for one 'user' (message key etc.)
     */
    configuration.add("web.max-reply-rate", "5");
    /*
     * Time a reply lives in the rate counter
     */
    configuration.add("web.reply-rate-lifetime", Long.toString(DateUtils.MILLIS_PER_MINUTE * 5));

    /*
     * The character encoding to use when replying to the PDF
     */
    configuration.add("web.pdf.reply.charset", CharacterEncoding.UTF_8);

    /*
     * parameters for the SSL management page
     */
    configuration.add("ssl.password", "djigzo");
    configuration.add("ssl.file", "./ssl/sslCertificate.p12");

    /*
     * If true the admin can edit My Destination
     */
    configuration.add("mta.enableMyDestination", "false");

    /*
     * If true the Fetchmail pages are enabled
     */
    configuration.add("fetchmail.enabled", "false");

    configuration.add("fetchmail.hidePasswords", "true");
    configuration.add("saslPasswords.hidePasswords", "true");

    configuration.add("caBulkRequest.maxLines", "10000");
    configuration.add("caBulkRequest.maxValueLength", "256");

    /*
     * Check whether a certificate is in use (if in use the delete option is disabled). 
     * This is a relatively slow process. Disable if more speed is required. 
     */
    configuration.add("certificates.checkInUse", "true");

    /*
     * maxBatchSize settings
     */
    configuration.add("certificateRequestsPreview.maxBatchSize", "10");
    configuration.add("certificateImport.maxBatchSize", "10");
    configuration.add("certificateImportKey.maxBatchSize", "10");

    /*
     * rowsPerPage settings
     */
    configuration.add("users.rowsPerPage", "25");
    configuration.add("certificates.rowsPerPage", "25");
    configuration.add("crls.rowsPerPage", "25");
    configuration.add("jamesLog.rowsPerPage", "25");
    configuration.add("postfixLog.rowsPerPage", "25");
    configuration.add("postfixSpool.rowsPerPage", "25");
    configuration.add("sendCertificate.rowsPerPage", "25");
    configuration.add("certificateUsage.rowsPerPage", "25");
    configuration.add("ctls.rowsPerPage", "25");
    configuration.add("fetchmail.rowsPerPage", "25");
    configuration.add("saslPasswords.rowsPerPage", "25");
    configuration.add("certificateRequests.rowsPerPage", "25");
    configuration.add("certificateRequestsPreview.rowsPerPage", "25");
    configuration.add("dlp.patterns.rowsPerPage", "25");
    configuration.add("quarantineManager.rowsPerPage", "25");
    configuration.add("quarantineView.rowsPerPage", "10");
    configuration.add("patternsUsage.rowsPerPage", "25");

    /*
     * portal settings
     */
    configuration.add("portal.selectpassword.validity", Long.toString(DateUtils.MILLIS_PER_DAY * 30));

    /*
     * Brute force filter settings.
     */
    configuration.add("bff.lifetime", "60000" /* failure is 1 min in cache */);
    configuration.add("bff.maxFailures", "5" /* 5 failures in cache => ban */);
    configuration.add("bff.enabled", "true");
}

From source file:eagle.jobrunning.crawler.RunningJobCrawlerImpl.java

public void startzkCleanupThread() {
    LOG.info("zk cleanup thread started");
    while (true) {
        try {//from   ww  w.j  a  v  a 2 s . com
            long thresholdTime = System.currentTimeMillis()
                    - controlConfig.zkCleanupTimeInday * DateUtils.MILLIS_PER_DAY;
            String date = DateTimeUtil.format(thresholdTime, "yyyyMMdd");
            zkStateManager.truncateJobBefore(ResourceType.JOB_CONFIGURATION, date);
            zkStateManager.truncateJobBefore(ResourceType.JOB_COMPLETE_INFO, date);
            Thread.sleep(30 * 60 * 1000);
        } catch (Throwable t) {
            LOG.warn("Got an throwable, t: ", t);
        }
    }
}

From source file:com.example.app.support.address.CommonUtils.java

/**
 * Calculate the elapsed time in specified {@link TimeUnit}
 *
 * @param startInMilli start time./*from  w w w  .  jav  a2 s  .  co m*/
 * @param unit unit.
 *
 * @return the elapsed time.
 */
public static double getElapsed(long startInMilli, TimeUnit unit) {
    double elapsed = System.currentTimeMillis() - startInMilli;
    if (unit == MILLISECONDS) {
        return elapsed;
    } else if (unit == DAYS) {
        return elapsed / DateUtils.MILLIS_PER_DAY;
    } else if (unit == HOURS) {
        return elapsed / DateUtils.MILLIS_PER_HOUR;
    } else if (unit == MINUTES) {
        return elapsed / DateUtils.MILLIS_PER_MINUTE;
    } else if (unit == SECONDS) {
        return elapsed / DateUtils.MILLIS_PER_SECOND;
    } else {
        throw new UnsupportedOperationException(unit + " conversion is not supported");
    }
}

From source file:com.naryx.tagfusion.cfm.application.cfApplicationManager.java

public void loadApplication(cfComponentData applicationCfc, cfSession session) throws cfmRunTimeException {
    cfData appName = applicationCfc.getData("NAME");
    cfApplicationData appData = getAppData(session,
            appName == null ? cfAPPLICATION.UNNAMED_APPNAME : appName.toString());

    String scriptProtect = null;//  www  .ja v  a 2  s . c o m
    if (applicationCfc.containsKey(cfAPPLICATION.SCRIPTPROTECT)) {
        scriptProtect = applicationCfc.getData(cfAPPLICATION.SCRIPTPROTECT).getString();
    }

    // Set up the specific application mappings
    if (applicationCfc.containsKey(cfAPPLICATION.MAPPINGS)) {
        cfData mappingsData = (cfData) applicationCfc.getData(cfAPPLICATION.MAPPINGS);
        if (mappingsData.getDataType() == cfData.CFSTRUCTDATA) {
            session.setDataBin(cfAPPLICATION.MAPPINGS, mappingsData);
        }
    }

    // Set up the specific application customtagpaths
    if (applicationCfc.containsKey(cfAPPLICATION.CUSTOMTAGPATHS)) {
        cfData mappingsData = (cfData) applicationCfc.getData(cfAPPLICATION.CUSTOMTAGPATHS);
        if (mappingsData.getDataType() == cfData.CFSTRINGDATA) {
            session.setDataBin(cfAPPLICATION.CUSTOMTAGPATHS, mappingsData.getString());
        }
    }

    String datasource = null;
    if (applicationCfc.containsKey(cfAPPLICATION.DATASOURCE))
        datasource = applicationCfc.getData(cfAPPLICATION.DATASOURCE).getString();

    String sessionstorage = null;
    if (applicationCfc.containsKey(cfAPPLICATION.SESSIONSTORAGE))
        sessionstorage = applicationCfc.getData(cfAPPLICATION.SESSIONSTORAGE).getString();

    appData.onRequestStart(session, bJ2EESessionManagement,
            (long) (applicationCfc.getData(cfAPPLICATION.APPLICATIONTIMEOUT).getDouble()
                    * DateUtils.MILLIS_PER_DAY),
            (long) (applicationCfc.getData(cfAPPLICATION.SESSIONTIMEOUT).getDouble()
                    * DateUtils.MILLIS_PER_DAY),
            applicationCfc.getData(cfAPPLICATION.SETCLIENTCOOKIES).getBoolean(),
            applicationCfc.getData(cfAPPLICATION.SETDOMAINCOOKIES).getBoolean(),
            applicationCfc.getData(cfAPPLICATION.SESSIONMANAGEMENT).getBoolean(),
            applicationCfc.getData(cfAPPLICATION.CLIENTMANAGEMENT).getBoolean(),
            applicationCfc.getData(cfAPPLICATION.CLIENTSTORAGE).getString(),
            applicationCfc.getData(cfAPPLICATION.LOGINSTORAGE).getString(), applicationCfc.getComponentPath(),
            scriptProtect, applicationCfc.getData(cfAPPLICATION.SECUREJSON).getBoolean(),
            applicationCfc.getData(cfAPPLICATION.SECUREJSONPREFIX).getString(), datasource, sessionstorage,
            applicationCfc);

}

From source file:de.tor.tribes.ui.algo.TimeFrameVisualizer.java

private void renderDayMarkers(long pStart, long pEnd, Graphics2D pG2D) {
    Date d = new Date(pStart);
    d = DateUtils.setHours(d, 0);/*from   w w w  . jav  a 2  s  .c o m*/
    d = DateUtils.setMinutes(d, 0);
    d = DateUtils.setSeconds(d, 0);
    d = DateUtils.setMilliseconds(d, 0);

    for (long mark = d.getTime(); mark <= pEnd; mark += DateUtils.MILLIS_PER_HOUR) {
        int markerPos = Math.round((mark - pStart) / DateUtils.MILLIS_PER_MINUTE);
        pG2D.setColor(Color.YELLOW);
        pG2D.fillRect(markerPos, 20, 2, 10);
        pG2D.setColor(Color.WHITE);
        pG2D.setFont(pG2D.getFont().deriveFont(Font.BOLD, 10.0f));
        pG2D.fillRect(markerPos - 5, 15, 12, 10);
        pG2D.setColor(Color.BLACK);
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date(mark));
        NumberFormat f = NumberFormat.getNumberInstance();
        f.setMinimumIntegerDigits(2);
        f.setMaximumFractionDigits(2);
        pG2D.drawString(f.format(cal.get(Calendar.HOUR_OF_DAY)), markerPos - 5, 23);
    }

    long currentDay = d.getTime();
    while (currentDay < pEnd) {
        currentDay += DateUtils.MILLIS_PER_DAY;
        int markerPos = Math.round((currentDay - pStart) / DateUtils.MILLIS_PER_MINUTE);
        pG2D.setColor(new Color(123, 123, 123));
        pG2D.fillRect(markerPos, 15, 3, 30);
        SimpleDateFormat f = new SimpleDateFormat("dd.MM.yy");
        String dayLabel = f.format(currentDay);
        Rectangle2D labelBounds = pG2D.getFontMetrics().getStringBounds(dayLabel, pG2D);
        pG2D.setColor(Color.YELLOW);
        int labelWidth = (int) labelBounds.getWidth() + 5;
        pG2D.fillRect(markerPos - (int) Math.rint(labelWidth / 2), 15, labelWidth, 10);
        pG2D.setColor(Color.BLACK);
        pG2D.setFont(pG2D.getFont().deriveFont(Font.BOLD, 10.0f));
        pG2D.drawString(dayLabel, markerPos - (int) Math.rint(labelWidth / 2) + 2, 23);
    }
}

From source file:com.naryx.tagfusion.cfm.application.cfApplicationManager.java

public void loadApplication(cfTag parentTag, cfSession _Session) throws cfmRunTimeException {
    // This method is invoked from the CFAPPLICATION tag and will initialise and setup all the application data storage
    String appName = parentTag.getDynamic(_Session, "NAME").getString();

    // Get the application data instance
    cfApplicationData appData = getAppData(_Session, appName);

    String scriptProtect = null;//from   w  ww.  ja  v a  2s  .  c  o m
    if (parentTag.containsAttribute(cfAPPLICATION.SCRIPTPROTECT)) {
        scriptProtect = parentTag.getDynamic(_Session, cfAPPLICATION.SCRIPTPROTECT).getString();
    }

    String datasource = null;
    if (parentTag.containsAttribute(cfAPPLICATION.DATASOURCE))
        datasource = parentTag.getDynamic(_Session, cfAPPLICATION.DATASOURCE).getString();

    String sessionstorage = null;
    if (parentTag.containsAttribute(cfAPPLICATION.SESSIONSTORAGE))
        sessionstorage = parentTag.getDynamic(_Session, cfAPPLICATION.SESSIONSTORAGE).getString();

    if (parentTag.containsAttribute(cfAPPLICATION.CUSTOMTAGPATHS))
        _Session.setDataBin(cfAPPLICATION.CUSTOMTAGPATHS,
                parentTag.getDynamic(_Session, cfAPPLICATION.CUSTOMTAGPATHS).getString());

    // Setup the properties of this application
    appData.onRequestStart(_Session, bJ2EESessionManagement,
            (long) (parentTag.getDynamic(_Session, cfAPPLICATION.APPLICATIONTIMEOUT).getDouble()
                    * DateUtils.MILLIS_PER_DAY),
            (long) (parentTag.getDynamic(_Session, cfAPPLICATION.SESSIONTIMEOUT).getDouble()
                    * DateUtils.MILLIS_PER_DAY),
            parentTag.getDynamic(_Session, cfAPPLICATION.SETCLIENTCOOKIES).getBoolean(),
            parentTag.getDynamic(_Session, cfAPPLICATION.SETDOMAINCOOKIES).getBoolean(),
            parentTag.getDynamic(_Session, cfAPPLICATION.SESSIONMANAGEMENT).getBoolean(),
            parentTag.getDynamic(_Session, cfAPPLICATION.CLIENTMANAGEMENT).getBoolean(),
            parentTag.getDynamic(_Session, cfAPPLICATION.CLIENTSTORAGE).getString(),
            parentTag.getDynamic(_Session, cfAPPLICATION.LOGINSTORAGE).getString(), null, scriptProtect,
            parentTag.getDynamic(_Session, cfAPPLICATION.SECUREJSON).getBoolean(),
            parentTag.getDynamic(_Session, cfAPPLICATION.SECUREJSONPREFIX).getString(), datasource,
            sessionstorage, null);
}

From source file:net.sourceforge.vulcan.core.support.AxisLabelGeneratorTest.java

public void testMinMaxThreeMonths() throws Exception {
    setParams(DateUtils.MILLIS_PER_DAY * 90);

    final Calendar c = DateUtils.truncate(cal, Calendar.MONTH);
    assertEquals(c.getTimeInMillis(), gen.getMin());

    c.add(Calendar.MONTH, 4);//  ww w .j  a v a  2 s.c  o  m

    assertEquals(c.getTimeInMillis(), gen.getMax());
}

From source file:net.sourceforge.vulcan.core.support.AxisLabelGeneratorTest.java

public void testLabelThreeMonths() throws Exception {
    assertLabels(DateUtils.MILLIS_PER_DAY * 90, "Oct 2001", "Nov 2001", "Dec 2001", "Jan 2002");
}

From source file:net.sourceforge.vulcan.core.support.AxisLabelGeneratorTest.java

public void testLabelThreeMonthsAlternateLocale() throws Exception {
    fakeDateFormats.put("fr:axis.by.month", "MMM yyyy");
    locale = Locale.FRENCH;//from ww  w  .  j  av a2 s.  com

    DateFormat df = new SimpleDateFormat("MMM yyyy", locale);
    String dec = df.format(new GregorianCalendar(2001, GregorianCalendar.DECEMBER, 1).getTime());

    assertLabels(DateUtils.MILLIS_PER_DAY * 90, "oct. 2001", "nov. 2001", dec, "janv. 2002");
}