當前位置: 首頁>>代碼示例>>Java>>正文


Java DateTime.plusWeeks方法代碼示例

本文整理匯總了Java中org.joda.time.DateTime.plusWeeks方法的典型用法代碼示例。如果您正苦於以下問題:Java DateTime.plusWeeks方法的具體用法?Java DateTime.plusWeeks怎麽用?Java DateTime.plusWeeks使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.joda.time.DateTime的用法示例。


在下文中一共展示了DateTime.plusWeeks方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getAverageGlucoseReadingsByWeek

import org.joda.time.DateTime; //導入方法依賴的package包/類
public List<Integer> getAverageGlucoseReadingsByWeek() {
    JodaTimeAndroid.init(mContext);

    DateTime maxDateTime = new DateTime(realm.where(GlucoseReading.class).maximumDate("created").getTime());
    DateTime minDateTime = new DateTime(realm.where(GlucoseReading.class).minimumDate("created").getTime());

    DateTime currentDateTime = minDateTime;
    DateTime newDateTime = minDateTime;

    ArrayList<Integer> averageReadings = new ArrayList<Integer>();

    // The number of weeks is at least 1 since we do have average for the current week even if incomplete
    int weeksNumber = Weeks.weeksBetween(minDateTime, maxDateTime).getWeeks() + 1;

    for (int i = 0; i < weeksNumber; i++) {
        newDateTime = currentDateTime.plusWeeks(1);
        RealmResults<GlucoseReading> readings = realm.where(GlucoseReading.class)
                .between("created", currentDateTime.toDate(), newDateTime.toDate())
                .findAll();
        averageReadings.add(((int) readings.average("reading")));
        currentDateTime = newDateTime;
    }
    return averageReadings;
}
 
開發者ID:adithya321,項目名稱:SOS-The-Healthcare-Companion,代碼行數:25,代碼來源:DatabaseHandler.java

示例2: getGlucoseDatetimesByWeek

import org.joda.time.DateTime; //導入方法依賴的package包/類
public List<String> getGlucoseDatetimesByWeek() {
    JodaTimeAndroid.init(mContext);

    DateTime maxDateTime = new DateTime(realm.where(GlucoseReading.class).maximumDate("created").getTime());
    DateTime minDateTime = new DateTime(realm.where(GlucoseReading.class).minimumDate("created").getTime());

    DateTime currentDateTime = minDateTime;
    DateTime newDateTime = minDateTime;

    ArrayList<String> finalWeeks = new ArrayList<String>();

    // The number of weeks is at least 1 since we do have average for the current week even if incomplete
    int weeksNumber = Weeks.weeksBetween(minDateTime, maxDateTime).getWeeks() + 1;

    DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    for (int i = 0; i < weeksNumber; i++) {
        newDateTime = currentDateTime.plusWeeks(1);
        finalWeeks.add(inputFormat.format(newDateTime.toDate()));
        currentDateTime = newDateTime;
    }
    return finalWeeks;
}
 
開發者ID:adithya321,項目名稱:SOS-The-Healthcare-Companion,代碼行數:23,代碼來源:DatabaseHandler.java

示例3: secondsUntilNextMondayRun

import org.joda.time.DateTime; //導入方法依賴的package包/類
private int secondsUntilNextMondayRun() {
    DateTime now = DateTime.now();
    // Every Monday at 5AM UTC
    int adjustedHours = 5;
    if (!AppUtil.getDefaultTimeZone().isStandardOffset(now.getMillis())) {
        // Have the run happen an hour earlier to take care of DST offset
        adjustedHours -= 1;
    }

    DateTime nextRun = now.withHourOfDay(adjustedHours)
            .withMinuteOfHour(0)
            .withSecondOfMinute(0)
            .withMillisOfSecond(0)
            .plusWeeks(now.getDayOfWeek() == DateTimeConstants.MONDAY ? 0 : 1)
            .withDayOfWeek(DateTimeConstants.MONDAY);
    if (!nextRun.isAfter(now)) {
        nextRun = nextRun.plusWeeks(1); // now is a Monday after scheduled run time -> postpone
    }
    // Case for: now there's no DST but by next run there will be.
    if (adjustedHours == 5 && !AppUtil.getDefaultTimeZone().isStandardOffset(nextRun.getMillis())) {
        nextRun = nextRun.minusHours(1);
    }
    // Case for: now there's DST but by next run there won't be
    else if (adjustedHours != 5 && AppUtil.getDefaultTimeZone().isStandardOffset(nextRun.getMillis())) {
        nextRun = nextRun.plusHours(1);
    }

    Logger.info("Scheduled next weekly report to be run at {}", nextRun.toString());
    // Increase delay with one second so that this won't fire off before intended time. This may happen because of
    // millisecond-level rounding issues and possibly cause resending of messages.
    return Seconds.secondsBetween(now, nextRun).getSeconds() + 1;
}
 
開發者ID:CSCfi,項目名稱:exam,代碼行數:33,代碼來源:SystemInitializer.java


注:本文中的org.joda.time.DateTime.plusWeeks方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。