Example usage for org.joda.time DateTime withTimeAtStartOfDay

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

Introduction

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

Prototype

public DateTime withTimeAtStartOfDay() 

Source Link

Document

Returns a copy of this datetime with the time set to the start of the day.

Usage

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/** ?     */
public static DateTime getDate(DateTime moment) {
    return moment.withTimeAtStartOfDay();
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/** ???  */
public static boolean hasDate(DateTime moment) {
    return moment.withTimeAtStartOfDay().getMillis() > 0;
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/**
 * Sets time.//  w w  w .  j  a  va  2  s  .com
 *
 * @param moment the moment
 * @param millis the millis
 * @return the time
 */
public static DateTime setTime(DateTime moment, int millis) {
    return moment.withTimeAtStartOfDay().plusMillis(millis);
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/**
 * Sets time./*from   ww w  .j  av  a2 s  .c  o  m*/
 *
 * @param moment       the moment
 * @param hourOfDay    the hour of day
 * @param minuteOfHour the minute of hour
 * @return the time
 */
public static DateTime setTime(DateTime moment, int hourOfDay, int minuteOfHour) {
    return moment.withTimeAtStartOfDay().withTime(hourOfDay, minuteOfHour, 0, 0);
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/**
 * Sets time./*  w  w  w.  ja  v  a  2  s  .  c  o  m*/
 *
 * @param moment         the moment
 * @param hourOfDay      the hour of day
 * @param minuteOfHour   the minute of hour
 * @param secondOfMinute the second of minute
 * @return the time
 */
public static DateTime setTime(DateTime moment, int hourOfDay, int minuteOfHour, int secondOfMinute) {
    return moment.withTimeAtStartOfDay().withTime(hourOfDay, minuteOfHour, secondOfMinute, 0);
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/**
 * Sets time./*  ww w.  j a v a  2 s .c  om*/
 *
 * @param moment         the moment
 * @param hourOfDay      the hour of day
 * @param minuteOfHour   the minute of hour
 * @param secondOfMinute the second of minute
 * @param millisOfSecond the millis of second
 * @return the time
 */
public static DateTime setTime(DateTime moment, int hourOfDay, int minuteOfHour, int secondOfMinute,
        int millisOfSecond) {
    return moment.withTimeAtStartOfDay().withTime(hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond);
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/**  */
public static DateTime noon(DateTime moment) {
    return moment.withTimeAtStartOfDay().plusHours(12);
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/**  ? ?(Day) . */
public static List<ITimePeriod> foreachDays(ITimePeriod period) {
    shouldNotBeNull(period, "period");
    if (isTraceEnabled)
        log.trace("[{}]?  ?(Day)  ...", period);

    List<ITimePeriod> days = Lists.newArrayList();
    if (period.isAnytime())
        return days;

    assertHasPeriod(period);/* w  w w  .j av  a2  s .c om*/

    if (Times.isSameDay(period.getStart(), period.getEnd())) {
        days.add(new TimeRange(period));
        return days;
    }

    days.add(new TimeRange(period.getStart(), Times.endTimeOfDay(period.getStart())));

    DateTime endDay = period.getEnd().withTimeAtStartOfDay();
    DateTime current = period.getStart().withTimeAtStartOfDay().plusDays(1);
    ITimeCalendar calendar = TimeCalendar.getDefault();

    while (current.compareTo(endDay) < 0) {
        days.add(Times.getDayRange(current, calendar));
        current = current.plusDays(1);
    }
    if (period.getEnd().getMillisOfDay() > 0)
        days.add(new TimeRange(endDay.withTimeAtStartOfDay(), period.getEnd()));

    return days;
}

From source file:net.es.enos.esnet.OSCARSTopologyPublisher.java

License:Open Source License

public boolean isToday() {
    DateTime now = DateTime.now();
    return this.date.withTimeAtStartOfDay().isEqual(now.withTimeAtStartOfDay());
}

From source file:nl.welteninstituut.tel.la.importers.fitbit.FitbitTask.java

License:Open Source License

@Override
public void run() {
    try {/*from ww  w. jav  a 2s .  c om*/
        OauthServiceAccount account = getAccount(AccountJDO.FITBITCLIENT, accountId);
        if (account != null) {

            if (start == null) {

                if (account.getLastSynced() == null) {
                    String startDate = Configuration.get(Configuration.STARTDATE);
                    if (startDate != null) {
                        start = new DateTime(startDate + "T00:00");
                    } else {
                        LOG.severe(Configuration.STARTDATE + " is missing from configuration");
                    }
                } else {
                    start = new DateTime(account.getLastSynced()).withSecondOfMinute(0).withMillisOfSecond(0)
                            .plusMinutes(1);
                }
            }

            if (deviceLastSynced == null) {
                deviceLastSynced = getDeviceLastSynced(account);
            }

            if (start != null && deviceLastSynced != null && start.isBefore(deviceLastSynced)) {

                DateTime end = start.plusHours(4);
                if (end.isAfter(deviceLastSynced)) {
                    end = new DateTime(deviceLastSynced).withSecondOfMinute(0).withMillisOfSecond(0)
                            .plusMinutes(1);
                }

                // check if the period spans to next day
                if (end.getDayOfMonth() != start.getDayOfMonth()) {
                    // if so reset to start of day because heart rate can
                    // only
                    // be retrieved for a single calendar day
                    end = end.withTimeAtStartOfDay();
                }

                System.out.println("processing from " + start + " to " + end);

                JSONObject stepCountData = new JSONObject(readURL(getStepcountURL(start, end), account));
                JSONObject heartRateData = new JSONObject(readURL(getHeartrateURL(start, end), account));

                if (!stepCountData.has("errors") && !heartRateData.has("errors")) {
                    AccountJDO pa = AccountManager.getAccount(account.getPrimaryAccount());
                    String mbox = pa != null ? pa.getEmail() : null;

                    String xapiTemplate = "{\"timestamp\":\"%s\","
                            + "\"actor\": {\"objectType\": \"Agent\",\"mbox\":\"mailto:" + mbox + "\"},"
                            + "\"verb\":{\"id\":\"https://brindlewaye.com/xAPITerms/verbs/walked\","
                            + "\"display\":{\"en-US\":\"indicates the user walked number of steps\"}},"
                            + "\"object\":{\"objectType\":\"Activity\",\"id\":\"StepCount\",\"definition\":{\"name\":{\"en-US\":\"step count\"},"
                            + "\"description\":{\"en-US\":\"step count\"},\"type\":\"http://activitystrea.ms/schema/1.0/event\"}},"
                            + "\"result\":{\"response\":\"%d\"}}";

                    processData(stepCountData, "activities-steps", xapiTemplate);

                    xapiTemplate = "{\"timestamp\":\"%s\","
                            + "\"actor\": {\"objectType\": \"Agent\",\"mbox\":\"mailto:" + mbox + "\"},"
                            + "\"verb\":{\"id\":\"http://adlnet.gov/expapi/verbs/experienced\","
                            + "\"display\":{\"en-US\":\"indicates the user experienced something\"}},"
                            + "\"object\":{\"objectType\":\"Activity\",\"id\":\"HeartRate\",\"definition\":{\"name\":{\"en-US\":\"heart rate\"},"
                            + "\"description\":{\"en-US\":\"heart rate\"},\"type\":\"http://activitystrea.ms/schema/1.0/event\"}},"
                            + "\"result\":{\"response\":\"%d\"}}";

                    processData(heartRateData, "activities-heart", xapiTemplate);
                }

                // store time of last block data that was
                // synchronized
                account.setLastSynced(end.toDate());
                OauthServiceAccountManager.updateOauthServiceAccount(account);

                // Daisy chain task for next period
                if (end.isBefore(deviceLastSynced)) {
                    ImportTask.scheduleTask(new FitbitTask(accountId, end, deviceLastSynced));
                }
            }

        } else {
            LOG.severe("no fitbit service account found for " + accountId);
        }
    } catch (JSONException | IOException e) {
        LOG.severe("aborting fitbit import for " + accountId + " reason: " + e.getMessage());
    }

}