-
Notifications
You must be signed in to change notification settings - Fork 224
/
Copy pathtime.dm
173 lines (146 loc) · 4.98 KB
/
time.dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/proc/minutes_to_readable(minutes)
if (!isnum(minutes))
minutes = text2num(minutes)
if (minutes < 0)
PRINT_STACK_TRACE("Negative minutes value supplied to minutes_to_readable().")
return "INFINITE"
else if (isnull(minutes))
PRINT_STACK_TRACE("Null minutes value supplied to minutes_to_readable().")
return "BAD INPUT"
var/hours = 0
var/days = 0
var/weeks = 0
var/months = 0
var/years = 0
if (minutes >= 518400)
years = round(minutes / 518400)
minutes = minutes - (years * 518400)
if (minutes >= 43200)
months = round(minutes / 43200)
minutes = minutes - (months * 43200)
if (minutes >= 10080)
weeks = round(minutes / 10080)
minutes = minutes - (weeks * 10080)
if (minutes >= 1440)
days = round(minutes / 1440)
minutes = minutes - (days * 1440)
if (minutes >= 60)
hours = round(minutes / 60)
minutes = minutes - (hours * 60)
var/result = list()
if (years)
result += "[years] year\s"
if (months)
result += "[months] month\s"
if (weeks)
result += "[weeks] week\s"
if (days)
result += "[days] day\s"
if (hours)
result += "[hours] hour\s"
if (minutes)
result += "[minutes] minute\s"
return jointext(result, ", ")
var/global/roundstart_hour
var/global/station_date = ""
var/global/next_station_date_change = 1 DAY
/proc/stationtime2text()
return time2text(station_time_in_ticks, "hh:mm")
/proc/stationdate2text()
var/update_time = FALSE
if(station_time_in_ticks > next_station_date_change)
next_station_date_change += 1 DAY
update_time = TRUE
if(!station_date || update_time)
var/extra_days = round(station_time_in_ticks / (1 DAY)) DAYS
var/timeofday = world.timeofday + extra_days
station_date = num2text(global.using_map.game_year) + "-" + time2text(timeofday, "MM-DD")
return station_date
/proc/time_stamp()
return time2text(station_time_in_ticks, "hh:mm:ss")
var/global/next_duration_update = 0
var/global/last_round_duration = 0
var/global/round_start_time = 0
/proc/ticks2shortreadable(tick_time, separator = ":")
var/hours = round(tick_time / (1 HOUR))
var/minutes = round((tick_time % (1 HOUR)) / (1 MINUTE))
var/seconds = round((tick_time % (1 MINUTE)) / (1 SECOND))
var/out = list()
if(hours > 0)
out += "[hours]"
if(minutes > 0)
if(minutes < 10 && hours > 0)
out += "0[minutes]"
else
out += "[minutes]"
else if(hours > 0)
out += "00"
if(seconds > 0)
if(seconds < 10 && (minutes > 0 || hours > 0))
out += "0[seconds]"
else
out += "[seconds]"
else if(minutes > 0 || hours > 0)
out += "00"
if(length(out))
return jointext(out, separator)
return null
/proc/ticks2readable(tick_time)
var/hours = round(tick_time / (1 HOUR))
var/minutes = round((tick_time % (1 HOUR)) / (1 MINUTE))
var/seconds = round((tick_time % (1 MINUTE)) / (1 SECOND))
var/out = list()
if(hours > 0)
out += "[hours] hour\s"
if(minutes > 0)
out += "[minutes] minute\s"
if(seconds > 0)
out += "[seconds] second\s"
if(length(out))
return english_list(out)
return "less than a second"
/proc/roundduration2text()
if(!round_start_time)
return "00:00"
if(last_round_duration && world.time < next_duration_update)
return last_round_duration
var/mills = round_duration_in_ticks // 1/10 of a second, not real milliseconds but whatever
//var/secs = ((mills % 36000) % 600) / 10 //Not really needed, but I'll leave it here for reference or something
var/mins = round((mills % 36000) / 600)
var/hours = round(mills / 36000)
mins = mins < 10 ? add_zero(mins, 1) : mins
hours = hours < 10 ? add_zero(hours, 1) : hours
last_round_duration = "[hours]:[mins]"
next_duration_update = world.time + 1 MINUTES
return last_round_duration
var/global/midnight_rollovers = 0
var/global/rollovercheck_last_timeofday = 0
/proc/update_midnight_rollover()
if (world.timeofday < global.rollovercheck_last_timeofday) //TIME IS GOING BACKWARDS!
global.midnight_rollovers += 1
global.rollovercheck_last_timeofday = world.timeofday
return global.midnight_rollovers
/// Increases delay as the server gets more overloaded
/// as sleeps aren't cheap and sleeping only to wake up and sleep again is wasteful
#define DELTA_CALC max(((max(TICK_USAGE, world.cpu) / 100) * max(Master.sleep_delta-1,1)), 1)
/// returns the number of ticks slept
/proc/stoplag(initial_delay)
// If we're initializing, our tick limit might be over 100 (testing config), but stoplag() penalizes procs that go over.
// Unfortunately, this penalty slows down init a *lot*. So, we disable it during boot and lobby, when relatively few things should be calling this.
if (!Master || Master.current_runlevel < 3)
sleep(world.tick_lag)
return 1
if (!initial_delay)
initial_delay = world.tick_lag
. = 0
var/i = DS2TICKS(initial_delay)
do
. += NONUNIT_CEILING(i*DELTA_CALC, 1)
sleep(i * world.tick_lag * DELTA_CALC)
i *= 2
while (TICK_USAGE > min(TICK_LIMIT_TO_RUN, Master.current_ticklimit))
#undef DELTA_CALC
/proc/current_month_and_day()
var/time_string = time2text(world.realtime, "MM-DD")
var/time_list = splittext(time_string, "-")
return list(text2num(time_list[1]), text2num(time_list[2]))