use of hirondelle.date4j.DateTime in project instructure-android by instructure.
the class CaldroidFragment method setSelectedDates.
/**
* Select the dates from fromDate to toDate. By default the background color
* is holo_blue_light, and the text color is black. You can customize the
* background by changing CaldroidFragment.selectedBackgroundDrawable, and
* change the text color CaldroidFragment.selectedTextColor before call this
* method. This method does not refresh view, need to call refreshView()
*
* @param fromDate
* @param toDate
*/
public void setSelectedDates(Date fromDate, Date toDate) {
// Ensure fromDate is before toDate
if (fromDate == null || toDate == null || fromDate.after(toDate)) {
return;
}
selectedDates.clear();
DateTime fromDateTime = CalendarHelper.convertDateToDateTime(fromDate);
DateTime toDateTime = CalendarHelper.convertDateToDateTime(toDate);
DateTime dateTime = fromDateTime;
while (dateTime.lt(toDateTime)) {
selectedDates.add(dateTime);
dateTime = dateTime.plusDays(1);
}
selectedDates.add(toDateTime);
}
use of hirondelle.date4j.DateTime in project instructure-android by instructure.
the class CaldroidFragment method moveToDateTime.
/**
* Move calendar to specified dateTime, with animation
*
* @param dateTime
*/
public void moveToDateTime(DateTime dateTime) {
DateTime firstOfMonth = new DateTime(year, month, 1, 0, 0, 0, 0);
DateTime lastOfMonth = firstOfMonth.getEndOfMonth();
// Calendar swipe left when dateTime is in the past
if (dateTime.lt(firstOfMonth)) {
// Get next month of dateTime. When swipe left, month will
// decrease
DateTime firstDayNextMonth = dateTime.plus(0, 1, 0, 0, 0, 0, 0, DateTime.DayOverflow.LastDay);
// Refresh adapters
pageChangeListener.setCurrentDateTime(firstDayNextMonth, false);
int currentItem = dateViewPager.getCurrentItem();
pageChangeListener.refreshAdapters(currentItem);
// Swipe left
dateViewPager.setCurrentItem(currentItem - 1);
} else // Calendar swipe right when dateTime is in the future
if (dateTime.gt(lastOfMonth)) {
// Get last month of dateTime. When swipe right, the month will
// increase
DateTime firstDayLastMonth = dateTime.minus(0, 1, 0, 0, 0, 0, 0, DateTime.DayOverflow.LastDay);
// Refresh adapters
pageChangeListener.setCurrentDateTime(firstDayLastMonth, false);
int currentItem = dateViewPager.getCurrentItem();
pageChangeListener.refreshAdapters(currentItem);
// Swipe right
dateViewPager.setCurrentItem(currentItem + 1);
}
}
use of hirondelle.date4j.DateTime in project instructure-android by instructure.
the class CalendarHelper method convertDateToDateTime.
/**
* Get the DateTime from Date, with hour and min is 0
*
* @param date
* @return
*/
public static DateTime convertDateToDateTime(Date date) {
// Get year, javaMonth, date
Calendar calendar = Calendar.getInstance();
calendar.clear();
calendar.setTime(date);
int year = calendar.get(Calendar.YEAR);
int javaMonth = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DATE);
// javaMonth start at 0. Need to plus 1 to get datetimeMonth
return new DateTime(year, javaMonth + 1, day, 0, 0, 0, 0);
}
use of hirondelle.date4j.DateTime in project instructure-android by instructure.
the class CalendarListRecyclerAdapter method getEndDate.
private Calendar getEndDate() {
int startDay = getStartDayOfWeek();
Calendar cal = Calendar.getInstance();
ArrayList<DateTime> dates = CalendarHelper.getFullWeeks(mSelectedDay.getMonth(), mSelectedDay.getYear(), startDay, false);
DateTime endDate = dates.get(dates.size() - 1);
cal.set(endDate.getYear(), endDate.getMonth() - 1, endDate.getDay(), endDate.getHour(), endDate.getMinute(), endDate.getSecond());
return cal;
}
use of hirondelle.date4j.DateTime in project instructure-android by instructure.
the class CalendarListRecyclerAdapter method getFirstEndDate.
private Calendar getFirstEndDate() {
int startDay = getStartDayOfWeek();
Calendar cal = Calendar.getInstance();
DateTime today = DateTime.forInstant(cal.getTime().getTime(), TimeZone.getDefault());
ArrayList<DateTime> dates = CalendarHelper.getFullWeeks(today.getMonth(), today.getYear(), startDay, false);
DateTime endDate = dates.get(dates.size() - 1);
cal.set(endDate.getYear(), endDate.getMonth() - 1, endDate.getDay(), endDate.getHour(), endDate.getMinute(), endDate.getSecond());
return cal;
}
Aggregations