main screen
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
class_name Datetime extends RefCounted
|
||||
|
||||
const WEEKDAYS = {
|
||||
"ru": ["вторник", "среда", "четверг", "пятница", "суббота", "воскресенье"],
|
||||
"en": ["tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"],
|
||||
}
|
||||
|
||||
# var readable is unused and removed to avoid confusion
|
||||
|
||||
static func init_datetime() -> Dictionary:
|
||||
const SEC_IN_YEAR := 31556925.9747
|
||||
const RATIO := SEC_IN_YEAR/432/24/60/60
|
||||
var now := int((1970 * SEC_IN_YEAR + Time.get_unix_time_from_system()) / RATIO - 1970 * SEC_IN_YEAR)
|
||||
var adt = Time.get_datetime_dict_from_unix_time(now)
|
||||
var dt: int = adt["second"] + 60 * adt["minute"] + 3600 * adt["hour"] + \
|
||||
+ 86400 * adt["day"] + 3110400 * adt["month"] + 37324800 * adt["year"]
|
||||
return _to_adventure_dict_dt(dt)
|
||||
|
||||
|
||||
static func add_timedelta(dt, delta_in_min: int) -> int:
|
||||
const TIME_DELTA_DEVIATION: float = 0.2
|
||||
var delta_in_sec = delta_in_min * 60
|
||||
var delta := int(TIME_DELTA_DEVIATION * delta_in_sec)
|
||||
return dt + delta_in_sec + randi_range(-delta, delta)
|
||||
|
||||
|
||||
static func _to_adventure_dict_dt(dt_from: int) -> Dictionary:
|
||||
var dt := {}
|
||||
dt["dt"] = dt_from
|
||||
@warning_ignore("integer_division")
|
||||
dt["year"] = dt_from / 37324800
|
||||
dt_from %= 37324800
|
||||
@warning_ignore("integer_division")
|
||||
dt["month"] = dt_from / 3110400
|
||||
dt_from %= 3110400
|
||||
@warning_ignore("integer_division")
|
||||
dt["day"] = dt_from / 86400
|
||||
dt["weekday"] = dt["day"] % 6
|
||||
|
||||
# TODO replace with language from global settings
|
||||
dt["weekdayname"] = WEEKDAYS["ru"][dt.weekday]
|
||||
dt_from %= 86400
|
||||
@warning_ignore("integer_division")
|
||||
dt["hour"] = dt_from / 3600
|
||||
dt_from %= 3600
|
||||
@warning_ignore("integer_division")
|
||||
dt["minute"] = dt_from / 60
|
||||
dt["second"] = dt_from % 60
|
||||
return dt
|
||||
@@ -0,0 +1 @@
|
||||
uid://btdmjpth4vks
|
||||
Reference in New Issue
Block a user