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:com.nridge.core.base.std.Sleep.java

public static void forDays(int aDays) {
    forMilliseconds(aDays * DateUtils.MILLIS_PER_DAY);
}

From source file:net.larry1123.util.api.time.StringTime.java

/**
 * Takes just a number or a set of numbers with a D, H, M or, S fallowing it
 * The letters can be upper or lower case
 * 15h 50m 5s//from   ww w .  ja va 2s  .  co  m
 *
 * @param string Whole String to decode into parts
 *
 * @return the amount of time in milliseconds that the time string Decodes to
 */
public static long millisecondsFromString(String string) {
    if (string == null) {
        throw new NullPointerException("String can not be null");
    }
    string = string.trim();
    long ret = 0;
    try {
        ret = Long.parseLong(string);
    } catch (NumberFormatException e) {
        for (String part : string.split(" ")) {
            if (part.length() >= 2) {
                String time = part.substring(part.length() - 1);
                switch (Part.getFromString(time)) {
                case DAYS:
                    try {
                        Long days = Long.parseLong(part.substring(0, part.length() - 1));
                        ret += days * DateUtils.MILLIS_PER_DAY;
                    } catch (NumberFormatException error) {
                        // DO nothing right now
                    }
                    break;
                case HOUR:
                    try {
                        Long hours = Long.parseLong(part.substring(0, part.length() - 1));
                        ret += hours * DateUtils.MILLIS_PER_HOUR;
                    } catch (NumberFormatException error) {
                        // DO nothing right now
                    }
                    break;
                case MINUTES:
                    try {
                        Long minutes = Long.parseLong(part.substring(0, part.length() - 1));
                        ret += minutes * DateUtils.MILLIS_PER_MINUTE;
                    } catch (NumberFormatException error) {
                        // DO nothing right now
                    }
                    break;
                case SECONDS:
                    try {
                        Long seconds = Long.parseLong(part.substring(0, part.length() - 1));
                        ret += seconds * DateUtils.MILLIS_PER_SECOND;
                    } catch (NumberFormatException error) {
                        // DO nothing right now
                    }
                    break;
                default:
                    // Something is malformed just let it fly by and keep going
                    break;
                }
            } else if (part.length() == 1) {
                switch (Part.getFromString("" + part.charAt(1))) {
                case DAYS:
                    ret += DateUtils.MILLIS_PER_DAY;
                    break;
                case HOUR:
                    ret += DateUtils.MILLIS_PER_HOUR;
                    break;
                case MINUTES:
                    ret += DateUtils.MILLIS_PER_MINUTE;
                    break;
                case SECONDS:
                    ret += DateUtils.MILLIS_PER_SECOND;
                    break;
                default:
                    // Something is malformed just let it fly by and keep going
                    break;
                }
            }
        }
    }
    return ret;
}

From source file:com.creditcloud.carinsurance.local.CarInsuranceFeeLocalBean.java

/**
 * ?/*from   www  . ja va 2 s . c o m*/
 * @param repayment
 * @return 
 */
public BigDecimal overdueFee(CarInsuranceRepayment repayment) {
    if (repayment == null) {
        return BigDecimal.ZERO;
    }
    if (LocalDate.now().toDate().compareTo(repayment.getDueDate()) <= 0) {
        return BigDecimal.ZERO;
    }
    BigDecimal days = BigDecimal.ZERO;
    //
    if (repayment.getRepayDate() != null) {
        long repayTime = repayment.getRepayDate().getTime();
        long dueTime = repayment.getDueDate().getTime();
        days = BigDecimal.valueOf((repayTime - dueTime) / DateUtils.MILLIS_PER_DAY);
        if (days.compareTo(BigDecimal.ZERO) < 0) {
            return BigDecimal.ZERO;
        }
    } else {
        long nowTime = LocalDate.now().plusDays(1).toDate().getTime();
        long dueTime = repayment.getDueDate().getTime();
        days = BigDecimal.valueOf((nowTime - dueTime) / DateUtils.MILLIS_PER_DAY);
    }
    BigDecimal penaltyAmount = BigDecimal.ZERO;
    //???
    Fee overduePenaltyFee = configManager.getCarInsuranceConfig().getPenaltyFee();
    penaltyAmount = FeeUtils.calculate(overduePenaltyFee, repayment.getAmountPrincipal()).multiply(days)
            .setScale(NumberConstant.DEFAULT_SCALE, NumberConstant.ROUNDING_MODE);
    return penaltyAmount;
}

