Dates provides additional extension methods on top of the Date type.

using Dates;

@author Jason O'Neil @author Franco Ponticelli

Static variables

staticread onlyorder:Ord<Date> = Ord.fromIntComparison(compare)

Static methods

staticcompare (a:Date, b:Date):Int

It compares two dates.

staticcreate (year:Int, month:Int = 0, day:Int = 1, hour:Int = 0, minute:Int = 0, second:Int = 0):Date

Creates a Date by using the passed year, month, day, hour, minute, second.

Note that each argument can overflow its normal boundaries (e.g. a month value of -33 is perfectly valid) and the method will normalize that value by offsetting the other arguments by the right amount.

staticdaysInMonth (year:Int, month:Int):Int

Returns the number of days in a month.

Parameters:

month

An integer representing the month. (Jan=0, Dec=11)

year

An 4 digit integer representing the year.

Throws:

Error

if the month is not between 0 and 11.

Returns:

Int, the number of days in the month.

staticdaysInThisMonth (d:Date):Int

Tells how many days in the month of the given date.

Parameters:

date

The date representing the month we are checking.

Returns:

Int, the number of days in the month.

staticdaysRange (start:Date, end:Date):Array<Date>

Creates an array of dates that begin at start and end at end included.

Time values are pick from the start value except for the last value that will match end. No interpolation is made.

staticinline equals (self:Date, other:Date):Bool

Returns true if the passed dates are the same.

staticinline greater (self:Date, other:Date):Bool

Returns true if the self date is greater than other.

staticinline greaterEquals (self:Date, other:Date):Bool

Returns true if the self date is greater than or equal to other.

staticinline isInLeapYear (d:Date):Bool

Tells if the given date is inside a leap year.

Parameters:

date

The date object to check.

Returns:

True if it is in a leap year, false otherwise.

staticisLeapYear (year:Int):Bool

Tells if a year is a leap year.

Parameters:

year

The year, represented as a 4 digit integer

Returns:

True if a leap year, false otherwise.

staticjump (date:Date, period:TimePeriod, amount:Int):Date

Get a date relative to the current date, shifting by a set period of time.

Please note this works by constructing a new date object, rather than using DateTools.delta(). The key difference is that this allows us to jump over a period that may not be a set number of seconds. For example, jumping between months (which have different numbers of days), leap years, leap seconds, daylight savings time changes etc.

Parameters:

date

The starting date.

period

The TimePeriod you wish to jump by, Second, Minute, Hour, Day, Week, Month or Year.

amount

The multiple of period that you wish to jump by. A positive amount moves forward in time, a negative amount moves backward.

staticinline less (self:Date, other:Date):Bool

Returns true if the self date is lesser than other.

staticinline lessEqual (self:Date, other:Date):Bool

staticinline lessEquals (self:Date, other:Date):Bool

Returns true if the self date is lesser than or equal to other.

staticmax (self:Date, other:Date):Date

Finds and returns which of the two passed dates is the newest.

staticmin (self:Date, other:Date):Date

Finds and returns which of the two passed dates is the oldest.

staticinline more (self:Date, other:Date):Bool

staticinline moreEqual (self:Date, other:Date):Bool

staticnearEquals (self:Date, other:Date, units:Int = 1, ?period:TimePeriod):Bool

Returns true if the dates are approximately equals. The amount of delta allowed is determined by units and it spans that amount equally before and after the self date. The default unit value is 1.

The default period range is Second.

staticinline nextDay (d:Date):Date

Returns a new date, exactly 1 day after the given date/time.

staticinline nextHour (d:Date):Date

Returns a new date, exactly 1 hour after the given date/time.

staticinline nextMinute (d:Date):Date

Returns a new date, exactly 1 minute after the given date/time.

staticinline nextMonth (d:Date):Date

Returns a new date, exactly 1 month after the given date/time.

staticinline nextSecond (d:Date):Date

Returns a new date, exactly 1 second after the given date/time.

staticinline nextWeek (d:Date):Date

Returns a new date, exactly 1 week after the given date/time.

staticinline nextYear (d:Date):Date

