当前位置: 首页>>代码示例>>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;未经允许,请勿转载。