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

using Dates;

Static variables

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

Static methods

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

It compares two dates.

@:value({ second : 0, minute : 0, hour : 0, day : 1, month : 0 })@:noUsingstaticcreate(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.

Returns:

Int, the number of days in the month.

Throws:

Error

if the month is not between 0 and 11.

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.

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

Returns true if the passed dates are the same.

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

Returns true if the self date is greater than other.

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

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

staticinlineisInLeapYear(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.

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

Returns true if the self date is lesser than other.

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

Deprecated: "lessEqual is deprecated, use lessEquals instead"

staticinlinelessEquals(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.

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

Deprecated: "more is deprecated, use greater instead"

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

Deprecated: "moreEqual is deprecated, use greaterEquals instead"

@:value({ units : 1 })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.

staticinlinenextDay(d:Date):Date

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

staticinlinenextHour(d:Date):Date

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

staticinlinenextMinute(d:Date):Date

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

staticinlinenextMonth(d:Date):Date

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

staticinlinenextSecond(d:Date):Date

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

staticinlinenextWeek(d:Date):Date

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

staticinlinenextYear(d:Date):Date

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

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

Deprecated: "Use daysIntMonth instead. Also notice that arguments are inverted now"

@:depreacated("use daysInThisMonth instead")staticnumDaysInThisMonth(d:Date):Int

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

Safely parse a string value to a date.

staticinlineprevDay(d:Date):Date

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

staticinlineprevHour(d:Date):Date

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

staticinlineprevMinute(d:Date):Date

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

staticinlineprevMonth(d:Date):Date

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

staticinlineprevSecond(d:Date):Date

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

staticinlineprevWeek(d:Date):Date

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

staticinlineprevYear(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.

staticinlinesnapNext(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.

staticinlinesnapPrev(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.

staticinlinesnapTo(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.

@:value({ firstDayOfWk : Sunday })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.