本文整理汇总了Java中org.joda.time.Weeks类的典型用法代码示例。如果您正苦于以下问题:Java Weeks类的具体用法?Java Weeks怎么用?Java Weeks使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Weeks类属于org.joda.time包,在下文中一共展示了Weeks类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAverageGlucoseReadingsByWeek
import org.joda.time.Weeks; //导入依赖的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;
}
示例2: getGlucoseDatetimesByWeek
import org.joda.time.Weeks; //导入依赖的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;
}
示例3: WEEKS
import org.joda.time.Weeks; //导入依赖的package包/类
/**
* Returns the number of weeks between two dates.
*/
@Function("WEEKS")
@FunctionParameters({
@FunctionParameter("startDate"),
@FunctionParameter("endDate")})
public Integer WEEKS(Object startDate, Object endDate){
Date startDateObj = convertDateObject(startDate);
if(startDateObj==null) {
logCannotConvertToDate();
return null;
}
Date endDateObj = convertDateObject(endDate);
if(endDateObj==null){
logCannotConvertToDate();
return null;
}
else{
LocalDate dt1=new LocalDate(startDateObj);
LocalDate dt2=new LocalDate(endDateObj);
return Weeks.weeksBetween(dt1, dt2).getWeeks();
}
}
示例4: create
import org.joda.time.Weeks; //导入依赖的package包/类
@Override
public Object create(Object request, SpecimenContext context) {
if (!(request instanceof SpecimenType)) {
return new NoSpecimen();
}
SpecimenType type = (SpecimenType) request;
if (!BaseSingleFieldPeriod.class.isAssignableFrom(type.getRawType())) {
return new NoSpecimen();
}
Duration duration = (Duration) context.resolve(Duration.class);
if (type.equals(Seconds.class)) return Seconds.seconds(Math.max(1, (int) duration.getStandardSeconds()));
if (type.equals(Minutes.class)) return Minutes.minutes(Math.max(1, (int) duration.getStandardMinutes()));
if (type.equals(Hours.class)) return Hours.hours(Math.max(1, (int) duration.getStandardHours()));
if (type.equals(Days.class)) return Days.days(Math.max(1, (int) duration.getStandardDays()));
if (type.equals(Weeks.class)) return Weeks.weeks(Math.max(1, (int) duration.getStandardDays() / 7));
if (type.equals(Months.class)) return Months.months(Math.max(1, (int) duration.getStandardDays() / 30));
if (type.equals(Years.class)) return Years.years(Math.max(1, (int) duration.getStandardDays() / 365));
return new NoSpecimen();
}
示例5: storeAllMeasures
import org.joda.time.Weeks; //导入依赖的package包/类
/**
* Obtain the indicators from the statistics and stores them into the im
*
* @param im indicatorMap to store the indicators
* @param statistics statistics of the git.
*/
private void storeAllMeasures(IndicatorsMap im, GitLogStatistics statistics)
{
DateTime dt = new DateTime(statistics.firstCommitDate);
Months months = Months.monthsBetween(dt, new DateTime());
Weeks weeks = Weeks.weeksBetween(dt, new DateTime());
im.add("git average-commits-per-month", (double) statistics.totalCommits / months.getMonths());
im.add("git average-commits-per-week", (double) statistics.totalCommits / weeks.getWeeks());
im.add("git average-commits-per-committer", (double) statistics.totalCommits / statistics.totalCommitters);
im.add("git average-files-changed-per-committer", (double) statistics.totalFilesChanged
/ statistics.totalCommitters);
im.add("git average-lines-added-per-commmit", (double) statistics.totalLinesAdded / statistics.totalCommits);
im.add("git average-lines-removed-per-commit", (double) statistics.totalLinesRemoved / statistics.totalCommits);
im.add("git average-files-changed-per-commit", (double) statistics.totalFilesChanged / statistics.totalCommits);
im.add("git distribution-commits-by-hour", RiskDataType.DISTRIBUTION,
getDistribution(statistics.commitsByHour, statistics.totalCommits));
im.add("git distribution-commits-by-weekday", RiskDataType.DISTRIBUTION,
getDistribution(statistics.commitsByWeekday, statistics.totalCommits));
}
示例6: predict
import org.joda.time.Weeks; //导入依赖的package包/类
@Override
public List<Prediction> predict(PredictorState state, UtilizationHistory history, int maxCapacity) {
Optional<Utilization> latest = history.getLatest();
if (!latest.isPresent()) return Collections.emptyList();
DateTime now = state.latestUtilization = latest.get().timestamp;
List<List<Prediction>> groupedByWeek = Stream.of(Weeks.weeks(1), Weeks.weeks(2), Weeks.weeks(3))
.map(offset -> {
DateTime start = now.minus(offset);
DateTime end = start.plus(PredictionRepository.PREDICTION_WINDOW);
List<Utilization> utilizations = history.getRange(start, end);
return utilizations.stream()
.map(u -> new Prediction(u.timestamp.plus(offset), u.spacesAvailable))
.collect(Collectors.toList());
})
.collect(Collectors.toList());
List<List<Prediction>> groupedByTimeOfDay = ListUtil.transpose(groupedByWeek);
return groupedByTimeOfDay.stream()
.map(this::reduce)
.collect(Collectors.toList());
}
示例7: onCreate
import org.joda.time.Weeks; //导入依赖的package包/类
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_knell);
ButterKnife.bind(this);
Birthday birthday = getBirthdayManager().get();
DateTime birDateTime = new DateTime(birthday.year, birthday.month, birthday.day, 0, 0);
Days days = Days.daysBetween(birDateTime, DateTime.now());
Hours hours = Hours.hoursBetween(birDateTime, DateTime.now());
Minutes minutes = Minutes.minutesBetween(birDateTime, DateTime.now());
Weeks weeks = Weeks.weeksBetween(birDateTime, DateTime.now());
Years years = Years.yearsBetween(birDateTime, DateTime.now());
Months months = Months.monthsBetween(birDateTime, DateTime.now());
Timber.d("onCreate: 年:%d", years.getYears());
Timber.d("onCreate: 月:%d", months.getMonths());
Timber.d("onCreate: 周:%d", weeks.getWeeks());
Timber.d("onCreate: 天数为:%d", days.getDays());
Timber.d("onCreate: 小时数为:%d", hours.getHours());
Timber.d("onCreate: 分钟数为:%d", minutes.getMinutes());
tvYear.setText(String.valueOf(years.getYears()));
tvMonth.setText(String.valueOf(months.getMonths()));
tvWeek.setText(String.valueOf(weeks.getWeeks()));
tvDay.setText(String.valueOf(days.getDays()));
tvHour.setText(String.valueOf(hours.getHours()));
tvMinute.setText(String.valueOf(minutes.getMinutes()));
}
示例8: execute
import org.joda.time.Weeks; //导入依赖的package包/类
@Override
public void execute(MessageReceivedEvent event, String[] args) {
DateTime current = new DateTime(DateTimeZone.forID("America/Montreal"));
while (current.getDayOfWeek() != DateTimeConstants.TUESDAY) {
current = current.minusDays(1);
}
int weeks = Weeks.weeksBetween(Utils.startDateMythicPlus, current).getWeeks();
String[] weekAffixes = Utils.mythicPlusAffixes[weeks % 12];
event.getChannel().sendMessage(Utils.createMythicEmbed(bot, event.getGuild(), weekAffixes).build()).queue();
}
示例9: execute
import org.joda.time.Weeks; //导入依赖的package包/类
@Override
public void execute(MessageReceivedEvent event, String[] args) {
DateTime current = new DateTime(DateTimeZone.forID("America/Montreal"));
if (current.getDayOfWeek() == DateTimeConstants.TUESDAY) {
current = current.plusDays(1);
}
while (current.getDayOfWeek() != DateTimeConstants.TUESDAY) {
current = current.plusDays(1);
}
int weeks = Weeks.weeksBetween(Utils.startDateMythicPlus, current).getWeeks();
String[] weekAffixes = Utils.mythicPlusAffixes[weeks % 12];
event.getChannel().sendMessage(Utils.createMythicEmbed(bot, event.getGuild(), weekAffixes).build()).queue();
}
示例10: parsePeriodString
import org.joda.time.Weeks; //导入依赖的package包/类
public static ReadablePeriod parsePeriodString(String periodStr) {
ReadablePeriod period;
char periodUnit = periodStr.charAt(periodStr.length() - 1);
if (periodUnit == 'n') {
return null;
}
int periodInt =
Integer.parseInt(periodStr.substring(0, periodStr.length() - 1));
switch (periodUnit) {
case 'M':
period = Months.months(periodInt);
break;
case 'w':
period = Weeks.weeks(periodInt);
break;
case 'd':
period = Days.days(periodInt);
break;
case 'h':
period = Hours.hours(periodInt);
break;
case 'm':
period = Minutes.minutes(periodInt);
break;
case 's':
period = Seconds.seconds(periodInt);
break;
default:
throw new IllegalArgumentException("Invalid schedule period unit '"
+ periodUnit);
}
return period;
}
示例11: parsePeriodString
import org.joda.time.Weeks; //导入依赖的package包/类
public static ReadablePeriod parsePeriodString(String periodStr) {
ReadablePeriod period;
char periodUnit = periodStr.charAt(periodStr.length() - 1);
if (periodStr.equals("null") || periodUnit == 'n') {
return null;
}
int periodInt =
Integer.parseInt(periodStr.substring(0, periodStr.length() - 1));
switch (periodUnit) {
case 'y':
period = Years.years(periodInt);
break;
case 'M':
period = Months.months(periodInt);
break;
case 'w':
period = Weeks.weeks(periodInt);
break;
case 'd':
period = Days.days(periodInt);
break;
case 'h':
period = Hours.hours(periodInt);
break;
case 'm':
period = Minutes.minutes(periodInt);
break;
case 's':
period = Seconds.seconds(periodInt);
break;
default:
throw new IllegalArgumentException("Invalid schedule period unit '"
+ periodUnit);
}
return period;
}
示例12: getTimeSteps
import org.joda.time.Weeks; //导入依赖的package包/类
public static int getTimeSteps(int tempRes, int startTime, int endTime) {
if (startTime > endTime) {
return 0;
}
int timeSteps = 0;
DateTime start = new DateTime(((long)startTime)*1000, DateTimeZone.UTC);
DateTime end = new DateTime(((long)endTime)*1000, DateTimeZone.UTC);
switch(tempRes) {
case FrameworkUtils.HOUR:
timeSteps = Hours.hoursBetween(start, end).getHours();
break;
case FrameworkUtils.DAY:
timeSteps = Days.daysBetween(start, end).getDays();
break;
case FrameworkUtils.WEEK:
timeSteps = Weeks.weeksBetween(start, end).getWeeks();
break;
case FrameworkUtils.MONTH:
timeSteps = Months.monthsBetween(start, end).getMonths();
break;
case FrameworkUtils.YEAR:
timeSteps = Years.yearsBetween(start, end).getYears();
break;
default:
timeSteps = Hours.hoursBetween(start, end).getHours();
break;
}
timeSteps++;
return timeSteps;
}
示例13: getDeltaSinceEpoch
import org.joda.time.Weeks; //导入依赖的package包/类
public static int getDeltaSinceEpoch(int time, int tempRes) {
int delta = 0;
// Epoch
MutableDateTime epoch = new MutableDateTime();
epoch.setDate(0);
DateTime dt = new DateTime(time*1000, DateTimeZone.UTC);
switch(tempRes) {
case FrameworkUtils.HOUR:
Hours hours = Hours.hoursBetween(epoch, dt);
delta = hours.getHours();
break;
case FrameworkUtils.DAY:
Days days = Days.daysBetween(epoch, dt);
delta = days.getDays();
break;
case FrameworkUtils.WEEK:
Weeks weeks = Weeks.weeksBetween(epoch, dt);
delta = weeks.getWeeks();
break;
case FrameworkUtils.MONTH:
Months months = Months.monthsBetween(epoch, dt);
delta = months.getMonths();
break;
case FrameworkUtils.YEAR:
Years years = Years.yearsBetween(epoch, dt);
delta = years.getYears();
break;
default:
hours = Hours.hoursBetween(epoch, dt);
delta = hours.getHours();
break;
}
return delta;
}
示例14: testParseOneWeekAgo
import org.joda.time.Weeks; //导入依赖的package包/类
@Test
public void testParseOneWeekAgo() {
PointInTime expectedLastWeek = PointInTime.today().subtract(Weeks.weeks(1));
PointInTime lastWeek = RelativeDateTimeFormat.parse("TODAY-7");
assertThat(lastWeek, is(expectedLastWeek));
assertThat(lastWeek.getPrecision(), is(Precision.DATE));
lastWeek = RelativeDateTimeFormat.parse("Today-7");
assertThat(lastWeek, is(expectedLastWeek));
assertThat(lastWeek.getPrecision(), is(Precision.DATE));
lastWeek = RelativeDateTimeFormat.parse("T-7");
assertThat(lastWeek, is(expectedLastWeek));
assertThat(lastWeek.getPrecision(), is(Precision.DATE));
lastWeek = RelativeDateTimeFormat.parse("t-7");
assertThat(lastWeek, is(expectedLastWeek));
assertThat(lastWeek.getPrecision(), is(Precision.DATE));
lastWeek = RelativeDateTimeFormat.parse("t-1W");
assertThat(lastWeek, is(expectedLastWeek));
assertThat(lastWeek.getPrecision(), is(Precision.DATE));
lastWeek = RelativeDateTimeFormat.parse("t-1w");
assertThat(lastWeek, is(expectedLastWeek));
assertThat(lastWeek.getPrecision(), is(Precision.DATE));
}
示例15: resolve
import org.joda.time.Weeks; //导入依赖的package包/类
public LocalDateTime resolve(LocalDateTime base) {
if (this.duration==null || this.durationUnit==null) {
return null;
}
ReadablePeriod period = null;
if (DAYS.equals(durationUnit)) {
period = Days.days(getDurationAsInt());
} else if (WEEKS.equals(durationUnit)) {
period = Weeks.weeks(getDurationAsInt());
} else if (HOURS.equals(durationUnit)) {
period = Hours.hours(getDurationAsInt());
} else if (MONTHS.equals(durationUnit)) {
period = Months.months(getDurationAsInt());
} else if (YEARS.equals(durationUnit)) {
period = Years.years(getDurationAsInt());
} else if (MINUTES.equals(durationUnit)) {
period = Minutes.minutes(getDurationAsInt());
} else {
return null;
}
LocalDateTime time = base.plus(period);
if (atHour!=null) {
LocalDateTime atTime = time.withTime(atHour, atMinute!=null ? atMinute : 0, 0, 0);
if (atTime.isBefore(time)) {
time = atTime.plusDays(1);
} else {
time = atTime;
}
} else if (isDayResolutionOrBigger()) {
time = time.withTime(23, 59, 59, 999);
}
return time;
}