From source file:de.tor.tribes.ui.renderer.DateCellRenderer.java

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {
    Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    JLabel label = (JLabel) c;
    try {/*from  w  w  w.  j av  a 2  s.com*/
        long val = ((Date) value).getTime();
        if (val > System.currentTimeMillis() - DateUtils.MILLIS_PER_DAY * 365 * 10) {//more than ten year ago...invalid!
            label.setText((value == null) ? "" : specialFormat.format(value));
        } else {
            label.setText("-");
        }
    } catch (Exception e) {
        label.setText("-");
    }

    return label;
}

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

private static String format(Locale locale, long duration, boolean islong, int maxUnits) {
    int max = Integer.MAX_VALUE;
    if (maxUnits > 0) {
        max = maxUnits;/*from  www  .j a  v a 2  s  . com*/
    }
    long days = duration / DateUtils.MILLIS_PER_DAY;
    long accountedMillis = days * DateUtils.MILLIS_PER_DAY;
    long hours = (duration - accountedMillis) / DateUtils.MILLIS_PER_HOUR;
    accountedMillis += (hours * DateUtils.MILLIS_PER_HOUR);
    long mins = (duration - accountedMillis) / DateUtils.MILLIS_PER_MINUTE;
    accountedMillis += (mins * DateUtils.MILLIS_PER_MINUTE);
    long secs = (duration - accountedMillis) / DateUtils.MILLIS_PER_SECOND;
    StringBuilder b = new StringBuilder();
    int unitCount = 0;
    // days
    if (days > 0) {
        b.append(getString(locale, days, "day", islong));
        unitCount++;
    }
    // hours
    if ((hours > 0 || b.length() > 0) && unitCount < max) {
        b.append(getString(locale, hours, "hour", islong));
        unitCount++;
    }
    // minutes
    if ((mins > 0 || b.length() > 0) && unitCount < max) {
        b.append(getString(locale, mins, "minute", islong));
        unitCount++;
    }
    // seconds
    if (unitCount < max) {
        b.append(getString(locale, secs, "second", islong));
    }
    return b.toString().trim();
}

From source file:TestDataDistributionDaoImpl.java

public void test() throws Exception {
    System.setProperty("config.resource", "/application.local.conf");
    Config config = ConfigFactory.load();
    String eagleServiceHost = config.getString(EagleConfigConstants.EAGLE_PROPS + "."
            + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.HOST);
    Integer eagleServicePort = config.getInt(EagleConfigConstants.EAGLE_PROPS + "."
            + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.PORT);
    String username = config.getString(EagleConfigConstants.EAGLE_PROPS + "."
            + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.USERNAME);
    String password = config.getString(EagleConfigConstants.EAGLE_PROPS + "."
            + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.PASSWORD);
    String topic = config.getString("dataSourceConfig.topic");
    DataDistributionDao dao = new DataDistributionDaoImpl(eagleServiceHost, eagleServicePort, username,
            password, topic);//from   w ww. ja  v a 2 s  .c o  m
    dao.fetchDataDistribution(System.currentTimeMillis() - 2 * DateUtils.MILLIS_PER_DAY,
            System.currentTimeMillis());
}

From source file:io.wcm.dam.assetservice.impl.dataversion.ChecksumDataVersionStrategyTest.java

