2023-03-03 21:12:54 +00:00
|
|
|
## 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)
|
|
|
|
|
|
|
|
|
2023-04-25 22:19:35 +00:00
|
|
|
func from_unix_time(unix_time: int) -> TimeStamp:
|
|
|
|
var time := Time.get_datetime_dict_from_unix_time(unix_time)
|
|
|
|
return from_dict(time)
|
|
|
|
|
|
|
|
|
|
|
|
func equals(other) -> bool:
|
|
|
|
return (
|
|
|
|
other.year == year and \
|
|
|
|
other.month == month and \
|
|
|
|
other.day == day and \
|
|
|
|
other.weekday == weekday and \
|
|
|
|
other.hour == hour and \
|
|
|
|
other.minute == minute and \
|
|
|
|
other.second == second and \
|
|
|
|
other.unix == unix
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-03-03 21:12:54 +00:00
|
|
|
func _to_string() -> String:
|
|
|
|
return Time.get_datetime_string_from_datetime_dict(to_dict(), false)
|
2023-04-25 22:19:35 +00:00
|
|
|
|