93 lines
2.8 KiB
GDScript
93 lines
2.8 KiB
GDScript
extends Node
|
|
|
|
|
|
var locational_time_offset: int = 7200
|
|
var offset: int = 0 # This is for debug purposes. (Doing sudden time jumps)
|
|
|
|
|
|
func get_current_time() -> int:
|
|
return OS.get_unix_time() + locational_time_offset + offset
|
|
|
|
|
|
func get_time_string(time_stamp: int) -> String:
|
|
var datetime: Dictionary = OS.get_datetime_from_unix_time(time_stamp)
|
|
|
|
var hour = datetime["hour"]
|
|
var minute = datetime["minute"]
|
|
var am_pm
|
|
|
|
var offset_wrapped_hour = wrapi(hour - 1, 0, 24)
|
|
var processed_hour = offset_wrapped_hour
|
|
if offset_wrapped_hour >= 12:
|
|
processed_hour -= 12
|
|
|
|
if hour >= 12:
|
|
am_pm = " PM"
|
|
else:
|
|
am_pm = " AM"
|
|
processed_hour += 1
|
|
|
|
var hour_string = str(processed_hour)
|
|
var minute_string = "%02d" % minute
|
|
|
|
return hour_string + ":" + minute_string + am_pm
|
|
|
|
|
|
func get_date_string(time_stamp: int) -> String:
|
|
var datetime: Dictionary = OS.get_datetime_from_unix_time(time_stamp)
|
|
|
|
var month_string = "%02d" % datetime["month"]
|
|
var day_string = "%02d" % datetime["day"]
|
|
var year_string = str(datetime["year"])
|
|
return month_string + "/" + day_string + "/" + year_string
|
|
|
|
|
|
func is_during_night_time(time_stamp: int) -> bool:
|
|
var datetime: Dictionary = OS.get_datetime_from_unix_time(time_stamp)
|
|
|
|
var hour = datetime["hour"]
|
|
return hour >= Settings.night_time or hour < Settings.inactive_time
|
|
|
|
|
|
func is_during_inactive_time(time_stamp: int) -> bool:
|
|
var datetime: Dictionary = OS.get_datetime_from_unix_time(time_stamp)
|
|
|
|
var hour = datetime["hour"]
|
|
return hour >= Settings.inactive_time and hour < Settings.active_time
|
|
|
|
|
|
func is_during_active_time(time_stamp: int) -> bool:
|
|
var datetime: Dictionary = OS.get_datetime_from_unix_time(time_stamp)
|
|
|
|
var hour = datetime["hour"]
|
|
return hour >= Settings.active_time and hour < Settings.calm_down_time
|
|
|
|
|
|
func is_during_calm_down_time(time_stamp: int) -> bool:
|
|
var datetime: Dictionary = OS.get_datetime_from_unix_time(time_stamp)
|
|
|
|
var hour = datetime["hour"]
|
|
return hour >= Settings.calm_down_time and hour < Settings.night_time
|
|
|
|
|
|
func get_current_phase_skipped(time_stamp: int) -> int:
|
|
var DAY_IN_SECONDS = 86400
|
|
var datetime: Dictionary = OS.get_datetime_from_unix_time(time_stamp)
|
|
var hour = datetime["hour"]
|
|
|
|
if hour < Settings.inactive_time:
|
|
datetime["hour"] = Settings.inactive_time
|
|
elif hour >= Settings.inactive_time and hour < Settings.active_time:
|
|
datetime["hour"] = Settings.active_time
|
|
elif hour >= Settings.active_time and hour < Settings.calm_down_time:
|
|
datetime["hour"] = Settings.calm_down_time
|
|
elif hour >= Settings.calm_down_time and hour < Settings.night_time:
|
|
datetime["hour"] = Settings.night_time
|
|
else:
|
|
datetime = OS.get_datetime_from_unix_time(time_stamp + DAY_IN_SECONDS)
|
|
datetime["hour"] = Settings.inactive_time
|
|
|
|
datetime["minute"] = 0
|
|
datetime["second"] = 0
|
|
return OS.get_unix_time_from_datetime(datetime)
|