Time

package
v0.0.0-...-0d6c339 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

The Time singleton allows converting time between various formats and also getting time information from the system.

This class conforms with as many of the ISO 8601 standards as possible. All dates follow the Proleptic Gregorian calendar. As such, the day before 1582-10-15 is 1582-10-14, not 1582-10-04. The year before 1 AD (aka 1 BC) is number 0, with the year before that (2 BC) being -1, etc.

Conversion methods assume "the same timezone", and do not handle timezone conversions or DST automatically. Leap seconds are also not handled, they must be done manually if desired. Suffixes such as "Z" are not handled, you need to strip them away manually.

When getting time information from the system, the time can either be in the local timezone or UTC depending on the utc parameter. However, the GetUnixTimeFromSystem method always uses UTC as it returns the seconds passed since the Unix epoch.

Important: The _from_system methods use the system clock that the user can manually set. Never use this method for precise time calculation since its results are subject to automatic adjustments by the user or the operating system. Always use GetTicksUsec or GetTicksMsec for precise time calculation instead, since they are guaranteed to be monotonic (i.e. never decrease).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Advanced

func Advanced() class

Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.

func GetDateStringFromSystem

func GetDateStringFromSystem(utc bool) string

Returns the current date as an ISO 8601 date string (YYYY-MM-DD).

The returned values are in the system's local time when 'utc' is false, otherwise they are in UTC.

func GetDateStringFromSystemOptions

func GetDateStringFromSystemOptions(utc bool) string

Returns the current date as an ISO 8601 date string (YYYY-MM-DD).

The returned values are in the system's local time when 'utc' is false, otherwise they are in UTC.

func GetDateStringFromUnixTime

func GetDateStringFromUnixTime(unix_time_val int) string

Converts the given Unix timestamp to an ISO 8601 date string (YYYY-MM-DD).

func GetDatetimeStringFromDatetimeDict

func GetDatetimeStringFromDatetimeDict(datetime Date, use_space bool) string

Converts the given dictionary of keys to an ISO 8601 date and time string (YYYY-MM-DDTHH:MM:SS).

The given dictionary can be populated with the following keys: year, month, day, hour, minute, and second. Any other entries (including dst) are ignored.

If the dictionary is empty, 0 is returned. If some keys are omitted, they default to the equivalent values for the Unix epoch timestamp 0 (1970-01-01 at 00:00:00).

If 'use_space' is true, the date and time bits are separated by an empty space character instead of the letter T.

func GetDatetimeStringFromSystem

func GetDatetimeStringFromSystem(utc bool, use_space bool) string

Returns the current date and time as an ISO 8601 date and time string (YYYY-MM-DDTHH:MM:SS).

The returned values are in the system's local time when 'utc' is false, otherwise they are in UTC.

If 'use_space' is true, the date and time bits are separated by an empty space character instead of the letter T.

func GetDatetimeStringFromSystemOptions

func GetDatetimeStringFromSystemOptions(utc bool, use_space bool) string

Returns the current date and time as an ISO 8601 date and time string (YYYY-MM-DDTHH:MM:SS).

The returned values are in the system's local time when 'utc' is false, otherwise they are in UTC.

If 'use_space' is true, the date and time bits are separated by an empty space character instead of the letter T.

func GetDatetimeStringFromUnixTime

func GetDatetimeStringFromUnixTime(unix_time_val int, use_space bool) string

Converts the given Unix timestamp to an ISO 8601 date and time string (YYYY-MM-DDTHH:MM:SS).

If 'use_space' is true, the date and time bits are separated by an empty space character instead of the letter T.

func GetDatetimeStringFromUnixTimeOptions

func GetDatetimeStringFromUnixTimeOptions(unix_time_val int, use_space bool) string

Converts the given Unix timestamp to an ISO 8601 date and time string (YYYY-MM-DDTHH:MM:SS).

If 'use_space' is true, the date and time bits are separated by an empty space character instead of the letter T.

func GetOffsetStringFromOffsetMinutes

func GetOffsetStringFromOffsetMinutes(offset_minutes int) string

Converts the given timezone offset in minutes to a timezone offset string. For example, -480 returns "-08:00", 345 returns "+05:45", and 0 returns "+00:00".

