Time

Operators and functions for working with date and time (time type) are described here.

Types

time

The time type has the following fields:

  • int Year - year

  • int Month - month

  • int Day - day of month

  • int Hour - hour

  • int Minute - minute

  • int Second - second

  • bool UTC - if it is true, then it is UTC time, otherwise it is local time.

Operators

Functions

int(time t) int

The int function converts time value to a Unix time, the number of seconds elapsed since January 1, 1970 UTC and returns it.

time(int unixtime) time

The time function converts the given Unix time, sec seconds since January 1, 1970 UTC to time structure and returns it.

AddHours(time t, int hours) time

The AddHours function returns the time corresponding to adding the given number of hours to t. The hours parameter can be negative.

Date(int year month day) time

The Date function returns a structure of the time type with the specified date.

DateTime(int year month day hour minute second) time

The DateTime function returns the time structure as local time. Also, you can initialize a time variable like this

time t = {Year: 2018, Month: 12, Day: 12}

Days(time t) int

The Days function returns the number of days in the month in which the specified time is located.

Format(str layout, time t) str

The Format function returns a textual representation of the time value formatted according to layout. It takes a string of tokens and replaces them with their corresponding values.

Now() time

The Now function returns the current local time.

ParseTime(str layout, str value) time

The ParseTime function parses a formatted string and returns the time value it represents. The list of layout tokens is the same as in Format function.

run str {
  time t &= ParseTime(`MMM D, YYYY at h:mmpm (zz)`, `Jun 7, 2019 at 6:05am (+0300)`)
  time t1 &= ParseTime(`YY/MM/DD HH:mm:s`, `19/05/29 03:21:3`)
  return Format(`YY/MM/DD HH:mm:ss zz`, UTC(t)) + Format(` YY/MM/DD HH:mm:ss`, UTC(t1))
}
// 19/06/07 03:05:00 +0000 19/05/29 03:21:03

str(time t) str

The str converts the specified time to a string in the format YYYY-MM-DD HH:mm:ss.

UTC(time t) time

The UTC function converts local time to UTC and returns a new time structure. If the time t was already UTC, then a copy of it is returned.

Weekday(time t) int

The Weekday function returns the day of the week specified by t. 0 - Sunday, 1 - Monday etc.

YearDay(time t) int

The YearDay function returns the day of the year specified by t.

Last updated