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

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

Introduction

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

Prototype

long MILLIS_PER_DAY

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

Click Source Link

Document

Number of milliseconds in a standard day.

Usage

From source file:de.tor.tribes.types.TribeStatsElement.java

public void addRandomSnapshots() {
    long[] snapshots = new long[] { System.currentTimeMillis() - DateUtils.MILLIS_PER_DAY,
            System.currentTimeMillis() };
    int cnt = 0;//  www  .j a  v a2 s  .c om
    for (long snapshot : snapshots) {
        timestampList.add(snapshot);
        rankList.add(tribe.getRank() + (int) Math.round(cnt * .1 * tribe.getRank()));
        pointList.add((long) tribe.getPoints() + (int) Math.round(cnt * .1 * tribe.getPoints()));
        villageList.add(tribe.getVillages());
        bashOffList.add((long) tribe.getKillsAtt() + (int) Math.round(cnt * .1 * tribe.getKillsAtt()));
        rankOffList.add((short) (tribe.getRankAtt() + (int) Math.round(cnt * .1 * tribe.getRankAtt())));
        bashDefList.add((long) tribe.getKillsDef() + (int) Math.round(cnt * .1 * tribe.getKillsDef()));
        rankDefList.add((short) (tribe.getRankDef() + (int) Math.round(cnt * .1 * tribe.getRankDef())));
        cnt++;
    }
}

From source file:com.norconex.commons.lang.time.YearMonthDayInterval.java

/**
 * Gets the number of days between start and end dates, rounded down.
 * @return number of days//ww w. ja  va  2 s.c  o  m
 */
public int getDays() {
    return (int) ((end.toMillis() - start.toMillis()) / DateUtils.MILLIS_PER_DAY);
}

From source file:io.wcm.wcm.commons.caching.CacheHeaderTest.java

@Test
public void testSetExpiresDays() {
    doAnswer(new ValidateDateHeaderAnswer(20 * DateUtils.MILLIS_PER_DAY)).when(response)
            .setHeader(eq(CacheHeader.HEADER_EXPIRES), anyString());
    CacheHeader.setExpiresDays(response, 20);
}

From source file:gov.nih.nci.firebird.service.periodic.DailyJobServiceBean.java

private void createTimer() {
    timerService.createTimer(initialExpiration, DateUtils.MILLIS_PER_DAY, DAILY_JOB_SERVICE_BEAN_TIMER_MARKER);
}

From source file:gov.nih.nci.firebird.service.periodic.DailyJobServiceBeanTest.java

private void checkCreatedTimer() {
    ArgumentCaptor<Date> initialDateCaptor = ArgumentCaptor.forClass(Date.class);
    verify(mockTimerService).createTimer(initialDateCaptor.capture(), eq(DateUtils.MILLIS_PER_DAY),
            eq(DAILY_JOB_SERVICE_BEAN_TIMER_MARKER));
    Date timerInitialDate = initialDateCaptor.getValue();
    assertEquals(getExpectedTimerInitialDate(), timerInitialDate);
}

From source file:de.tor.tribes.types.TimeSpan.java

public boolean intersects(TimeSpan pSpan) {
    if (!this.getDirection().equals(pSpan.getDirection())) {
        //different directions
        return false;
    }/* w  ww . ja v  a2  s .  c  o m*/

    //one of the spans uses manual Time (new intersect)
    Range<Long> thisSpan = this.getSpan();
    Range<Long> theOtherSpan = pSpan.getSpan();

    if (this.isValidAtEveryDay() || pSpan.isValidAtEveryDay()) {
        if (this.isValidAtSpecificDay() || pSpan.isValidAtSpecificDay()) {
            //remove day Information
            Long thisStart = DateUtils.getFragmentInMilliseconds(new Date(thisSpan.getMinimum()),
                    Calendar.DATE);
            Long thisEnd = DateUtils.getFragmentInMilliseconds(new Date(thisSpan.getMaximum()), Calendar.DATE);
            thisSpan = Range.between(thisStart, thisEnd);

            Long otherStart = DateUtils.getFragmentInMilliseconds(new Date(theOtherSpan.getMinimum()),
                    Calendar.DATE);
            Long otherEnd = DateUtils.getFragmentInMilliseconds(new Date(theOtherSpan.getMaximum()),
                    Calendar.DATE);

            theOtherSpan = Range.between(otherStart, otherEnd);

            return thisSpan.isOverlappedBy(theOtherSpan);
        } else if (this.isValidAtEveryDay() && pSpan.isValidAtEveryDay()) {
            //both valid at every Day - just compare spans
            return thisSpan.isOverlappedBy(theOtherSpan);
        } else {
            //one span is for everyDay the other is over multiple Days
            //manual intersect
            Range<Long> always;
            Range<Long> manual;
            if (this.isValidAtEveryDay()) {
                always = thisSpan;
                manual = theOtherSpan;
            } else {
                always = theOtherSpan;
                manual = thisSpan;
            }

            long manualDate = DateUtils.truncate(new Date(manual.getMinimum()), Calendar.DATE).getTime();
            long manualStart = manual.getMinimum() - manualDate;
            long manualEnd = manual.getMaximum() - manualDate;

            if (manualEnd - manualStart > DateUtils.MILLIS_PER_DAY) {
                //must intersect somehow because span is longer than 1 Day
                return true;
            }
            //direct intersection
            manual = Range.between(manualStart, manualEnd);
            if (always.isOverlappedBy(manual))
                return true;

            //should not be possible, because it should be handeld by isValidAtSpecificDay
            if (manualEnd <= DateUtils.MILLIS_PER_DAY)
                return false;

            //maybe intersection at next day
            manual = Range.between(new Long(0), manualEnd - DateUtils.MILLIS_PER_DAY);
            return always.isOverlappedBy(manual);
        }
    }

    return thisSpan.isOverlappedBy(theOtherSpan);
}