func GetTicksMsec

func GetTicksMsec() int

Returns the amount of time passed in milliseconds since the engine started.

Will always be positive or 0 and uses a 64-bit value (it will wrap after roughly 500 million years).

func GetTicksUsec

func GetTicksUsec() int

Returns the amount of time passed in microseconds since the engine started.

Will always be positive or 0 and uses a 64-bit value (it will wrap after roughly half a million years).

func GetTimeStringFromSystem

func GetTimeStringFromSystem(utc bool) string

Returns the current time as an ISO 8601 time string (HH:MM:SS).

The returned values are in the system's local time when 'utc' is false, otherwise they are in UTC.

func GetTimeStringFromSystemOptions

func GetTimeStringFromSystemOptions(utc bool) string

Returns the current time as an ISO 8601 time string (HH:MM:SS).

The returned values are in the system's local time when 'utc' is false, otherwise they are in UTC.

func GetTimeStringFromUnixTime

func GetTimeStringFromUnixTime(unix_time_val int) string

Converts the given Unix timestamp to an ISO 8601 time string (HH:MM:SS).

func GetUnixTimeFromDatetimeDict

func GetUnixTimeFromDatetimeDict(datetime Date) int

Converts a dictionary of time values to a Unix timestamp.

The given dictionary can be populated with the following keys: year, month, day, hour, minute, and second. Any other entries (including dst) are ignored.

If the dictionary is empty, 0 is returned. If some keys are omitted, they default to the equivalent values for the Unix epoch timestamp 0 (1970-01-01 at 00:00:00).

You can pass the output from GetDatetimeDictFromUnixTime directly into this function and get the same as what was put in.

Note: Unix timestamps are often in UTC. This method does not do any timezone conversion, so the timestamp will be in the same timezone as the given datetime dictionary.

func GetUnixTimeFromDatetimeString

func GetUnixTimeFromDatetimeString(datetime string) int

Converts the given ISO 8601 date and/or time string to a Unix timestamp. The string can contain a date only, a time only, or both.

Note: Unix timestamps are often in UTC. This method does not do any timezone conversion, so the timestamp will be in the same timezone as the given datetime string.

Note: Any decimal fraction in the time string will be ignored silently.

func GetUnixTimeFromSystem

func GetUnixTimeFromSystem() Float.X

Returns the current Unix timestamp in seconds based on the system time in UTC. This method is implemented by the operating system and always returns the time in UTC. The Unix timestamp is the number of seconds passed since 1970-01-01 at 00:00:00, the Unix epoch.

Note: Unlike other methods that use integer timestamps, this method returns the timestamp as a [Float.X] for sub-second precision.

Types

type Date

type Date struct {
	Year    int `gd:"year"`
	Month   int `gd:"month"`
	Day     int `gd:"day"`
	Weekday int `gd:"weekday"`
	Hour    int `gd:"hour"`
	Minute  int `gd:"minute"`
	Second  int `gd:"second"`
}

func GetDatetimeDictFromDatetimeString

func GetDatetimeDictFromDatetimeString(datetime string, weekday bool) Date

Converts the given ISO 8601 date and time string (YYYY-MM-DDTHH:MM:SS) to a dictionary of keys: year, month, day, weekday, hour, minute, and second.

If 'weekday' is false, then the weekday entry is excluded (the calculation is relatively expensive).

Note: Any decimal fraction in the time string will be ignored silently.

func GetDatetimeDictFromSystem

func GetDatetimeDictFromSystem(utc bool) Date

Returns the current date as a dictionary of keys: year, month, day, weekday, hour, minute, second, and dst (Daylight Savings Time).

func GetDatetimeDictFromSystemOptions

func GetDatetimeDictFromSystemOptions(utc bool) Date

Returns the current date as a dictionary of keys: year, month, day, weekday, hour, minute, second, and dst (Daylight Savings Time).

func GetDatetimeDictFromUnixTime

func GetDatetimeDictFromUnixTime(unix_time_val int) Date

Converts the given Unix timestamp to a dictionary of keys: year, month, day, weekday, hour, minute, and second.