Returns a new date, exactly 1 year after the given date/time.

staticnumDaysInMonth (month:Int, year:Int):Int

staticnumDaysInThisMonth (d:Date):Int

staticparseDate (s:String):Either<String, Date>

Safely parse a string value to a date.

staticinline prevDay (d:Date):Date

Returns a new date, exactly 1 day before the given date/time.

staticinline prevHour (d:Date):Date

Returns a new date, exactly 1 hour before the given date/time.

staticinline prevMinute (d:Date):Date

Returns a new date, exactly 1 minute before the given date/time.

staticinline prevMonth (d:Date):Date

Returns a new date, exactly 1 month before the given date/time.

staticinline prevSecond (d:Date):Date

Returns a new date, exactly 1 second before the given date/time.

staticinline prevWeek (d:Date):Date

Returns a new date, exactly 1 week before the given date/time.

staticinline prevYear (d:Date):Date

Returns a new date, exactly 1 year before the given date/time.

staticsameDay (self:Date, other:Date):Bool

Returns true if the 2 dates share the same year, month and day.

staticsameHour (self:Date, other:Date):Bool

Returns true if the 2 dates share the same year, month, day and hour.

staticsameMinute (self:Date, other:Date):Bool

Returns true if the 2 dates share the same year, month, day, hour and minute.

staticsameMonth (self:Date, other:Date):Bool

Returns true if the 2 dates share the same year and month.

staticsameYear (self:Date, other:Date):Bool

Returns true if the 2 dates share the same year.

staticinline snapNext (date:Date, period:TimePeriod):Date

Snaps a Date to the next second, minute, hour, day, week, month or year.

Parameters:

date

The date to snap. See Date.

period

Either: Second, Minute, Hour, Day, Week, Month or Year

Returns:

The snapped date.

staticsnapNextWeekDay (date:Date, day:Weekday):Date

Snaps a date to the next given weekday. The time within the day will stay the same.

If you are already on the given day, the date will not change.

Parameters:

date

The date value to snap

day

Day to snap to. Either Sunday, Monday, Tuesday etc.

Returns:

The date of the day you have snapped to.

staticinline snapPrev (date:Date, period:TimePeriod):Date

Snaps a Date to the previous second, minute, hour, day, week, month or year.

Parameters:

date

The date to snap. See Date.

period

Either: Second, Minute, Hour, Day, Week, Month or Year

Returns:

The snapped date.

staticsnapPrevWeekDay (date:Date, day:Weekday):Date

Snaps a date to the previous given weekday. The time within the day will stay the same.

If you are already on the given day, the date will not change.

Parameters:

date

The date value to snap

day

Day to snap to. Either Sunday, Monday, Tuesday etc.

Returns:

The date of the day you have snapped to.

staticinline snapTo (date:Date, period:TimePeriod):Date

Snaps a Date to the nearest second, minute, hour, day, week, month or year.

Parameters:

date

The date to snap. See Date.

period

Either: Second, Minute, Hour, Day, Week, Month or Year

Returns:

The snapped date.

staticsnapToWeekDay (date:Date, day:Weekday, firstDayOfWk:Weekday = Sunday):Date

Snaps a date to the given weekday inside the current week. The time within the day will stay the same.

If you are already on the given day, the date will not change.

Parameters:

date

The date value to snap

day

Day to snap to. Either Sunday, Monday, Tuesday etc.

firstDayOfWk

The first day of the week. Default to Sunday.

Returns:

The date of the day you have snapped to.

staticwithDay (date:Date, day:Int):Date

Returns a new date that is modified only by the day.

staticwithHour (date:Date, hour:Int):Date

Returns a new date that is modified only by the hour.

staticwithMinute (date:Date, minute:Int):Date

Returns a new date that is modified only by the minute.

staticwithMonth (date:Date, month:Int):Date

Returns a new date that is modified only by the month (remember that month indexes begin at zero).

staticwithSecond (date:Date, second:Int):Date

Returns a new date that is modified only by the second.

staticwithYear (date:Date, year:Int):Date

Returns a new date that is modified only by the year.