@Before
public void setUp() throws Exception {

    // create some sample assets with SHA-1 checksums
    asset11 = context.create().asset(VALID_PATH_1 + "/asset11", 100, 50, ContentType.JPEG);
    setLastModified(asset11, 15 * DateUtils.MILLIS_PER_DAY);
    asset12 = context.create().asset(VALID_PATH_1 + "/asset12", 100, 50, ContentType.JPEG);
    setLastModified(asset12, 16 * DateUtils.MILLIS_PER_DAY);
    asset21 = context.create().asset(VALID_PATH_2 + "/asset21", 100, 50, ContentType.JPEG);
    setLastModified(asset21, 17 * DateUtils.MILLIS_PER_DAY);

    ResourceResolverFactory resourceResolverFactory = context.getService(ResourceResolverFactory.class);
    underTest = new DamPathHandler(new String[] { VALID_PATH_1, VALID_PATH_2 },
            ChecksumDataVersionStrategy.STRATEGY, 1, resourceResolverFactory);

    // wait until first data versions are generated
    Thread.sleep(500);//from www. ja  v  a 2s  .com
}

From source file:TestGreedyPartition.java

public void test() throws Exception {
    System.setProperty("config.resource", "/application.local.conf");
    Config config = ConfigFactory.load();
    String host = config.getString(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE
            + "." + EagleConfigConstants.HOST);
    Integer port = config.getInt(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE
            + "." + EagleConfigConstants.PORT);
    String username = config.getString(EagleConfigConstants.EAGLE_PROPS + "."
            + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.USERNAME);
    String password = config.getString(EagleConfigConstants.EAGLE_PROPS + "."
            + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.PASSWORD);
    String topic = config.getString("dataSourceConfig.topic");
    DataDistributionDao dao = new DataDistributionDaoImpl(host, port, username, password, topic);
    PartitionAlgorithm algorithm = new GreedyPartitionAlgorithm();
    algorithm.partition(dao.fetchDataDistribution(System.currentTimeMillis() - 2 * DateUtils.MILLIS_PER_DAY,
            System.currentTimeMillis()), 4);
}

From source file:de.tor.tribes.ui.wiz.dep.DefensePlanerWizard.java

private static List<SOSRequest> createSampleRequests() {
    int wallLevel = 20;
    int supportCount = 100;
    int maxAttackCount = 50;
    int maxFakeCount = 0;

    List<SOSRequest> result = new LinkedList<>();
    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  w  w  .  j  av a 2s.c  o  m*/
        SOSRequest r = new SOSRequest(target.getTribe());
        r.addTarget(target);
        TargetInformation info = r.getTargetInformation(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())));
            }
        }
        result.add(r);
    }

    return result;
}

From source file:io.wcm.dam.assetservice.impl.dataversion.ChecksumDataVersionStrategyTest.java

@Test
public void testNewDataVersionOnValidPathEvent() throws Exception {
    String dataVersion1 = underTest.getDataVersion(VALID_PATH_1);
    String dataVersion2 = underTest.getDataVersion(VALID_PATH_2);
    assertNotNull(dataVersion1);/* w w w .  j a  v  a  2s .c  om*/

    setLastModified(asset11, 30 * DateUtils.MILLIS_PER_DAY);
    underTest.handleDamEvent(DamEvent.metadataUpdated(asset11.getPath(), null));

    // data version is generated asynchronously
    Thread.sleep(1000);

    // data version for path 1 should be changed
    String dataVersion1a = underTest.getDataVersion(VALID_PATH_1);
    assertNotNull(dataVersion1a);
    assertNotEquals("data version 1 changed", dataVersion1, dataVersion1a);

    // data version for path 2 should not be unchanged
    String dataVersion2a = underTest.getDataVersion(VALID_PATH_2);
    assertNotNull(dataVersion2a);
    assertEquals("data version 2 unchanged", dataVersion2, dataVersion2a);

    // wait a bit more and test again
    Thread.sleep(1000);

    // data version for path 1 should not be changed
    String dataVersion1b = underTest.getDataVersion(VALID_PATH_1);
    assertNotNull(dataVersion1b);
    assertEquals("data version 1 changed", dataVersion1a, dataVersion1b);

    // data version for path 2 should not be unchanged
    String dataVersion2b = underTest.getDataVersion(VALID_PATH_2);
    assertNotNull(dataVersion2b);
    assertEquals("data version 2 unchanged", dataVersion2a, dataVersion2b);

}