The returned Dictionary's values will be the same as the GetDatetimeDictFromSystem if the Unix timestamp is the current time, with the exception of Daylight Savings Time as it cannot be determined from the epoch.

type DateOnly

type DateOnly struct {
	Year    int `gd:"year"`
	Month   int `gd:"month"`
	Day     int `gd:"day"`
	Weekday int `gd:"weekday"`
}

func GetDateDictFromSystem

func GetDateDictFromSystem(utc bool) DateOnly

Returns the current date as a dictionary of keys: year, month, day, and weekday.

The returned values are in the system's local time when 'utc' is false, otherwise they are in UTC.

func GetDateDictFromSystemOptions

func GetDateDictFromSystemOptions(utc bool) DateOnly

Returns the current date as a dictionary of keys: year, month, day, and weekday.

The returned values are in the system's local time when 'utc' is false, otherwise they are in UTC.

func GetDateDictFromUnixTime

func GetDateDictFromUnixTime(unix_time_val int) DateOnly

Converts the given Unix timestamp to a dictionary of keys: year, month, day, and weekday.

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

type ID

type ID Object.ID

ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Instance

type Instance [1]gdclass.Time

Instance of the class with convieniently typed arguments and results.

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) ID

func (self Instance) ID() ID

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

type Month

type Month int //gd:Time.Month
const (
	// The month of January, represented numerically as 01.
	MonthJanuary Month = 1
	// The month of February, represented numerically as 02.
	MonthFebruary Month = 2
	// The month of March, represented numerically as 03.
	MonthMarch Month = 3
	// The month of April, represented numerically as 04.
	MonthApril Month = 4
	// The month of May, represented numerically as 05.
	MonthMay Month = 5
	// The month of June, represented numerically as 06.
	MonthJune Month = 6
	// The month of July, represented numerically as 07.
	MonthJuly Month = 7
	// The month of August, represented numerically as 08.
	MonthAugust Month = 8
	// The month of September, represented numerically as 09.
	MonthSeptember Month = 9
	// The month of October, represented numerically as 10.
	MonthOctober Month = 10
	// The month of November, represented numerically as 11.
	MonthNovember Month = 11
	// The month of December, represented numerically as 12.
	MonthDecember Month = 12
)

type OnTheClock

type OnTheClock struct {
	Hour   int `gd:"hour"`
	Minute int `gd:"minute"`
	Second int `gd:"second"`
}

func GetTimeDictFromSystem

func GetTimeDictFromSystem(utc bool) OnTheClock

Returns the current time as a dictionary of keys: hour, minute, and second.

The returned values are in the system's local time when 'utc' is false, otherwise they are in UTC.

func GetTimeDictFromSystemOptions

func GetTimeDictFromSystemOptions(utc bool) OnTheClock

Returns the current time as a dictionary of keys: hour, minute, and second.

The returned values are in the system's local time when 'utc' is false, otherwise they are in UTC.

func GetTimeDictFromUnixTime

func GetTimeDictFromUnixTime(unix_time_val int) OnTheClock

Converts the given time to a dictionary of keys: hour, minute, and second.

type Weekday

type Weekday int //gd:Time.Weekday
const (
	// The day of the week Sunday, represented numerically as 0.
	WeekdaySunday Weekday = 0
	// The day of the week Monday, represented numerically as 1.
	WeekdayMonday Weekday = 1
	// The day of the week Tuesday, represented numerically as 2.
	WeekdayTuesday Weekday = 2
	// The day of the week Wednesday, represented numerically as 3.
	WeekdayWednesday Weekday = 3
	// The day of the week Thursday, represented numerically as 4.
	WeekdayThursday Weekday = 4
	// The day of the week Friday, represented numerically as 5.
	WeekdayFriday Weekday = 5
	// The day of the week Saturday, represented numerically as 6.
	WeekdaySaturday Weekday = 6
)

type Zone

type Zone struct {
	Name string `gd:"name"`
	Bias int64  `gd:"bias"`
}

func GetTimeZoneFromSystem

func GetTimeZoneFromSystem() Zone

Returns the current time zone as a dictionary of keys: bias and name.

- bias is the offset from UTC in minutes, since not all time zones are multiples of an hour from UTC.

- name is the localized name of the time zone, according to the OS locale settings of the current user.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL