This is an utility class that wraps the standard Date
class
providing some useful methods without using the Calendar
object.
dependencies {
compile 'com.llollox.androidprojects:wdate:1.2.1'
}
<dependency>
<groupId>com.llollox.androidprojects</groupId>
<artifactId>wdate</artifactId>
<version>1.2.1</version>
<type>pom</type>
</dependency>
The first thing to do is set the date for our
WDate
object. This can be done in the following manner:
// Set its date as now
WDate wdate = new WDate();
// Set as its date the one passed as argument
WDate wdate = new WDate(yourDate);
// Get the Date object
Date date = wDate.getDate();
// By default the week starts on Monday,
// but it is possible to customize it
// configuring the wdate object setting it
// with WeekStart.SUNDAY
wDate.setWeekStart(WeekStart weekStart);
boolean isToday()
boolean isTomorrow()
boolean isYesterday()
// Week
boolean isMonday();
boolean isThursday();
boolean isWednesday();
boolean isTuesday();
boolean isFriday();
boolean isSaturday();
boolean isSunday();
// Time
boolean isAtMidNight();
// Returns the number of days (absolute value) between the dates.
// The wdate's date is included, the other one not.
int getNumDaysBetween(Date date)
// Returns the number of months (absolute value) between the dates.
// The wdate's date is included, the other one not.
int getNumMonthsBetween(Date date)
// Returns the number of years (absolute value) between the dates.
// The wdate's date is included, the other one not.
int getNumYearsBetween(Date date)
// Returns the number of milliseconds (absolute value) between the dates.
long getMilliSecondsDifference(Date date)
// Checks if the wdate's date is contained in the period.
// Both start and end date limits are excluded.
boolean isInRange (Date start, Date end)
// Checks if both dates have same day, month and year.
boolean isSameDay(Date date)
// Set the time to midnight 00:00:00.000
WDate atMidnight()
// Format string following the Simple Date Format pattern.
String format (String sdfPattern)
int getDay () // Day number in the month
int getMonth () // Months start from 0
int getYear ()
int getHours () // 24h format
int getMinutes ()
int getSeconds ()
int getMilliSeconds ()
Date getFirstDayOfWeek ()
Date getLastDayOfWeek ()
Date getFirstDayOfMonth ()
Date getLastDayOfMonth ()
Date getFirstDayOfYear ()
Date getLastDayOfYear ()
All modifiers supports method chaining.
WDate addDays (int numDays)
WDate addMonths (int numMonths)
WDate addYears (int numYears)
WDate addHours (int numHours)
WDate addMinutes (int numMinutes)
WDate addSeconds (int numSeconds)
WDate addMilliSeconds (int numMilliSeconds)
All setters supports method chaining.
WDate setDay (int days)
WDate setMonth (int months)
WDate setYear (int years)
WDate setHours (int hours)
WDate setMinutes (int minutes)
WDate setSeconds (int seconds)
WDate setMilliSeconds (int milliSeconds)
The following methods return a WDate
object
with the time set at midnight (00:00:00)
WDate.dayAfterTomorrow()
WDate.dayBeforeYesterday()
WDate.today()
WDate.tomorrow()
WDate.yesterday()
WDate.min(List<Date> dates)
WDate.max(List<Date> dates)