本文整理汇总了Java中org.joda.time.DateTimeConstants类的典型用法代码示例。如果您正苦于以下问题:Java DateTimeConstants类的具体用法?Java DateTimeConstants怎么用?Java DateTimeConstants使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DateTimeConstants类属于org.joda.time包,在下文中一共展示了DateTimeConstants类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRoundingRandom
import org.joda.time.DateTimeConstants; //导入依赖的package包/类
/**
* Randomized test on TimeUnitRounding. Test uses random
* {@link DateTimeUnit} and {@link DateTimeZone} and often (50% of the time)
* chooses test dates that are exactly on or close to offset changes (e.g.
* DST) in the chosen time zone.
*
* It rounds the test date down and up and performs various checks on the
* rounding unit interval that is defined by this. Assumptions tested are
* described in
* {@link #assertInterval(long, long, long, Rounding, DateTimeZone)}
*/
public void testRoundingRandom() {
for (int i = 0; i < 1000; ++i) {
DateTimeUnit timeUnit = randomTimeUnit();
DateTimeZone tz = randomDateTimeZone();
Rounding rounding = new Rounding.TimeUnitRounding(timeUnit, tz);
long date = Math.abs(randomLong() % (2 * (long) 10e11)); // 1970-01-01T00:00:00Z - 2033-05-18T05:33:20.000+02:00
long unitMillis = timeUnit.field(tz).getDurationField().getUnitMillis();
if (randomBoolean()) {
nastyDate(date, tz, unitMillis);
}
final long roundedDate = rounding.round(date);
final long nextRoundingValue = rounding.nextRoundingValue(roundedDate);
assertInterval(roundedDate, date, nextRoundingValue, rounding, tz);
// check correct unit interval width for units smaller than a day, they should be fixed size except for transitions
if (unitMillis <= DateTimeConstants.MILLIS_PER_DAY) {
// if the interval defined didn't cross timezone offset transition, it should cover unitMillis width
if (tz.getOffset(roundedDate - 1) == tz.getOffset(nextRoundingValue + 1)) {
assertThat("unit interval width not as expected for [" + timeUnit + "], [" + tz + "] at "
+ new DateTime(roundedDate), nextRoundingValue - roundedDate, equalTo(unitMillis));
}
}
}
}
示例2: getWeekIncludeThisDay
import org.joda.time.DateTimeConstants; //导入依赖的package包/类
public static CalendarWeek getWeekIncludeThisDay(LocalDate localDate) {
LocalDate monday = localDate.withDayOfWeek(DateTimeConstants.MONDAY);
LocalDate tuesday = localDate.withDayOfWeek(DateTimeConstants.TUESDAY);
LocalDate wednesday = localDate.withDayOfWeek(DateTimeConstants.WEDNESDAY);
LocalDate thursday = localDate.withDayOfWeek(DateTimeConstants.THURSDAY);
LocalDate friday = localDate.withDayOfWeek(DateTimeConstants.FRIDAY);
LocalDate saturday = localDate.withDayOfWeek(DateTimeConstants.SATURDAY);
LocalDate sunday = localDate.withDayOfWeek(DateTimeConstants.SUNDAY);
CalendarWeek calendarWeek = new CalendarWeek(
monday,
tuesday,
wednesday,
thursday,
friday,
saturday,
sunday
);
calendarWeek.firstDayOfCurrentMonth = localDate.withDayOfMonth(1);
calendarWeek.originDate = localDate;
return calendarWeek;
}
示例3: getDayOfWeekTimeFlag
import org.joda.time.DateTimeConstants; //导入依赖的package包/类
public static long getDayOfWeekTimeFlag(int dayOfWeek) {
dayOfWeek = (dayOfWeek - 1) % 7 + 1;
switch (dayOfWeek) {
case DateTimeConstants.SUNDAY:
return FLAG_SUNDAY;
case DateTimeConstants.MONDAY:
return FLAG_MONDAY;
case DateTimeConstants.SATURDAY:
return FLAG_SATURDAY;
case DateTimeConstants.WEDNESDAY:
return FLAG_WEDNESDAY;
case DateTimeConstants.TUESDAY:
return FLAG_TUESDAY;
case DateTimeConstants.THURSDAY:
return FLAG_THURSDAY;
case DateTimeConstants.FRIDAY:
return FLAG_FRIDAY;
}
throw new IllegalArgumentException("dayOfWeek = " + dayOfWeek);
}
示例4: getMondaysFromCurrentSchoolYear
import org.joda.time.DateTimeConstants; //导入依赖的package包/类
public static List<String> getMondaysFromCurrentSchoolYear(String dateFormat) {
LocalDate startDate = new LocalDate(getCurrentSchoolYear(), 9, 1);
LocalDate endDate = new LocalDate(getCurrentSchoolYear() + 1, 8, 31);
List<String> dateList = new ArrayList<>();
LocalDate thisMonday = startDate.withDayOfWeek(DateTimeConstants.MONDAY);
if (startDate.isAfter(thisMonday)) {
startDate = thisMonday.plusWeeks(1);
} else {
startDate = thisMonday;
}
while (startDate.isBefore(endDate)) {
dateList.add(startDate.toString(dateFormat));
startDate = startDate.plusWeeks(1);
}
return dateList;
}
示例5: getDateOfCurrentMonday
import org.joda.time.DateTimeConstants; //导入依赖的package包/类
private String getDateOfCurrentMonday() {
DateTime currentDate = new DateTime();
if (currentDate.getDayOfWeek() == DateTimeConstants.SATURDAY) {
currentDate = currentDate.plusDays(2);
} else if (currentDate.getDayOfWeek() == DateTimeConstants.SUNDAY) {
currentDate = currentDate.plusDays(1);
} else {
currentDate = currentDate.withDayOfWeek(DateTimeConstants.MONDAY);
}
return currentDate.toString(DATE_PATTERN);
}
示例6: GetNPastWeeks
import org.joda.time.DateTimeConstants; //导入依赖的package包/类
/**
* Generates the datetime bounds for the last N weeks, this week inclusive
* The first day of the week is considered to be a Monday (1)
* @param dateTime the anchor date
* @param nPastWeeks the number of weeks to compute
* @return a series of n week objects, containing the start date and end date of those weeks
*/
public static ArrayList<Week>
GetNPastWeeks(DateTime dateTime, int nPastWeeks) {
if (nPastWeeks < 1) return new ArrayList<>();
LocalDate localDate = new LocalDate(dateTime);
DateTime monday = localDate.withDayOfWeek(DateTimeConstants.MONDAY)
.toDateTimeAtStartOfDay();
DateTime sunday = localDate.withDayOfWeek(DateTimeConstants.SUNDAY)
.toDateTimeAtStartOfDay().plusDays(1)
.minusMillis(1);
Week datePair = new Week(monday, sunday);
ArrayList<Week> datePairs = new ArrayList<>(nPastWeeks);
datePairs.add(datePair);
for (int i = 1; i < nPastWeeks; ++i) {
datePairs.add(new Week(
datePairs.get(i - 1).getStartOfWeek().minusWeeks(1),
datePairs.get(i - 1).getEndOfWeek().minusWeeks(1)));
}
Collections.reverse(datePairs);
return datePairs;
}
示例7: HabitDataModel
import org.joda.time.DateTimeConstants; //导入依赖的package包/类
/**
* Convert a habit to its data model
* @param habit the habit to convert
*/
public HabitDataModel(Habit habit) {
key = habit.getKey();
userId = habit.getUserId();
title = habit.getTitle();
reason = habit.getReason();
startDate = habit.getStartDate().getMillis();
schedule = new ArrayList<>(DateTimeConstants.DAYS_PER_WEEK);
for (int i = 0; i < DateTimeConstants.DAYS_PER_WEEK; i++) {
schedule.add(habit.getSchedule().contains(i + 1));
}
completionRate = habit.getCompletionRate();
}
示例8: getHabit
import org.joda.time.DateTimeConstants; //导入依赖的package包/类
/**
* Convert to a habit
* @return the corresponding Habit object
*/
@Exclude
public Habit getHabit() {
HashSet<Integer> newSchedule = new HashSet<>(DateTimeConstants.DAYS_PER_WEEK);
for(int i = 0; i < schedule.size(); i++) {
if(schedule.get(i)) {
newSchedule.add(i + 1);
}
}
Habit habit = new Habit();
habit.setKey(key);
habit.setUserId(userId);
habit.setTitle(title);
habit.setReason(reason);
habit.setStartDate(new DateTime(startDate));
habit.setSchedule(newSchedule);
habit.setCompletionRate(completionRate);
if (completionRate != null) {
habit.setStatus(HabitStatus.fromCompletionRate(completionRate));
}
return habit;
}
示例9: testGetMillisKeepLocal
import org.joda.time.DateTimeConstants; //导入依赖的package包/类
public void testGetMillisKeepLocal() {
long millisLondon = TEST_TIME_SUMMER;
long millisParis = TEST_TIME_SUMMER - 1L * DateTimeConstants.MILLIS_PER_HOUR;
assertEquals(millisLondon, LONDON.getMillisKeepLocal(LONDON, millisLondon));
assertEquals(millisParis, LONDON.getMillisKeepLocal(LONDON, millisParis));
assertEquals(millisLondon, PARIS.getMillisKeepLocal(PARIS, millisLondon));
assertEquals(millisParis, PARIS.getMillisKeepLocal(PARIS, millisParis));
assertEquals(millisParis, LONDON.getMillisKeepLocal(PARIS, millisLondon));
assertEquals(millisLondon, PARIS.getMillisKeepLocal(LONDON, millisParis));
DateTimeZone zone = DateTimeZone.getDefault();
try {
DateTimeZone.setDefault(LONDON);
assertEquals(millisLondon, PARIS.getMillisKeepLocal(null, millisParis));
} finally {
DateTimeZone.setDefault(zone);
}
}
示例10: createLessonsForWeek
import org.joda.time.DateTimeConstants; //导入依赖的package包/类
private Timetable createLessonsForWeek(LocalDate weekStart) {
Timetable result = new Timetable();
for (int dayNo = DateTimeConstants.MONDAY; dayNo <= DateTimeConstants.FRIDAY; dayNo++) {
List<List<JsonLesson>> schoolDay = new ArrayList<>();
for (int lessonNo = 0; lessonNo < repository.getList(PlainLesson.class).size(); lessonNo++) {
ImmutableJsonLesson lesson = templates.jsonLesson()
.withDayNo(dayNo);
schoolDay.add(withLessonNumber(lesson, lessonNo));
}
result.put(weekStart.plusDays(dayNo - 1), schoolDay);
}
//weekend
result.put(weekStart.plusDays(5), newArrayList());
result.put(weekStart.plusDays(6), newArrayList());
result.get(weekStart).add(withLessonNumber(cancelledLesson(), 7));
result.get(weekStart.plusDays(1)).add(withLessonNumber(substitutionLesson(), 7));
//Empty lesson
result.get(weekStart.plusDays(2)).remove(2);
return result;
}
示例11: bindViewHolder
import org.joda.time.DateTimeConstants; //导入依赖的package包/类
@Override
public void bindViewHolder(FlexibleAdapter adapter, ViewHolder holder, int position, List payloads) {
this.backgroundView = holder.background;
this.title = holder.announcementSubject;
holder.announcementSubject.setText(announcement.subject());
ViewCompat.setTransitionName(holder.background, "announcement_background_" + announcement.id());
LibrusUtils.setTextViewValue(holder.announcementTeacherName, announcement.addedByName());
holder.announcementContent.setText(announcement.content());
Reader reader = new Reader(holder.itemView.getContext());
if (!reader.isRead(announcement))
holder.announcementSubject.setTypeface(holder.announcementSubject.getTypeface(), Typeface.BOLD);
else
holder.announcementSubject.setTypeface(null, Typeface.NORMAL);
if (announcement.startDate().isBefore(LocalDate.now().withDayOfWeek(DateTimeConstants.MONDAY)))
holder.announcementDate.setText(announcement.startDate().toString("d MMM."));
else
holder.announcementDate.setText(announcement.startDate().dayOfWeek().getAsShortText(new Locale("pl")));
}
示例12: getDateTimeDifferenceInMinutes
import org.joda.time.DateTimeConstants; //导入依赖的package包/类
/**
* @param d2
* @param d1
* @return the difference d2-d1 in minutes
*/
public static long getDateTimeDifferenceInMinutes(DateTime d2, DateTime d1) {
if(d2.toLocalDate().isEqual(d1.toLocalDate())) {
return d2.getMinuteOfDay() - d1.getMinuteOfDay();
}
else {
int minutesFromD1ToNextDay = DateTimeConstants.MINUTES_PER_DAY - d1.getMinuteOfDay();
int minutesFromD2ToPreviousDay = d2.getMinuteOfDay();
DateTime dayAfterD1 = endOfDay(d1).plusMillis(1);
DateTime dayBeforeD2 = startOfDay(d2);
int daysDifference = dayBeforeD2.getDayOfYear() - dayAfterD1.getDayOfYear()
+ (dayBeforeD2.getYear() - dayAfterD1.getYear()) * 365;
return minutesFromD1ToNextDay + minutesFromD2ToPreviousDay + daysDifference * DateTimeConstants.MINUTES_PER_DAY;
}
}
示例13: millisPerUnit
import org.joda.time.DateTimeConstants; //导入依赖的package包/类
private static int millisPerUnit(String unit) {
switch (Ascii.toLowerCase(unit)) {
case "d":
return DateTimeConstants.MILLIS_PER_DAY;
case "h":
return DateTimeConstants.MILLIS_PER_HOUR;
case "m":
return DateTimeConstants.MILLIS_PER_MINUTE;
case "s":
return DateTimeConstants.MILLIS_PER_SECOND;
case "ms":
return 1;
default:
throw new IllegalArgumentException("Unknown duration unit " + unit);
}
}
示例14: testCreatePeriod
import org.joda.time.DateTimeConstants; //导入依赖的package包/类
@Test
public void testCreatePeriod()
{
DateTime testDate = new DateTime( 2009, 4, 27, 0, 0 );
WeeklyPeriodType wpt = new WeeklyPeriodType();
Period p = wpt.createPeriod( testDate.toDate() );
DateTime startDate = new DateTime( 2009, 4, 27, 0, 0 );
DateTime endDate = new DateTime( 2009, 5, 3, 0, 0 );
assertFalse( "start date after given date", startDate.isAfter( p.getStartDate().getTime() ) );
assertFalse( "end date before given date", endDate.isAfter( p.getEndDate().getTime() ) );
assertTrue( startDate.getDayOfWeek() == DateTimeConstants.MONDAY );
assertTrue( endDate.getDayOfWeek() == DateTimeConstants.SUNDAY );
}
示例15: run
import org.joda.time.DateTimeConstants; //导入依赖的package包/类
@Scheduled(fixedRate=DateTimeConstants.MILLIS_PER_DAY)
public void run() {
LocalDateTime lastImport = service.getLastImportDate(PublicationSource.ARXIV);
for (String feedKey : FEEDS) {
SyndFeedInput input = new SyndFeedInput();
try {
SyndFeed feed = input.build(new XmlReader(new URL(ROOT_RSS_URL + feedKey)));
List<String> ids = new ArrayList<String>(feed.getEntries().size());
for (SyndEntry entry : feed.getEntries()) {
ids.add(entry.getLink().replace(URI_PREFIX, ""));
}
URL url = new URL("http://export.arxiv.org/api/query?id_list=" + joiner.join(ids) + "&max_results=100");
try (InputStream inputStream = url.openStream()) {
List<Publication> publications = extractPublications(inputStream, lastImport, ids.size());
publications = publications.stream().filter(p -> p.getCreated().isAfter(lastImport)).collect(Collectors.toList());
logger.info("Obtained publications from arxiv for category {}: {}", feedKey, publications.size());
service.storePublication(publications);
}
} catch (IllegalArgumentException | FeedException | IOException e) {
logger.error("Problem getting arxiv RSS feed", e);
}
}
}