55 lines
1.1 KiB
GDScript
55 lines
1.1 KiB
GDScript
## A simple proxy for the object returned by Godot's time functions
|
|
## Ensures proper typing
|
|
class_name TimeStamp
|
|
|
|
|
|
var year := 0
|
|
var month := 0
|
|
var day := 0
|
|
var weekday := 0
|
|
var hour := 0
|
|
var minute := 0
|
|
var second := 0
|
|
var unix := 0
|
|
|
|
|
|
func from_current_time() -> TimeStamp:
|
|
return from_dict(Time.get_datetime_dict_from_system())
|
|
|
|
|
|
func from_dict(time: Dictionary) -> TimeStamp:
|
|
year = time.year
|
|
month = time.month
|
|
day = time.day
|
|
weekday = time.weekday
|
|
hour = time.hour
|
|
minute = time.minute
|
|
second = time.second
|
|
unix = Time.get_unix_time_from_datetime_dict(time)
|
|
return self
|
|
|
|
|
|
func to_dict() -> Dictionary:
|
|
return {
|
|
year = year,
|
|
month = month,
|
|
day = day,
|
|
weekday = weekday,
|
|
hour = hour,
|
|
minute = minute,
|
|
second = second,
|
|
}
|
|
|
|
|
|
func get_difference(other_timestamp: TimeStamp) -> int:
|
|
return unix - other_timestamp.unix
|
|
|
|
|
|
func from_string(time_string: String) -> TimeStamp:
|
|
var time := Time.get_datetime_dict_from_datetime_string(time_string, true)
|
|
return from_dict(time)
|
|
|
|
|
|
func _to_string() -> String:
|
|
return Time.get_datetime_string_from_datetime_dict(to_dict(), false)
|