Time

package
v0.0.0-...-5eaf078 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2025 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package Time provides methods for working with Time object instances.

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 [param utc] is [code]false[/code], 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 [param utc] is [code]false[/code], 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: [code]year[/code], [code]month[/code], [code]day[/code], [code]hour[/code], [code]minute[/code], and [code]second[/code]. Any other entries (including [code]dst[/code]) are ignored. If the dictionary is empty, [code]0[/code] 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 [param use_space] is [code]true[/code], 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 [param utc] is [code]false[/code], otherwise they are in UTC. If [param use_space] is [code]true[/code], 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 [param utc] is [code]false[/code], otherwise they are in UTC. If [param use_space] is [code]true[/code], 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 [param use_space] is [code]true[/code], 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 [param use_space] is [code]true[/code], 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 [param utc] is [code]false[/code], 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 [param utc] is [code]false[/code], 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 GetTimeZoneFromSystem

func GetTimeZoneFromSystem() map[string]string

Returns the current time zone as a dictionary of keys: [code]bias[/code] and [code]name[/code]. - [code]bias[/code] is the offset from UTC in minutes, since not all time zones are multiples of an hour from UTC. - [code]name[/code] is the localized name of the time zone, according to the OS locale settings of the current user.

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: [code]year[/code], [code]month[/code], [code]day[/code], [code]hour[/code], [code]minute[/code], and [code]second[/code]. Any other entries (including [code]dst[/code]) are ignored. If the dictionary is empty, [code]0[/code] 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 [method get_datetime_dict_from_unix_time] directly into this function and get the same as what was put in. [b]Note:[/b] 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. [b]Note:[/b] 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. [b]Note:[/b] 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 [url=https://en.wikipedia.org/wiki/Unix_time]Unix epoch[/url]. [b]Note:[/b] Unlike other methods that use integer timestamps, this method returns the timestamp as a [float] 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: [code]year[/code], [code]month[/code], [code]day[/code], [code skip-lint]weekday[/code], [code]hour[/code], [code]minute[/code], and [code]second[/code]. If [param weekday] is [code]false[/code], then the [code skip-lint]weekday[/code] entry is excluded (the calculation is relatively expensive). [b]Note:[/b] 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: [code]year[/code], [code]month[/code], [code]day[/code], [code]weekday[/code], [code]hour[/code], [code]minute[/code], [code]second[/code], and [code]dst[/code] (Daylight Savings Time).

func GetDatetimeDictFromSystemOptions

func GetDatetimeDictFromSystemOptions(utc bool) Date

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

func GetDatetimeDictFromUnixTime

func GetDatetimeDictFromUnixTime(unix_time_val int) Date

Converts the given Unix timestamp to a dictionary of keys: [code]year[/code], [code]month[/code], [code]day[/code], [code]weekday[/code], [code]hour[/code], [code]minute[/code], and [code]second[/code]. The returned Dictionary's values will be the same as the [method get_datetime_dict_from_system] 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: [code]year[/code], [code]month[/code], [code]day[/code], and [code]weekday[/code]. The returned values are in the system's local time when [param utc] is [code]false[/code], otherwise they are in UTC.

func GetDateDictFromSystemOptions

func GetDateDictFromSystemOptions(utc bool) DateOnly

Returns the current date as a dictionary of keys: [code]year[/code], [code]month[/code], [code]day[/code], and [code]weekday[/code]. The returned values are in the system's local time when [param utc] is [code]false[/code], otherwise they are in UTC.

func GetDateDictFromUnixTime

func GetDateDictFromUnixTime(unix_time_val int) DateOnly

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

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

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 [code]1582-10-15[/code] is [code]1582-10-14[/code], not [code]1582-10-04[/code]. The year before 1 AD (aka 1 BC) is number [code]0[/code], with the year before that (2 BC) being [code]-1[/code], 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 [code]utc[/code] parameter. However, the [method get_unix_time_from_system] method always uses UTC as it returns the seconds passed since the [url=https://en.wikipedia.org/wiki/Unix_time]Unix epoch[/url]. [b]Important:[/b] The [code]_from_system[/code] methods use the system clock that the user can manually set. [b]Never use[/b] this method for precise time calculation since its results are subject to automatic adjustments by the user or the operating system. [b]Always use[/b] [method get_ticks_usec] or [method get_ticks_msec] for precise time calculation instead, since they are guaranteed to be monotonic (i.e. never decrease).

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) UnsafePointer

func (self *Instance) UnsafePointer() unsafe.Pointer

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 [code]01[/code].*/
	MonthJanuary Month = 1
	/*The month of February, represented numerically as [code]02[/code].*/
	MonthFebruary Month = 2
	/*The month of March, represented numerically as [code]03[/code].*/
	MonthMarch Month = 3
	/*The month of April, represented numerically as [code]04[/code].*/
	MonthApril Month = 4
	/*The month of May, represented numerically as [code]05[/code].*/
	MonthMay Month = 5
	/*The month of June, represented numerically as [code]06[/code].*/
	MonthJune Month = 6
	/*The month of July, represented numerically as [code]07[/code].*/
	MonthJuly Month = 7
	/*The month of August, represented numerically as [code]08[/code].*/
	MonthAugust Month = 8
	/*The month of September, represented numerically as [code]09[/code].*/
	MonthSeptember Month = 9
	/*The month of October, represented numerically as [code]10[/code].*/
	MonthOctober Month = 10
	/*The month of November, represented numerically as [code]11[/code].*/
	MonthNovember Month = 11
	/*The month of December, represented numerically as [code]12[/code].*/
	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: [code]hour[/code], [code]minute[/code], and [code]second[/code]. The returned values are in the system's local time when [param utc] is [code]false[/code], otherwise they are in UTC.

func GetTimeDictFromSystemOptions

func GetTimeDictFromSystemOptions(utc bool) OnTheClock

Returns the current time as a dictionary of keys: [code]hour[/code], [code]minute[/code], and [code]second[/code]. The returned values are in the system's local time when [param utc] is [code]false[/code], otherwise they are in UTC.

func GetTimeDictFromUnixTime

func GetTimeDictFromUnixTime(unix_time_val int) OnTheClock

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

type Weekday

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

Jump to

Keyboard shortcuts

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