Date Object

A Date object describes a single date and time.

Date Type Commands

Date.now v1.1

Returns a Date object describing the current date & time. This value does not update, eg: the date and time are fixed at the point of creation.

Date.newWithText someText v2.1

Returns a Date object extracted from the given piece of text. The format of the text is not exact; parsing is lenient and will use system localization as needed. For example, in the USA you might see any of the following:

$date = Date.newWithText("12/25/2013")

$date = Date.newWithText("12/25/2013 10AM")

$date = Date.newWithText("December 25, 2013")

Generally, this should be used to parse dates from user input.

Date.newWithYearMonthDay year, month, day v2.1

Returns a Date object using the given date components. Time is set at 00:00:00.

Date.newWithYearMonthDayHourMinuteSecond year, month, day, hour, min, sec v2.1

Returns a Date object using the given date and time components.

Date.nameOfMonth monthNumber v1.1

Returns the localized name of the given month number, which should be between 1-12. The language used for the localization is the one currently used to run the application (eg: the language as set by system preferences and/or the Finder).

Date.nameOfWeekday weekdayNumber v1.1

Returns the localized name of the given weekday number, which should be between 1-7. The language used for the localization is the one currently used to run the application (eg: the language as set by system preferences and/or the Finder).

Date.zeroPad number v1.1

Pads the given number to be at least two digits in length, eg: the number 7 becomes ‘07’, the number 13 stays as 13.

Date.textDescribingSeconds seconds v2.0.5

Returns a string that describes the given number of seconds. The returned string will always be accurate to the nearest seconds, but may choose to represent the time in different units, eg:

Date.textDescribingSeconds(62) # returns "1 minute, 2 seconds"

Date Object Properties

.year v1.1

The year of the date, eg: 2008. Read-only.

.month v1.1

The month of the year, 1-12 inclusive. Read-only.

.day v1.1

The day of the month, 1-31 inclusive. Read-only.

.weekday v1.1

The day of the week, 1-7 inclusive. 1 means Monday, 2 for Tuesday, and so on until 7 for Sunday. Read-only.

.hour v1.1

The hour on the 24 hour clock, eg: 0-11 for AM hours, 12-23 for PM hours. Read-only.

.hour12 v1.1

The hour on the 12 hour clock, 1-12 inclusive. Read-only.

.am v1.1

true if time is between 00:00:00 and 11:59:59, otherwise @false. Read-only.

.pm v1.1

true if time is between 12:00:00 and 23:59:59, otherwise @false. Read-only.

.minute v1.1

The minute of the hour, 1-59 inclusive. Read-only.

.second v1.1

The second of the minute, 1-59 inclusive. Read-only.

.secondsSinceUnixEpoch v1.1

The total number of seconds that have elapsed since the Unix epoch (January 1st, 1970). Read-only.

Date Object Commands

.isBeforeDate otherDate v2.1

Returns @true if the date comes before (is older than) the given “otherDate” Date object, otherwise @false.

.isAfterDate otherDate v2.1

Returns @true if the date comes after (is newer than) the given “otherDate” Date object, otherwise @false.

.secondsSinceDate olderDate v2.0.5

Returns the difference in seconds between the two dates, which could be a fractional value. It is assumed that the given Date object is the older of the two; if not then the return value will be negative.

.dateByAddingSeconds seconds v2.0.5

Returns a new Date object that is the given number of seconds later in time. If the given number of seconds is negative, then this returns a prior date, ie: subtraction occurs.

Date Object Example

The following macro would insert the day and month into the active document in the format “April 01”:

$now = Date.now

$day = Date.zeroPad( $now.day ) # turn 1 into "01"

$month = Date.nameOfMonth( $now.month ) # turn 4 into "April"

Insert Text "$month $day"

The following code can be used to describe how long an operation took:

$startDate = Date.now

# do some work

$endDate = Date.now

$seconds = $endDate.secondsSinceDate($startDate)

$message = Date.textDescribingSeconds($seconds)

Prompt "The work took $message."


Previous Chapter
Data Object
<<  index  >>
 
Next Chapter
Color Object