From source file:de.tor.tribes.ui.windows.ReportRulesDialog.java

private void fireAddRuleEvent(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fireAddRuleEvent

    Component c = jRuleSettingsPanel.getComponent(0);
    String targetReportSet = jTargetReportSet.getText();
    if (targetReportSet == null || targetReportSet.length() == 0) {
        return;//  w  ww.jav  a  2 s.co  m
    }
    try {
        ReportRule rule;
        if (c == jReportColorPanel) {
            Integer value = 0;
            value += (jGreyBox.isSelected()) ? ReportRule.GREY : 0;
            value += (jBlueBox.isSelected()) ? ReportRule.BLUE : 0;
            value += (jGreenBox.isSelected()) ? ReportRule.GREEN : 0;
            value += (jYellowBox.isSelected()) ? ReportRule.YELLOW : 0;
            value += (jRedBox.isSelected()) ? ReportRule.RED : 0;
            rule = new ReportRule(ReportRule.RuleType.COLOR, value, targetReportSet);
        } else if (c == jDatePanel) {
            Range<Long> span = Range.between(jMinDate.getDate().getTime(),
                    jMaxDate.getDate().getTime() + DateUtils.MILLIS_PER_DAY);
            rule = new ReportRule(ReportRule.RuleType.DATE, span, targetReportSet);
        } else if (c == jAgePanel) {
            long val;
            try {
                val = Long.parseLong(jMaxAge.getText());
            } catch (Exception e) {
                val = 365;
            }
            val = val * DateUtils.MILLIS_PER_DAY;
            rule = new ReportRule(ReportRule.RuleType.AGE, val, targetReportSet);
        } else if (c == jAttackerPanel) {
            List<Tribe> tribeList = new ArrayList<>();

            for (String tribe : jAttackerTextArea.getText().split(";")) {
                Tribe t = DataHolder.getSingleton().getTribeByName(tribe);
                if (t != null) {
                    tribeList.add(t);
                }
            }
            rule = new ReportRule(ReportRule.RuleType.ATTACKER_TRIBE, tribeList, targetReportSet);
        } else if (c == jDefenderPanel) {
            List<Tribe> tribeList = new ArrayList<>();

            for (String tribe : jDefenderTextArea.getText().split(";")) {
                Tribe t = DataHolder.getSingleton().getTribeByName(tribe);
                if (t != null) {
                    tribeList.add(t);
                }
            }
            rule = new ReportRule(ReportRule.RuleType.DEFENDER_TRIBE, tribeList, targetReportSet);
        } else if (c == jAttackerAllyPanel) {
            List<Ally> allyList = new ArrayList<>();

            for (String ally : jAttackerAllyTextArea.getText().split(";")) {
                Ally a = DataHolder.getSingleton().getAllyByName(ally);
                if (a != null) {
                    allyList.add(a);
                }
            }
            rule = new ReportRule(ReportRule.RuleType.ATTACKER_ALLY, allyList, targetReportSet);
        } else if (c == jDefenderAllyPanel) {
            List<Ally> allyList = new ArrayList<>();

            for (String ally : jDefenderAllyTextArea.getText().split(";")) {
                Ally a = DataHolder.getSingleton().getAllyByName(ally);
                if (a != null) {
                    allyList.add(a);
                }
            }
            rule = new ReportRule(ReportRule.RuleType.DEFENDER_ALLY, allyList, targetReportSet);
        } else {
            //no settings panel
            if (jNoSettingsType.getText().equals("OFF")) {
                rule = new ReportRule(ReportRule.RuleType.OFF, null, targetReportSet);
            } else if (jNoSettingsType.getText().equals("FAKE")) {
                rule = new ReportRule(ReportRule.RuleType.FAKE, null, targetReportSet);
            } else if (jNoSettingsType.getText().equals("SNOB")) {
                rule = new ReportRule(ReportRule.RuleType.CONQUERED, null, targetReportSet);
            } else if (jNoSettingsType.getText().equals("WALL")) {
                rule = new ReportRule(ReportRule.RuleType.WALL, null, targetReportSet);
            } else if (jNoSettingsType.getText().equals("BUILDING")) {
                rule = new ReportRule(ReportRule.RuleType.CATA, null, targetReportSet);
            } else {
                logger.warn("Reached unreachable code part");
                return;
            }
        }

        ReportManager.getSingleton().addRule(rule);
        rebuildRuleList();
    } catch (IllegalArgumentException e) {
        logger.debug("Failed to create Rule", e);
        String message = "Regel konnte nicht erstellt werden.\nBitte prfe die Einstellungen.";
        if (e.getMessage() != null) {
            message += "\n\nFehler: " + e.getMessage();
        }
        JOptionPaneHelper.showWarningBox(this, message, "Warnung");
    }
}

