Date and Time API Functions: Unterschied zwischen den Versionen

Aus expecco Wiki (Version 2.x)
Zur Navigation springen Zur Suche springen
Zeile 59: Zeile 59:
== Timestamp ==
== Timestamp ==
Timestamp instances represent a particular point in time. (i.e. "dd-mm-yyyy hh:mm:ss").
Timestamp instances represent a particular point in time. (i.e. "dd-mm-yyyy hh:mm:ss").
Conceptionally, they combine Date and Time with a higher resolution into one object.
Timestamps can be created from strings or acquired from the operating system (although the precision varies among Operating systems - some will only provide millisecond resolution, others provide nanosecond resolution.

Timestamps can be either local timestamps, UTC timestamps or timezone-specific timestamps, and are then instances of one of the classes Timestamp, UTCTimestamp or TZTimestamp.

==== Creation ====
==== Creation ====


Timestamp '''now''' => a timestamp
Timestamp '''now''' => a timestamp
::provides the current timestamp
::provides the current timestamp (local time)
UTCTimestamp '''now''' => a timestamp
::provides the current timestamp (UTC time)
TZTimestamp '''now''' => a timestamp
::provides the current timestamp (in the local timezone)
Timestamp '''year:''' ''y'' '''month:''' ''m'' '''day:''' ''d'' '''hour:''' ''h'' '''minute:''' ''min'' '''second:''' ''s'' '''millisecond:''' ''millis''
::provides a new local timestamp for the given date and time
::also to get UTCTimestamps and TZTimestamps

==== Conversion ====
''aTimestamp'' '''asUTCTimestamp''' => a timestamp
::convert a timestamp to an UTC timestamp
''aTimestamp'' '''asLocalTimestamp''' => a timestamp
::convert a timestamp to a local timestamp (i.e. no timezone info)
''aTimestamp'' '''asTZTimestamp''' => a timestamp
::convert a timestamp to a timestamp for your timezone
''aTimestamp'' '''asTZTimestamp:''' ''utcOffsetInSeconds'' => a timestamp
::convert a timestamp to a timestamp with the given tz offset
''aTimestamp'' '''asTZTimestampInZone:''' ''nameOfTimeZone'' => a timestamp
::convert a timestamp to a timestamp in the given timezone.
::for example to get the current time in NewYork, use "Timestamp now asTZTimestampInZone:'EST'" and to get the time in Stuttgart, use "Timestamp now asTZTimestampInZone:'MEZ'"


== TimeDuration ==
== TimeDuration ==

Version vom 5. Januar 2022, 18:04 Uhr

This document lists most useful (and most often needed) functions. Be aware, that there are many more to be found in either the class references or via the builtin class browser.

Reference: Date Time Timestamp TimeDuration

Back to Useful API Functions

Time[Bearbeiten]

Time instances represent a time-of-day (i.e. "hh:mm:ss" within a single day).
Times are seldom used - usually timestamps are better suited.

Creation[Bearbeiten]

Time now => a time

provides the current time of day

Arithmetic[Bearbeiten]

aTime addSeconds: nSeconds => a time
aTime addMinutes: nMinutes => a time
aTime addHours: nHours => a time

to compute times

Accessing[Bearbeiten]

aTime hours => hours (0..24)
aTime minutes => hours (0..59)
aTime seconds => hours (0..59)

to retrieve the hour, minute and second component:

Date[Bearbeiten]

Date instances represent a date (i.e. "dd-mm-yyyy").
Dates are seldom used - usually timestamps are better suited. However, there are a number of useful query function provided on the class side.

Creation[Bearbeiten]

Date today => a date

provides the current date

Date tomorrow => a date

provides the date of tomorrow

Date yesterday => a date

provides the date of yesterday

Date year: yearNr month: monthNr day: dayNr => a date

for example, "(Date year:2025 month:4 day:20)" generates 20-04-2025 (i.e. 20th April 2025)

Arithmetic[Bearbeiten]

aDate addDays: numDays => a date

to compute a date numDays after aDate

aDate subtractDays: numDays => a date

to compute a date numDays before aDate; for example: "(Date today subtractDays:7)"

aDate subtractDate: date2 => nr of days

to compute the number of days since 1.1.1900, use: "(Date today subtractDate:(Date year:1900 month:1 day:1))"

Accessing[Bearbeiten]

aDate day => day (1..31)
aDate month => month (1..12)
aDate year => year

to retrieve date components.

Timestamp[Bearbeiten]

Timestamp instances represent a particular point in time. (i.e. "dd-mm-yyyy hh:mm:ss"). Conceptionally, they combine Date and Time with a higher resolution into one object. Timestamps can be created from strings or acquired from the operating system (although the precision varies among Operating systems - some will only provide millisecond resolution, others provide nanosecond resolution.

Timestamps can be either local timestamps, UTC timestamps or timezone-specific timestamps, and are then instances of one of the classes Timestamp, UTCTimestamp or TZTimestamp.

Creation[Bearbeiten]

Timestamp now => a timestamp

provides the current timestamp (local time)

UTCTimestamp now => a timestamp

provides the current timestamp (UTC time)

TZTimestamp now => a timestamp

provides the current timestamp (in the local timezone)

Timestamp year: y month: m day: d hour: h minute: min second: s millisecond: millis

provides a new local timestamp for the given date and time
also to get UTCTimestamps and TZTimestamps

Conversion[Bearbeiten]

aTimestamp asUTCTimestamp => a timestamp

convert a timestamp to an UTC timestamp

aTimestamp asLocalTimestamp => a timestamp

convert a timestamp to a local timestamp (i.e. no timezone info)

aTimestamp asTZTimestamp => a timestamp

convert a timestamp to a timestamp for your timezone

aTimestamp asTZTimestamp: utcOffsetInSeconds => a timestamp

convert a timestamp to a timestamp with the given tz offset

aTimestamp asTZTimestampInZone: nameOfTimeZone => a timestamp

convert a timestamp to a timestamp in the given timezone.
for example to get the current time in NewYork, use "Timestamp now asTZTimestampInZone:'EST'" and to get the time in Stuttgart, use "Timestamp now asTZTimestampInZone:'MEZ'"

TimeDuration[Bearbeiten]

Timeduration instances represent a time-delta. (i.e. seconds).



Copyright © 2014-2024 eXept Software AG