Example usage for org.joda.time DateTime getMillisOfDay

List of usage examples for org.joda.time DateTime getMillisOfDay

Introduction

In this page you can find the example usage for org.joda.time DateTime getMillisOfDay.

Prototype

public int getMillisOfDay() 

Source Link

Document

Get the millis of day field value.

Usage

From source file:org.wso2.strategy.poc.webartifact.WebArtifactHandler.java

License:Open Source License

public boolean deploy(String tenant, String appName, Path artifactPath, String version, int replicas)
        throws WebArtifactHandlerException {
    String componentName = WebArtifactHandlerHelper.generateKubernetesComponentIdentifier(tenant, appName);
    String dockerImageName;//from   w  w w . j  ava2s .c  o m
    try {
        if (imageBuilder.getExistingImages(tenant, appName, version).size() == 0) {
            // append build date and time to major version
            DateTime dateTime = new DateTime();
            String now = dateTime.getYear() + "-" + dateTime.getMonthOfYear() + "-" + dateTime.getDayOfMonth()
                    + "-" + dateTime.getMillisOfDay();
            version += ("-" + now);
            dockerImageName = imageBuilder.buildImage(tenant, appName, version, artifactPath);
            Thread.sleep(IMAGE_BUILD_DELAY_IN_MILLISECONDS);
            replicationControllerHandler.createReplicationController(componentName, componentName,
                    dockerImageName, replicas);
            serviceHandler.createService(componentName, componentName);
            return true;
        } else {
            return false;
        }
    } catch (Exception exception) {
        String message = String.format("Failed to deploy web artifact[web-artifact]: %s",
                artifactPath.toString());
        LOG.error(message, exception);
        throw new WebArtifactHandlerException(message, exception);
    }
}

From source file:org.wso2.strategy.poc.webartifact.WebArtifactHandler.java

License:Open Source License

public boolean rollUpdate(String tenant, String appName, String version, Path artifactPath)
        throws WebArtifactHandlerException {
    String componentName = WebArtifactHandlerHelper.generateKubernetesComponentIdentifier(tenant, appName);
    if ((imageBuilder.getExistingImages(tenant, appName, version).size() > 0)) {
        DateTime dateTime = new DateTime();
        String now = dateTime.getYear() + "-" + dateTime.getMonthOfYear() + "-" + dateTime.getDayOfMonth() + "-"
                + dateTime.getMillisOfDay();
        version += ("-" + now);
        String dockerImageName = imageBuilder.buildImage(tenant, appName, version, artifactPath);
        replicationControllerHandler.updateImage(componentName, dockerImageName);
        podHandler.deleteReplicaPods(//from w w w .  j  a  v a  2s  . c  o m
                replicationControllerHandler.getReplicationController(
                        WebArtifactHandlerHelper.generateKubernetesComponentIdentifier(tenant, appName)),
                tenant, appName);
        return true;
    } else {
        return false;
    }
}

From source file:przypominacz.AbstractService.java

@Override
public void run() {
    reloadConfiguration();//from www  . ja  va 2  s. co m
    while (!isInterrupted() && !isExit()) {
        DateTime now = new DateTime();
        if (lastConfiguration.getTime() + confWaitTime < now.getMillis()) {
            reloadConfiguration();
        }
        if (now.getMillisOfDay() > startTime.getTime() && now.getMillisOfDay() < endTime.getTime()) {
            if (!running) {
                try {
                    setRunning(true);
                    startObject();
                } catch (Throwable t) {
                    t.printStackTrace();
                    logger.error(t);
                } finally {
                    setRunning(false);
                    try {
                        synchronized (lock) {
                            logger.debug("AbstractService: It's : " + new DateTime() + " i'm going sleep to "
                                    + new DateTime().plus(waitTime));
                            lock.wait(waitTime);
                            lock.notify();
                        }
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                        logger.error(e);
                    }
                }
            }
        }
    }
}

From source file:rapture.dp.invocable.CheckPrerequisiteStep.java

License:Open Source License