From source file:de.tor.tribes.ui.views.DSWorkbenchSOSRequestAnalyzer.java

private static void createSampleRequests() {
    int wallLevel = 20;
    int supportCount = 20;
    int maxAttackCount = 10;
    int maxFakeCount = 0;

    Village[] villages = GlobalOptions.getSelectedProfile().getTribe().getVillageList();
    Village[] attackerVillages = DataHolder.getSingleton().getTribeByName("Alexander25").getVillageList();

    for (int i = 0; i < supportCount; i++) {
        int id = (int) Math.rint(Math.random() * (villages.length - 1));
        Village target = villages[id];/*from  w  ww .  j  av  a  2 s  . c  o m*/
        SOSRequest r = new SOSRequest(target.getTribe());
        TargetInformation info = r.addTarget(target);
        info.setWallLevel(wallLevel);

        TroopAmountFixed troops = new TroopAmountFixed();
        troops.setAmountForUnit("spear", (int) Math.rint(Math.random() * 14000));
        troops.setAmountForUnit("sword", (int) Math.rint(Math.random() * 14000));
        troops.setAmountForUnit("heavy", (int) Math.rint(Math.random() * 5000));
        info.setTroops(troops);

        int cnt = (int) Math.rint(maxAttackCount * Math.random());
        for (int j = 0; j < cnt; j++) {
            int idx = (int) Math.rint(Math.random() * (attackerVillages.length - 2));
            Village v = attackerVillages[idx];
            info.addAttack(v, new Date(
                    System.currentTimeMillis() + Math.round(DateUtils.MILLIS_PER_DAY * 7 * Math.random())));
            for (int k = 0; k < (int) Math.rint(maxFakeCount * Math.random()); k++) {
                idx = (int) Math.rint(Math.random() * (attackerVillages.length - 2));
                v = attackerVillages[idx];
                info.addAttack(v, new Date(System.currentTimeMillis() + Math.round(3600 * Math.random())));
            }
        }
        SOSManager.getSingleton().addRequest(r);
    }
}

From source file:de.tor.tribes.ui.views.DSWorkbenchStatsFrame.java

private void fireChangeStatTimeEvent(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fireChangeStatTimeEvent
    if (evt.getSource() == jWeeklyStats) {
        //remove one week from end date
        long oneWeek = DateUtils.MILLIS_PER_DAY * 7;// 1000l * 60l * 60l * 24l * 7l;
        Date end = new Date();//jEndDate.getSelectedDate();
        jEndDate.setDate(end);/*from   w  w  w.  ja v  a  2 s. co m*/
        //long start = end.getTime() - oneWeek;
        jStartDate.setDate(new Date(end.getTime() - oneWeek));
    } else {
        //remove one month from end date
        long oneMonth = DateUtils.MILLIS_PER_DAY * 31;// 1000l * 60l * 60l * 24l * 31l;
        Date end = new Date();//jEndDate.getSelectedDate();
        jEndDate.setDate(end);
        //  long start = end.getTime() - oneMonth;
        jStartDate.setDate(new Date(end.getTime() - oneMonth));
    }
}

From source file:jproxy.ProxyControl.java

/**
 * Initialise the user-provided keystore
 *///from  ww  w .j a v  a  2 s.c  o  m
private void initUserKeyStore() {
    try {
        keyStore = getKeyStore(storePassword.toCharArray());
        X509Certificate caCert = (X509Certificate) keyStore.getCertificate(CERT_ALIAS);
        if (caCert == null) {
            log.error("Could not find key with alias " + CERT_ALIAS);
            keyStore = null;
        } else {
            caCert.checkValidity(new Date(System.currentTimeMillis() + DateUtils.MILLIS_PER_DAY));
        }
    } catch (Exception e) {
        keyStore = null;
        log.error(
                "Could not open keystore or certificate is not valid " + CERT_PATH_ABS + " " + e.getMessage());
    }
}