class Dates
package thx
Dates
provides additional extension methods on top of the Date
type.
using Dates;
@author Jason O'Neil @author Franco Ponticelli
Static variables
Static methods
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 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 |
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.
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 nextMinute (d:Date):Date
Returns a new date, exactly 1 minute after the given date/time.
staticinline nextSecond (d:Date):Date
Returns a new date, exactly 1 second after the given date/time.
staticinline prevMinute (d:Date):Date
Returns a new date, exactly 1 minute before the given date/time.
staticinline prevSecond (d:Date):Date
Returns a new date, exactly 1 second 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.
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 |
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 |
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 |
firstDayOfWk | The first day of the week. Default to |
Returns:
The date of the day you have snapped to.
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.