本文整理汇总了Java中org.joda.time.DateMidnight.minusDays方法的典型用法代码示例。如果您正苦于以下问题:Java DateMidnight.minusDays方法的具体用法?Java DateMidnight.minusDays怎么用?Java DateMidnight.minusDays使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.joda.time.DateMidnight
的用法示例。
在下文中一共展示了DateMidnight.minusDays方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ensureCallingOnUpdateChangesLastModificationDate
import org.joda.time.DateMidnight; //导入方法依赖的package包/类
@Test
public void ensureCallingOnUpdateChangesLastModificationDate() throws IllegalAccessException {
Person person = TestDataCreator.createPerson();
DateMidnight now = DateMidnight.now();
Overtime overtime = new Overtime(person, now.minusDays(2), now, BigDecimal.ONE);
// Simulate that the overtime record has been created to an earlier time
Field lastModificationDateField = ReflectionUtils.findField(Overtime.class, "lastModificationDate");
lastModificationDateField.setAccessible(true);
lastModificationDateField.set(overtime, now.minusDays(3).toDate());
Assert.assertEquals("Wrong initial last modification date", now.minusDays(3),
overtime.getLastModificationDate());
overtime.onUpdate();
Assert.assertEquals("Last modification date should be set to now", now, overtime.getLastModificationDate());
}
示例2: ensureReturnsCorrectEndDate
import org.joda.time.DateMidnight; //导入方法依赖的package包/类
@Test
public void ensureReturnsCorrectEndDate() {
Person person = TestDataCreator.createPerson();
DateMidnight now = DateMidnight.now();
Overtime overtime = new Overtime(person, now.minusDays(2), now, BigDecimal.ONE);
Assert.assertNotNull("Should not be null", overtime.getEndDate());
Assert.assertEquals("Wrong end date", now, overtime.getEndDate());
}
示例3: ensureSetLastModificationDateOnInitialization
import org.joda.time.DateMidnight; //导入方法依赖的package包/类
@Test
public void ensureSetLastModificationDateOnInitialization() {
Person person = TestDataCreator.createPerson();
DateMidnight now = DateMidnight.now();
Overtime overtime = new Overtime(person, now.minusDays(2), now.plusDays(4), BigDecimal.ONE);
Assert.assertNotNull("Should not be null", overtime.getLastModificationDate());
Assert.assertEquals("Wrong last modification date", now, overtime.getLastModificationDate());
}
示例4: ensureThrowsIfGettingStartDateOnACorruptedOvertime
import org.joda.time.DateMidnight; //导入方法依赖的package包/类
@Test(expected = IllegalStateException.class)
public void ensureThrowsIfGettingStartDateOnACorruptedOvertime() throws IllegalAccessException {
Person person = TestDataCreator.createPerson();
DateMidnight now = DateMidnight.now();
Overtime overtime = new Overtime(person, now.minusDays(2), now, BigDecimal.ONE);
Field startDateField = ReflectionUtils.findField(Overtime.class, "startDate");
startDateField.setAccessible(true);
startDateField.set(overtime, null);
overtime.getStartDate();
}
示例5: ensureThrowsIfGettingEndDateOnACorruptedOvertime
import org.joda.time.DateMidnight; //导入方法依赖的package包/类
@Test(expected = IllegalStateException.class)
public void ensureThrowsIfGettingEndDateOnACorruptedOvertime() throws IllegalAccessException {
Person person = TestDataCreator.createPerson();
DateMidnight now = DateMidnight.now();
Overtime overtime = new Overtime(person, now.minusDays(2), now, BigDecimal.ONE);
Field endDateField = ReflectionUtils.findField(Overtime.class, "endDate");
endDateField.setAccessible(true);
endDateField.set(overtime, null);
overtime.getEndDate();
}
示例6: ensureThrowsIfGettingLastModificationDateOnACorruptedOvertime
import org.joda.time.DateMidnight; //导入方法依赖的package包/类
@Test(expected = IllegalStateException.class)
public void ensureThrowsIfGettingLastModificationDateOnACorruptedOvertime() throws IllegalAccessException {
Person person = TestDataCreator.createPerson();
DateMidnight now = DateMidnight.now();
Overtime overtime = new Overtime(person, now.minusDays(2), now, BigDecimal.ONE);
Field lastModificationDateField = ReflectionUtils.findField(Overtime.class, "lastModificationDate");
lastModificationDateField.setAccessible(true);
lastModificationDateField.set(overtime, null);
overtime.getLastModificationDate();
}
示例7: ensureThrowsIfEndDateIsBeforeStartDate
import org.joda.time.DateMidnight; //导入方法依赖的package包/类
@Test(expected = IllegalArgumentException.class)
public void ensureThrowsIfEndDateIsBeforeStartDate() {
DateMidnight startDate = DateMidnight.now();
DateMidnight endDateBeforeStartDate = startDate.minusDays(1);
new Period(startDate, endDateBeforeStartDate, DayLength.FULL);
}
示例8: getStats
import org.joda.time.DateMidnight; //导入方法依赖的package包/类
@Override
public TwitterStats getStats(User user) {
if (!isServiceEnabled(user)) {
return null;
}
Twitter t = helper.getTwitter(user);
try {
Paging paging = new Paging();
paging.setCount(200); // max allowed
TwitterStats stats = new TwitterStats();
List<Status> statuses = t.getUserTimeline(paging);
if (statuses.isEmpty()) {
return stats;
}
// start and end of displaying. Chronologically reverse order
DateMidnight start = new DateMidnight(statuses.get(statuses.size() - 1).getCreatedAt());
DateMidnight end = new DateMidnight(statuses.get(0).getCreatedAt());
if (Days.daysBetween(start, end).getDays() > 30) {
start = end.minusDays(30);
}
fillStats(statuses, stats.getTweets(), start, end);
// Get mentions and retweets only as old as the last tweet
paging.setSinceId(statuses.get(statuses.size() - 1).getId());
fillStats(t.getMentions(paging), stats.getMentions(), start, end);
fillStats(t.getRetweetsOfMe(paging), stats.getRetweets(), start, end);
int days = Days.daysBetween(start, end).getDays();
if (days == 0) {
return stats; // no further calculation
}
int[] tweetsMaxAndSum = CollectionUtils.getMaxAndSum(stats.getTweets());
stats.setMaxTweets(tweetsMaxAndSum[0]);
stats.setAverageTweets(tweetsMaxAndSum[1] / days);
int[] retweetsMaxAndSum = CollectionUtils.getMaxAndSum(stats.getRetweets());
stats.setMaxRetweets(retweetsMaxAndSum[0]);
stats.setAverageRetweets(retweetsMaxAndSum[1] / days);
int[] mentionsMaxAndSum = CollectionUtils.getMaxAndSum(stats.getMentions());
stats.setMaxMentions(mentionsMaxAndSum[0]);
stats.setAverageMentions(mentionsMaxAndSum[1] / days);
stats.setMaxCount(NumberUtils.max(
stats.getMaxTweets(),
stats.getMaxMentions(),
stats.getMaxRetweets()));
return stats;
} catch (TwitterException e) {
handleException("Problem fetching statistics", e, user);
return null;
}
}
示例9: getStats
import org.joda.time.DateMidnight; //导入方法依赖的package包/类
@Override
@SqlReadonlyTransactional
public WelshareStats getStats(User user) {
WelshareStats stats = new WelshareStats();
List<Message> messages = getDao().getUserMessages(user, 200, 0);
if (messages.isEmpty()) {
return stats;
}
LinkedList<Message> linkedList = new LinkedList<Message>(messages);
Iterator<Message> iterator = linkedList.descendingIterator();
Multiset<DateMidnight> messagesData = LinkedHashMultiset.create();
Multiset<DateMidnight> likesData = LinkedHashMultiset.create();
Multiset<DateMidnight> repliesData = LinkedHashMultiset.create();
Message currentMessage = iterator.next();
DateMidnight current = new DateMidnight(currentMessage.getDateTime());
DateMidnight start = current;
while (iterator.hasNext() || currentMessage != null) {
// skip imported messages
DateMidnight msgTime = new DateMidnight(currentMessage.getDateTime());
if (current.equals(msgTime)) {
if (!currentMessage.isImported()) {
messagesData.add(current);
likesData.add(current, currentMessage.getScore());
repliesData.add(current, currentMessage.getReplies());
}
if (iterator.hasNext()) {
currentMessage = iterator.next();
} else {
currentMessage = null;
}
} else {
current = current.plusDays(1);
}
}
DateMidnight end = current;
if (Days.daysBetween(start, end).getDays() > 30) {
start = end.minusDays(30);
}
for (DateMidnight dm = start; !dm.isAfter(end); dm = dm.plusDays(1)) {
stats.getMessages().put(dm, messagesData.count(dm));
stats.getReplies().put(dm, repliesData.count(dm));
stats.getLikes().put(dm, likesData.count(dm));
}
int days = Days.daysBetween(start, end).getDays();
if (days == 0) {
return stats; // no further calculation
}
int[] messagesMaxAndSum = CollectionUtils.getMaxAndSum(stats.getMessages());
stats.setMaxMessages(messagesMaxAndSum[0]);
stats.setAverageMessages(messagesMaxAndSum[1] / days);
int[] likesMaxAndSum = CollectionUtils.getMaxAndSum(stats.getLikes());
stats.setMaxLikes(likesMaxAndSum[0]);
stats.setAverageLikes(likesMaxAndSum[1] / days);
int[] repliesMaxAndSum = CollectionUtils.getMaxAndSum(stats.getReplies());
stats.setMaxReplies(repliesMaxAndSum[0]);
stats.setAverageReplies(repliesMaxAndSum[1] / days);
stats.setMaxCount(NumberUtils.max(
stats.getMaxMessages(),
stats.getMaxReplies(),
stats.getMaxLikes()));
return stats;
}
示例10: ensureThrowsIfInitializedWithEndDateThatIsBeforeStartDate
import org.joda.time.DateMidnight; //导入方法依赖的package包/类
@Test(expected = IllegalArgumentException.class)
public void ensureThrowsIfInitializedWithEndDateThatIsBeforeStartDate() {
DateMidnight now = DateMidnight.now();
new FilterPeriod(now, now.minusDays(1));
}