private DateTime getDateTime(DateTime dateTime, String dateWithin, String timeNoEarlierThan) {
    if (!StringUtils.isEmpty(timeNoEarlierThan)) {
        DateTime hours = getDateTime(timeNoEarlierThan);
        if (dateTime == null)
            dateTime = hours;//  w ww  .  j  a va  2  s .  c  om
        else {
            dateTime = dateTime.withMillisOfDay(hours.getMillisOfDay()).withZone(hours.getZone());
        }
    }
    if (!StringUtils.isEmpty(dateWithin)) {
        int number = Integer.valueOf(dateWithin.substring(0, dateWithin.length() - 1));
        char dateUnit = dateWithin.charAt(dateWithin.length() - 1);
        switch (dateUnit) {
        case 'M':
            dateTime = dateTime.minusMonths(number);
            break;
        case 'W':
            dateTime = dateTime.minusWeeks(number);
            break;
        case 'D':
            dateTime = dateTime.minusDays(number);
            break;
        case 'H':
            dateTime = dateTime.minusHours(number);
            break;
        case 'B':
            dateTime = USCalendar.minusBusinessDays(dateTime, number);
            break;
        default:
            throw RaptureExceptionFactory.create("Invalid date unit " + dateUnit);
        }
    }
    return dateTime;
}

From source file:swrbPointCase.ShortwaveRadiationBalancePointCase.java

License:GNU General Public License

/**
 * getHourAngle is the value of the hour angle at a given time and latitude (Corripio (2003))
 * /* w w  w  .ja va  2  s  .co m*/
 *
 * @param date is the current date
 * @param latitude is the latitude of the station
 * @return the double value of the hour angle
 */
private double getHourAngle(DateTime date, double latitude) {
    int day = date.getDayOfYear();

    hour = (doHourly == true) ? (double) date.getMillisOfDay() / (1000 * 60 * 60) : 12.5;

    // (360 / 365.25) * (day - 79.436) is the number of the day 
    double dayangb = Math.toRadians((360 / 365.25) * (day - 79.436));

    // Evaluate the declination of the sun.
    delta = Math.toRadians(.3723 + 23.2567 * Math.sin(dayangb) - .758 * Math.cos(dayangb)
            + .1149 * Math.sin(2 * dayangb) + .3656 * Math.cos(2 * dayangb) - .1712 * Math.sin(3 * dayangb)
            + .0201 * Math.cos(3 * dayangb));

    // ss is the absolute value of the hour angle at sunrise or sunset      
    double ss = Math.acos(-Math.tan(delta) * Math.tan(latitude));
    sunrise = 12 * (1.0 - ss / Math.PI);
    sunset = 12 * (1.0 + ss / Math.PI);

    if (hour > (sunrise) && hour < (sunset) & (hour - sunrise) < 0.01)
        hour = hour + 0.1;
    if (hour > (sunrise) && hour < (sunset) & (sunset - hour) < 0.01)
        hour = hour - 0.1;

    //the hour angle is zero at noon and has the following value in radians at any time t
    // given in hours and decimal fraction:
    double hourangle = (hour / 12.0 - 1.0) * Math.PI;
    return hourangle;

}

From source file:swrbRasterCase.ShortwaveRadiationBalanceRasterCase.java

License:Open Source License

/**
 * getHourAngle is the value of the hour angle at a given time and latitude (Corripio (2003))
 * /*from w w w .  j  a  v  a 2  s .c om*/
 *
 * @param date is the current date
 * @param latitude is the latitude of the station
 * @return the double value of the hour angle
 */
private double getHourAngle(DateTime date, double latitude) {
    int day = date.getDayOfYear();
    hour = (doHourly == true) ? (double) date.getMillisOfDay() / (1000 * 60 * 60) : 12.5;

    // (360 / 365.25) * (day - 79.436) is the number of the day 
    double dayangb = Math.toRadians((360 / 365.25) * (day - 79.436));

    // Evaluate the declination of the sun.
    delta = Math.toRadians(.3723 + 23.2567 * Math.sin(dayangb) - .758 * Math.cos(dayangb)
            + .1149 * Math.sin(2 * dayangb) + .3656 * Math.cos(2 * dayangb) - .1712 * Math.sin(3 * dayangb)
            + .0201 * Math.cos(3 * dayangb));

    // ss is the absolute value of the hour angle at sunrise or sunset
    double ss = Math.acos(-Math.tan(delta) * Math.tan(latitude));
    sunrise = 12 * (1.0 - ss / Math.PI);
    sunset = 12 * (1.0 + ss / Math.PI);

    if (hour > (sunrise) && hour < (sunset) & (hour - sunrise) < 0.01)
        hour = hour + 0.1;
    if (hour > (sunrise) && hour < (sunset) & (sunset - hour) < 0.01)
        hour = hour - 0.1;

    //the hour angle is zero at noon and has the following value in radians at any time t
    // given in hours and decimal fraction:
    double hourangle = (hour / 12.0 - 1.0) * Math.PI;
    return hourangle;

}