View source

abstract thx.DateTime(Array<Int64>)

Available on all platforms

DateTime represents an instant in time since about year 29228 B.C.E. up to 29228 C.E. (A.D.).

DateTime supports a resolution up to 1e7th of second (a tick) and has no precision issues since it is mapped internally to a Int64.

DateTime is an abstract and support some operator overloadings. Most notably subtractions (to get a Time value), and addition/subtraction of a Time value.

DateTime also supports a time offset to describe time zone values.

Class Fields

inline function compare(a:DateTime, b:DateTime):Int

inline function create(year:Int, month:Int, day:Int, hour:Int = 0, minute:Int = 0, second:Int = 0, millisecond:Int = 0, offset:Time):DateTime

Creates a DateTime instance from its components (year, mont, day, hour, minute, second, millisecond and time offset).

All time components are optionals.

function daysRange(start:DateTime, end:DateTime):Array<DateTime>

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.

inline function equals(self:DateTime, that:DateTime):Bool

function fromDate(date:Date):DateTime

Converts a Date type into a DateTime type.

It uses the local server time offset.

function fromDateWithOffset(date:Date, offset:Time):DateTime

Converts a Date type into a DateTime type with a given offset.

function fromString(s:String):DateTime

Converts a string into a DateTime value. The format accepted is looks like this:

2016-08-07T23:18:22.123Z

The decimals of seconds can be omitted (and so should be dot separator .).

T can also be replaced with a whitespace . Z represents the UTC timezone and can be replaced with a time offset in the format:

-06:00

In this case the sign (+/-) is not optional and seconds cannot be used.

function fromTime(timestamp:Float):DateTime

Converts a Float value representing the number of millisecond since Epoch into a DateTime type.

inline function greater(self:DateTime, that:DateTime):Bool

inline function greaterEquals(self:DateTime, that:DateTime):Bool

inline function less(self:DateTime, that:DateTime):Bool

inline function lessEquals(self:DateTime, that:DateTime):Bool

function localOffset():Time

inline function notEquals(self:DateTime, that:DateTime):Bool

inline function now():DateTime

Generates an instance of DateTime for the current instant and with an offset as set on your local machine.

Note that PHP requires a configuration setting to setup a specific timezone or it will default to UTC.

inline function nowUtc():DateTime

Same as now but it returns the current instant as if the time zone was set to UTC.

inline function ord():Ord<DateTime>

Instance Fields

var day(get,null):Int

var dayOfWeek(get,null):Weekday

var dayOfYear(get,null):Int

var hour(get,null):Int

var isInLeapYear(get,null):Bool

var microsecond(get,null):Int

var millisecond(get,null):Int

var minute(get,null):Int

var month(get,null):Int

var monthDays(get,null):Int

var offset(get,null):Time

var second(get,null):Int

var tickInSecond(get,null):Int

var timeOfDay(get,null):Time

var utc(get,null):DateTimeUtc

var year(get,null):Int

inline function new(dateTime:DateTimeUtc, offset:Time):DateTime

DateTime constructor, requires a utc value and an offset.

inline function addDays(days:Float):DateTime

inline function addHours(hours:Float):DateTime

inline function addMilliseconds(milliseconds:Int):DateTime

inline function addMinutes(minutes:Float):DateTime

inline function addMonths(months:Int):DateTime

inline function addSeconds(seconds:Float):DateTime

inline function addYears(years:Int):DateTime

inline function changeOffset(newoffset:Time):DateTime

inline function compareTo(other:DateTime):Int

function daysInThisMonth():Int

Tells how many days in the month of this date.

Returns:

Int, the number of days in the month.

inline function equalsTo(that:DateTime):Bool

inline function greaterEqualsTo(that:DateTime):Bool

inline function greaterThan(that:DateTime):Bool

function jump(period:TimePeriod, amount:Int):DateTime

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. @param period The TimePeriod you wish to jump by, Second, Minute, Hour, Day, Week, Month or Year. @param amount The multiple of period that you wish to jump by. A positive amount moves forward in time, a negative amount moves backward.

inline function lessEqualsTo(that:DateTime):Bool

inline function lessTo(that:DateTime):Bool

inline function max(other:DateTime):DateTime

inline function min(other:DateTime):DateTime

function nearEqualsTo(other:DateTime, span:Time):Bool

inline function nextDay():DateTime

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

inline function nextHour():DateTime

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

inline function nextMinute():DateTime

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

inline function nextMonth():DateTime

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

inline function nextSecond():DateTime

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

inline function nextWeek():DateTime

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

inline function nextYear():DateTime

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

inline function notEqualsTo(that:DateTime):Bool

inline function prevDay():DateTime

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

inline function prevHour():DateTime

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

inline function prevMinute():DateTime

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

inline function prevMonth():DateTime

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

inline function prevSecond():DateTime

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

inline function prevWeek():DateTime

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

inline function prevYear():DateTime

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

function sameDay(other:DateTime):Bool

Returns true if this date and the other date share the same year, month and day.

function sameHour(other:DateTime):Bool

Returns true if this date and the other date share the same year, month, day and hour.

function sameMinute(other:DateTime):Bool

Returns true if this date and the other date share the same year, month, day, hour and minute.

function sameMonth(other:DateTime):Bool

Returns true if this date and the other date share the same year and month.

function sameSecond(other:DateTime):Bool

Returns true if this date and the other date share the same year, month, day, hour, minute and second.

function sameYear(other:DateTime):Bool

Returns true if this date and the other date share the same year.

function snapNext(period:TimePeriod):DateTime

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

Parameters:
period

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

function snapNextWeekDay(weekday:Weekday):DateTime

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.

function snapPrev(period:TimePeriod):DateTime

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

Parameters:
period

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

function snapPrevWeekDay(weekday:Weekday):DateTime

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.

function snapTo(period:TimePeriod):DateTime

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

Parameters:
period

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

function snapToWeekDay(weekday:Weekday, firstDayOfWk:Weekday = Sunday):DateTime

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.

function toString():String

inline function toUtc():DateTimeUtc

function withDay(day:Int):DateTime

function withHour(hour:Int):DateTime

function withMillisecond(millisecond:Int):DateTime

function withMinute(minute:Int):DateTime

function withMonth(month:Int):DateTime

inline function withOffset(offset:Time):DateTime

function withSecond(second:Int):DateTime

function withYear(year:Int):DateTime