140 lines
2.7 KiB
GDScript
140 lines
2.7 KiB
GDScript
class_name TimeTool
|
|
|
|
static func is_leap_year(year:int)->bool:
|
|
|
|
if year%4==0 and year%100!=0:
|
|
return true
|
|
elif year%400==0:
|
|
return true
|
|
else:
|
|
return false
|
|
|
|
static func is_in_date(data:Dictionary,now_time:Dictionary)->bool:
|
|
var from_time:Dictionary
|
|
if data.has("from"):
|
|
from_time=data["from"]
|
|
else:
|
|
from_time={
|
|
|
|
"year":-999999,
|
|
"month":-1,
|
|
"day":-1
|
|
}
|
|
var to_time:Dictionary
|
|
if data.has("to"):
|
|
to_time=data["to"]
|
|
else:
|
|
to_time={
|
|
|
|
"year":99999999,
|
|
"month":-1,
|
|
"day":-1
|
|
}
|
|
return date_limit(from_time,to_time,now_time)
|
|
|
|
|
|
static func date_limit(from:Dictionary,to:Dictionary,now_time:Dictionary)->bool:
|
|
var dic:Dictionary=now_time
|
|
var from_year=from["year"]
|
|
var from_month
|
|
if from.has("month"):
|
|
from_month=from["month"]
|
|
else:
|
|
from_month=1
|
|
var from_day
|
|
if from.has("day"):
|
|
from_day=from["day"]
|
|
else:
|
|
from_day=1
|
|
var to_year=to["year"]
|
|
var to_month
|
|
if to.has("month"):
|
|
to_month=to["month"]
|
|
else:
|
|
to_month=1
|
|
var to_day
|
|
if to.has("day"):
|
|
to_day=to["day"]
|
|
else:
|
|
to_day=1
|
|
var now_year=dic["year"]
|
|
var now_month=dic["month"]
|
|
var now_day=dic["day"]
|
|
return date_CMOS(now_year,now_month,now_day,from_year,from_month,from_day) and date_CMOS(to_year,to_month,to_day,now_year,now_month,now_day)
|
|
pass
|
|
|
|
|
|
static func date_CMOS(from_year:int,from_month:int,from_day:int,to_year:int,to_month:int,to_day:int):
|
|
if from_year>to_year:
|
|
return true
|
|
elif from_year==to_year:
|
|
if from_month>to_month:
|
|
return true
|
|
elif from_month==to_month:
|
|
return from_day>=to_day
|
|
else:
|
|
return false
|
|
pass
|
|
else:
|
|
return false
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static func is_in_time(data:Dictionary,now_time:Dictionary)->bool:
|
|
var from_time:Dictionary
|
|
if data.has("from"):
|
|
from_time=data["from"]
|
|
else:
|
|
from_time={
|
|
"hour":-1,
|
|
"minute":-1
|
|
}
|
|
var to_time:Dictionary
|
|
if data.has("to"):
|
|
to_time=data["to"]
|
|
else:
|
|
to_time={
|
|
"hour":25,
|
|
"minute":61
|
|
}
|
|
return time_limit(from_time,to_time,now_time)
|
|
|
|
static func time_limit(from:Dictionary,to:Dictionary,now_time:Dictionary)->bool:
|
|
var dic:Dictionary=now_time
|
|
var from_hour=from["hour"]
|
|
var from_minute
|
|
if from.has("minute"):
|
|
from_minute=from["minute"]
|
|
else:
|
|
from_minute=0
|
|
var to_hour=to["hour"]
|
|
var to_minute
|
|
if to.has("minute"):
|
|
to_minute=to["minute"]
|
|
else:
|
|
to_minute=0
|
|
var now_hour=dic["hour"]
|
|
var now_minute=dic["minute"]
|
|
return time_CMOS(now_hour,now_minute,from_hour,from_minute) and time_CMOS(to_hour,to_minute,now_hour,now_minute)
|
|
pass
|
|
static func time_CMOS(from_hour:int,from_minute:int,to_hour:int,to_minute:int)->bool:
|
|
|
|
if from_hour>to_hour:
|
|
return true
|
|
elif from_hour==to_hour:
|
|
if from_minute>=to_minute:
|
|
return true
|
|
else:
|
|
return false
|
|
pass
|
|
else:
|
|
return false
|