|
@@ -0,0 +1,518 @@
|
|
1
|
+local skynet = require "skynet"
|
|
2
|
+local moduleData = require("data.module")
|
|
3
|
+
|
|
4
|
+local root = {
|
|
5
|
+ SEC_PER_HOUR = 3600,
|
|
6
|
+ SEC_PER_DAY = 86400,
|
|
7
|
+ SEC_PER_WEEK = 7 * 86400,
|
|
8
|
+ REFRESH_HOUR = 5
|
|
9
|
+}
|
|
10
|
+
|
|
11
|
+-- 获取当前时间 单位秒
|
|
12
|
+function root.currentTime()
|
|
13
|
+ return math.floor(skynet.time())
|
|
14
|
+end
|
|
15
|
+-- 获取玩家当前时间
|
|
16
|
+function root.now(uid)
|
|
17
|
+ local currTime = skynet_time()
|
|
18
|
+ if not IS_TEST then
|
|
19
|
+ return currTime
|
|
20
|
+ end
|
|
21
|
+ local deltaTime = moduleData:hget_int(uid, "user", "time:sys")
|
|
22
|
+ if not is_empty(deltaTime) then
|
|
23
|
+ return currTime + deltaTime
|
|
24
|
+ end
|
|
25
|
+ return currTime
|
|
26
|
+end
|
|
27
|
+
|
|
28
|
+function root.toString(t)
|
|
29
|
+ return os.date("%Y-%m-%d %H:%M:%S", t)
|
|
30
|
+end
|
|
31
|
+
|
|
32
|
+function root.toDate(t)
|
|
33
|
+ return os.date("%Y-%m-%d", t or root.currentTime())
|
|
34
|
+end
|
|
35
|
+
|
|
36
|
+function root.toTab(t)
|
|
37
|
+ return os.date("*t", t)
|
|
38
|
+end
|
|
39
|
+
|
|
40
|
+function root.toInt(tab)
|
|
41
|
+ return os.time(tab)
|
|
42
|
+end
|
|
43
|
+
|
|
44
|
+function root.getYday(t)
|
|
45
|
+ return os.date("%j", t)
|
|
46
|
+end
|
|
47
|
+
|
|
48
|
+-- 获取时间的0点时间戳
|
|
49
|
+function root.getCday(ctime)
|
|
50
|
+ local a = root.toTab(ctime)
|
|
51
|
+ a.hour, a.min, a.sec = 0, 0, 0
|
|
52
|
+ return root.toInt(a)
|
|
53
|
+end
|
|
54
|
+
|
|
55
|
+-- 将时间格式化秒 %Y-%m-%d %H:%M:%S
|
|
56
|
+function root.getSecond(t)
|
|
57
|
+ local function split(str, pat)
|
|
58
|
+ local t = {}
|
|
59
|
+ local fpat = "(.-)" .. pat
|
|
60
|
+ local last_end = 1
|
|
61
|
+ local s, e, cap = str:find(fpat, 1)
|
|
62
|
+ while s do
|
|
63
|
+ if s ~= 1 or cap ~= "" then
|
|
64
|
+ table.insert(t, cap)
|
|
65
|
+ end
|
|
66
|
+ last_end = e + 1
|
|
67
|
+ s, e, cap = str:find(fpat, last_end)
|
|
68
|
+ end
|
|
69
|
+
|
|
70
|
+ if last_end <= #str then
|
|
71
|
+ cap = str:sub(last_end)
|
|
72
|
+ table.insert(t, cap)
|
|
73
|
+ end
|
|
74
|
+
|
|
75
|
+ return t
|
|
76
|
+ end
|
|
77
|
+
|
|
78
|
+ local a = split(t, " ")
|
|
79
|
+ local b = split(a[1], "-")
|
|
80
|
+ local c = split(a[2], ":")
|
|
81
|
+
|
|
82
|
+ return root.toInt({year = b[1], month = b[2], day = b[3], hour = c[1], min = c[2], sec = c[3]})
|
|
83
|
+end
|
|
84
|
+
|
|
85
|
+function root.getDayCount(year, month)
|
|
86
|
+ local year = tonumber(year)
|
|
87
|
+ local month = tonumber(month)
|
|
88
|
+ if not year or not month then
|
|
89
|
+ return 0
|
|
90
|
+ end
|
|
91
|
+
|
|
92
|
+ if month == 1 or month == 3 or month == 5 or month == 7 or month == 8 or month == 10 or month == 12 then
|
|
93
|
+ return 31
|
|
94
|
+ end
|
|
95
|
+
|
|
96
|
+ if month == 2 then
|
|
97
|
+ if (year % 4 == 0 and year % 100 ~= 0) or (year % 400 == 0) then
|
|
98
|
+ return 29
|
|
99
|
+ else
|
|
100
|
+ return 28
|
|
101
|
+ end
|
|
102
|
+ end
|
|
103
|
+
|
|
104
|
+ return 30
|
|
105
|
+end
|
|
106
|
+
|
|
107
|
+function root.getTime(year, month, day, hour, min, sec)
|
|
108
|
+ local timeStruct = {}
|
|
109
|
+ timeStruct.sec = tonumber(sec) or 0
|
|
110
|
+ timeStruct.min = tonumber(min) or 0
|
|
111
|
+ timeStruct.hour = tonumber(hour) or 0
|
|
112
|
+ timeStruct.day = tonumber(day) or 0
|
|
113
|
+ timeStruct.month = tonumber(month) or 0
|
|
114
|
+ timeStruct.year = tonumber(year) or 0
|
|
115
|
+
|
|
116
|
+ return root.toInt(timeStruct)
|
|
117
|
+end
|
|
118
|
+
|
|
119
|
+-- 能否日刷新
|
|
120
|
+function root.dailyRefresh(atime, btime, hour, min, sec)
|
|
121
|
+ local atime = tonumber(atime) or 0
|
|
122
|
+ local btime = tonumber(btime) or root.currentTime()
|
|
123
|
+ local hour, min, sec = tonumber(hour) or 0, tonumber(min) or 0, tonumber(sec) or 0
|
|
124
|
+
|
|
125
|
+ local aTimeTab, bTimeTab = root.toTab(atime), root.toTab(btime)
|
|
126
|
+ bTimeTab.hour, bTimeTab.min, bTimeTab.sec = hour, min, sec
|
|
127
|
+ aTimeTab.hour, aTimeTab.min, aTimeTab.sec = hour, min, sec
|
|
128
|
+ -- 超过1天
|
|
129
|
+ if btime - atime >= 24 * 60 * 60 then
|
|
130
|
+ return true
|
|
131
|
+ end
|
|
132
|
+ -- 1天之内
|
|
133
|
+ if btime >= root.toInt(aTimeTab) and root.toInt(aTimeTab) >= atime then
|
|
134
|
+ return true
|
|
135
|
+ end
|
|
136
|
+ if btime >= root.toInt(bTimeTab) and root.toInt(bTimeTab) >= atime then
|
|
137
|
+ return true
|
|
138
|
+ end
|
|
139
|
+
|
|
140
|
+ return false
|
|
141
|
+end
|
|
142
|
+
|
|
143
|
+-- 能否周刷新 [wday=2 是周一]
|
|
144
|
+function root.WeekRefresh(atime, btime, wday, hour, min, sec)
|
|
145
|
+ atime = tonumber(atime) or 0
|
|
146
|
+ btime = tonumber(btime) or root.currentTime()
|
|
147
|
+ wday, hour, min, sec = tonumber(wday) or 2, tonumber(hour) or 0, tonumber(min) or 0, tonumber(sec) or 0
|
|
148
|
+
|
|
149
|
+ local aTimeTab, bTimeTab = root.toTab(atime), root.toTab(btime)
|
|
150
|
+ bTimeTab.day = bTimeTab.day + (wday - bTimeTab.wday)
|
|
151
|
+ aTimeTab.day = aTimeTab.day + (wday - aTimeTab.wday)
|
|
152
|
+ bTimeTab.hour, bTimeTab.min, bTimeTab.sec = hour, min, sec
|
|
153
|
+ aTimeTab.hour, aTimeTab.min, aTimeTab.sec = hour, min, sec
|
|
154
|
+ -- 超过七天
|
|
155
|
+ if btime - atime >= 7 * 24 * 60 * 60 then
|
|
156
|
+ return true
|
|
157
|
+ end
|
|
158
|
+ -- 七天之内
|
|
159
|
+ if btime >= root.toInt(aTimeTab) and root.toInt(aTimeTab) >= atime then
|
|
160
|
+ return true
|
|
161
|
+ end
|
|
162
|
+ if btime >= root.toInt(bTimeTab) and root.toInt(bTimeTab) >= atime then
|
|
163
|
+ return true
|
|
164
|
+ end
|
|
165
|
+
|
|
166
|
+ return false
|
|
167
|
+end
|
|
168
|
+
|
|
169
|
+-- 能否月刷新
|
|
170
|
+function root.can_month_refresh(atime, btime, in_day, hour, min, sec)
|
|
171
|
+ local atime = tonumber(atime) or 0
|
|
172
|
+ local btime = tonumber(btime) or root.currentTime()
|
|
173
|
+ local bTimeTab, aTimeTab = root.toTab(btime), root.toTab(atime)
|
|
174
|
+ local day, hour, min, sec = tonumber(in_day) or 1, tonumber(hour) or 0, tonumber(min) or 0, tonumber(sec) or 0
|
|
175
|
+ aTimeTab.day, aTimeTab.hour, aTimeTab.min, aTimeTab.sec = day, hour, min, sec
|
|
176
|
+ bTimeTab.day, bTimeTab.hour, bTimeTab.min, bTimeTab.sec = day, hour, min, sec
|
|
177
|
+ -- 超过一月
|
|
178
|
+ local month = (bTimeTab.year - aTimeTab.year) * 12
|
|
179
|
+ if bTimeTab.month + month > aTimeTab.month + 1 then
|
|
180
|
+ return true
|
|
181
|
+ end
|
|
182
|
+ -- 一月之内
|
|
183
|
+ if btime >= root.toInt(aTimeTab) and root.toInt(aTimeTab) >= atime then
|
|
184
|
+ return true
|
|
185
|
+ end
|
|
186
|
+ if btime >= root.toInt(bTimeTab) and root.toInt(bTimeTab) >= atime then
|
|
187
|
+ return true
|
|
188
|
+ end
|
|
189
|
+
|
|
190
|
+ return false
|
|
191
|
+end
|
|
192
|
+
|
|
193
|
+-- 两个时间相距天数
|
|
194
|
+function root.getDisDays(t1, t2)
|
|
195
|
+ if t1 == nil or t2 == nil then
|
|
196
|
+ return 0
|
|
197
|
+ end
|
|
198
|
+
|
|
199
|
+ local d1 = root.getYday(t1)
|
|
200
|
+ local d2 = root.getYday(t2)
|
|
201
|
+ return math.abs(d1 - d2)
|
|
202
|
+end
|
|
203
|
+
|
|
204
|
+function root.isSameDay(t1, t2)
|
|
205
|
+ if t1 == nil or t2 == nil then
|
|
206
|
+ return false
|
|
207
|
+ end
|
|
208
|
+ local d1 = root.getYday(t1)
|
|
209
|
+ local d2 = root.getYday(t2)
|
|
210
|
+ if d1 == d2 then
|
|
211
|
+ return true
|
|
212
|
+ end
|
|
213
|
+ return false
|
|
214
|
+end
|
|
215
|
+-- 是否同一天(凌晨5点)
|
|
216
|
+function root.is_same_c5_day(t1, t2)
|
|
217
|
+ if t1 == nil or t2 == nil then
|
|
218
|
+ return false
|
|
219
|
+ end
|
|
220
|
+ local d1 = root.getYday(t1 - 5 * 3600)
|
|
221
|
+ local d2 = root.getYday(t2 - 5 * 3600)
|
|
222
|
+ if d1 == d2 then
|
|
223
|
+ return true
|
|
224
|
+ end
|
|
225
|
+ return false
|
|
226
|
+end
|
|
227
|
+
|
|
228
|
+-- 获取当前天数(自1970年)
|
|
229
|
+function root.getDaysOfTimestampExt(timestamp, diffTime)
|
|
230
|
+ timestamp = (timestamp or root.currentTime()) - (diffTime or 0)
|
|
231
|
+ return math.floor((timestamp + (8 * 3600)) / (3600 * 24))
|
|
232
|
+end
|
|
233
|
+
|
|
234
|
+-- 获取获取相差的天数
|
|
235
|
+function root.getDisDaysC5(t1, t2)
|
|
236
|
+ if t1 == nil or t2 == nil then
|
|
237
|
+ return 0
|
|
238
|
+ end
|
|
239
|
+
|
|
240
|
+ local d1 = root.getDaysOfTimestampExt(t1, 5 * 3600)
|
|
241
|
+ local d2 = root.getDaysOfTimestampExt(t2, 5 * 3600)
|
|
242
|
+ return math.abs(d1 - d2)
|
|
243
|
+end
|
|
244
|
+
|
|
245
|
+-- 获取获取相差的天数
|
|
246
|
+function root.getDisDaysExt(t1, t2)
|
|
247
|
+ if t1 == nil or t2 == nil then
|
|
248
|
+ return 0
|
|
249
|
+ end
|
|
250
|
+
|
|
251
|
+ local d1 = root.getDaysOfTimestampExt(t1)
|
|
252
|
+ local d2 = root.getDaysOfTimestampExt(t2)
|
|
253
|
+ return math.abs(d1 - d2)
|
|
254
|
+end
|
|
255
|
+
|
|
256
|
+-- 获取下一个凌晨5点时间戳
|
|
257
|
+function root.get_next_c5_time(currTime)
|
|
258
|
+ currTime = currTime or skynet_time()
|
|
259
|
+ local startTime = root.getDayStartTime(currTime) + 5 * 3600
|
|
260
|
+ if currTime >= startTime then
|
|
261
|
+ return startTime + 24 * 3600
|
|
262
|
+ end
|
|
263
|
+ return startTime
|
|
264
|
+end
|
|
265
|
+
|
|
266
|
+-- 获取下周一开始时间 5点
|
|
267
|
+function root.c5_get_next_week_start_time(currTime)
|
|
268
|
+ local date = os.date("*t", currTime)
|
|
269
|
+ -- log.info("获取下周一5点时间 date[%s]", tostring(date))
|
|
270
|
+ if date.wday == 1 and date.hour < 5 then
|
|
271
|
+ return root.getTime(date.year, date.month, date.day, 5, 0, 0)
|
|
272
|
+ end
|
|
273
|
+ local diffDays
|
|
274
|
+ local wday = date.wday - 1
|
|
275
|
+ if wday == 0 then
|
|
276
|
+ wday = 7
|
|
277
|
+ end
|
|
278
|
+ diffDays = 8 - wday
|
|
279
|
+ -- log.info("diffDays = %s", diffDays)
|
|
280
|
+ return root.getDayStartTime(currTime, diffDays) + 5 * 3600
|
|
281
|
+end
|
|
282
|
+
|
|
283
|
+-- 获取下个月1号开始时间 5点
|
|
284
|
+function root.c5_get_next_month_start_time(currTime)
|
|
285
|
+ local date = os.date("*t", currTime)
|
|
286
|
+ -- log.info("获取下周一5点时间 date[%s]", tostring(date))
|
|
287
|
+ if date.day == 1 and date.hour < 5 then
|
|
288
|
+ return root.getTime(date.year, date.month, date.day, 5, 0, 0)
|
|
289
|
+ end
|
|
290
|
+
|
|
291
|
+ date.month = date.month + 1
|
|
292
|
+ return root.getTime(date.year, date.month, date.day, 5, 0, 0)
|
|
293
|
+end
|
|
294
|
+
|
|
295
|
+-- 两个时间间隔(凌晨5点)
|
|
296
|
+function root.get_c5_dis_days(t1, t2)
|
|
297
|
+ if t1 == nil or t2 == nil then
|
|
298
|
+ return 0
|
|
299
|
+ end
|
|
300
|
+
|
|
301
|
+ local d1 = root.getYday(t1 - 5 * 3600)
|
|
302
|
+ local d2 = root.getYday(t2 - 5 * 3600)
|
|
303
|
+ return math.abs(d1 - d2)
|
|
304
|
+end
|
|
305
|
+
|
|
306
|
+function root.isSameWeek(t1, t2)
|
|
307
|
+ local dateA = os.date("*t", t1)
|
|
308
|
+ local dateB = os.date("*t", t2)
|
|
309
|
+ local diff = math.abs(dateA.yday - dateB.yday)
|
|
310
|
+ if diff == 0 then
|
|
311
|
+ return true
|
|
312
|
+ end
|
|
313
|
+
|
|
314
|
+ local beforeDt = 0
|
|
315
|
+ if dateA.yday < dateB.yday then
|
|
316
|
+ beforeDt = dateA
|
|
317
|
+ else
|
|
318
|
+ beforeDt = dateB
|
|
319
|
+ end
|
|
320
|
+ if diff > 7 then
|
|
321
|
+ return false
|
|
322
|
+ end
|
|
323
|
+
|
|
324
|
+ local wday = beforeDt.wday - 1
|
|
325
|
+ if wday == 0 then
|
|
326
|
+ wday = 7
|
|
327
|
+ end
|
|
328
|
+
|
|
329
|
+ if wday + diff > 7 then
|
|
330
|
+ return false
|
|
331
|
+ end
|
|
332
|
+
|
|
333
|
+ return true
|
|
334
|
+end
|
|
335
|
+
|
|
336
|
+function root.isSameMonth(t1, t2)
|
|
337
|
+ if t1 == nil or t2 == nil then
|
|
338
|
+ return false
|
|
339
|
+ end
|
|
340
|
+ local n1 = os.date("*t", t1)
|
|
341
|
+ local n2 = os.date("*t", t2)
|
|
342
|
+ if n1.year == n2.year and n1.month == n2.month then
|
|
343
|
+ return true
|
|
344
|
+ end
|
|
345
|
+ return false
|
|
346
|
+end
|
|
347
|
+
|
|
348
|
+-- 获取当天结束时间
|
|
349
|
+function root.getDayEndTime(currTime, days)
|
|
350
|
+ local daySec = 24 * 3600
|
|
351
|
+ local addDay = days or 1
|
|
352
|
+ local timeout = math.floor((currTime + 8 * 3600) / daySec) * daySec + daySec * addDay - 8 * 3600 - 1
|
|
353
|
+
|
|
354
|
+ return timeout
|
|
355
|
+end
|
|
356
|
+
|
|
357
|
+-- 获取当天开始时间
|
|
358
|
+function root.getDayStartTime(currTime, days)
|
|
359
|
+ local daySec = 24 * 3600
|
|
360
|
+ local addDay = days or 0
|
|
361
|
+ local timeout = math.floor((currTime + 8 * 3600) / daySec) * daySec + daySec * addDay - 8 * 3600
|
|
362
|
+
|
|
363
|
+ return timeout
|
|
364
|
+end
|
|
365
|
+
|
|
366
|
+-- 获取当前周开始时间[周日开始]
|
|
367
|
+function root.getWeekStartTime(currTime)
|
|
368
|
+ local t = root.toTab(currTime)
|
|
369
|
+ local startTime = root.getDayStartTime(currTime)
|
|
370
|
+ return startTime - (t.wday - 1) * root.SEC_PER_DAY
|
|
371
|
+end
|
|
372
|
+
|
|
373
|
+-- 获取当天周结束时间[周六结束]
|
|
374
|
+function root.getWeekEndTime(currTime)
|
|
375
|
+ local startTime = root.getWeekStartTime(currTime)
|
|
376
|
+ return startTime + root.SEC_PER_WEEK - 1
|
|
377
|
+end
|
|
378
|
+
|
|
379
|
+-- 获取当前周的指定时间的时间戳[从周日起]
|
|
380
|
+-- day周日为0,周六为6
|
|
381
|
+function root.getTimeByWeek(currTime, day, h, m, s)
|
|
382
|
+ day = day or 0
|
|
383
|
+ h = h or 0
|
|
384
|
+ m = m or 0
|
|
385
|
+ s = s or 0
|
|
386
|
+ local startTime = root.getWeekStartTime(currTime)
|
|
387
|
+ local addTime = day * root.SEC_PER_DAY + h * root.SEC_PER_HOUR + m * 60 + s
|
|
388
|
+ return startTime + addTime
|
|
389
|
+end
|
|
390
|
+
|
|
391
|
+-- 获取现在时间是几星期几.day周日为0,周六为6
|
|
392
|
+function root.getWeekDay(currTime)
|
|
393
|
+ local tab = os.date("*t", currTime or os.time())
|
|
394
|
+ return tab.wday - 1
|
|
395
|
+end
|
|
396
|
+
|
|
397
|
+-- 获取当天0点时间戳
|
|
398
|
+function root.getUnixtimeToday(t1)
|
|
399
|
+ local nt = os.date("*t", t1)
|
|
400
|
+ return os.time({year = nt.year, month = nt.month, day = nt.day, hour = 0, min = 0, sec = 0})
|
|
401
|
+end
|
|
402
|
+
|
|
403
|
+-- 获取明天0点时间戳
|
|
404
|
+function root.getUnixtimeTomorrow(t1)
|
|
405
|
+ return root.getUnixtimeToday(t1) + 86400
|
|
406
|
+end
|
|
407
|
+
|
|
408
|
+-- 明天零点倒计时
|
|
409
|
+function root.countdownToTomorrow(t1)
|
|
410
|
+ return root.getUnixtimeTomorrow(t1) - (t1 or os.time())
|
|
411
|
+end
|
|
412
|
+
|
|
413
|
+-- 跨分钟数
|
|
414
|
+function root.get_across_minutes(startTime, endTime)
|
|
415
|
+ if startTime == nil or endTime == nil then
|
|
416
|
+ return 0
|
|
417
|
+ end
|
|
418
|
+ local s = math.floor(startTime / 60)
|
|
419
|
+ local e = math.floor(endTime / 60)
|
|
420
|
+ if endTime > e * 60 then
|
|
421
|
+ e = e + 1
|
|
422
|
+ end
|
|
423
|
+ log.info(
|
|
424
|
+ "get_across_minutes startTime[%s] s[%s] endTime[%s] e[%s]",
|
|
425
|
+ tostring(startTime),
|
|
426
|
+ tostring(s),
|
|
427
|
+ tostring(endTime),
|
|
428
|
+ tostring(e)
|
|
429
|
+ )
|
|
430
|
+ return math.abs(e - s)
|
|
431
|
+end
|
|
432
|
+-- 跨小时数(rate每多少整小时,可以是每整1小时,也可以是每整2小时)
|
|
433
|
+function root.get_across_hours(startTime, endTime, rate)
|
|
434
|
+ if startTime == nil or endTime == nil then
|
|
435
|
+ return 0
|
|
436
|
+ end
|
|
437
|
+
|
|
438
|
+ if not rate then
|
|
439
|
+ rate = 3600
|
|
440
|
+ end
|
|
441
|
+
|
|
442
|
+ local s = math.floor(startTime / rate)
|
|
443
|
+ local e = math.floor(endTime / rate)
|
|
444
|
+ log.info(
|
|
445
|
+ "get_across_hours startTime[%s] s[%s] endTime[%s] e[%s]",
|
|
446
|
+ tostring(startTime),
|
|
447
|
+ tostring(s),
|
|
448
|
+ tostring(endTime),
|
|
449
|
+ tostring(e)
|
|
450
|
+ )
|
|
451
|
+ return math.abs(e - s)
|
|
452
|
+end
|
|
453
|
+-- 跨天数
|
|
454
|
+function root.c5_get_cross_days(startTime, endTime)
|
|
455
|
+ if startTime == nil or endTime == nil then
|
|
456
|
+ return 0
|
|
457
|
+ end
|
|
458
|
+ local days = 0
|
|
459
|
+ local nextTime = root.get_next_c5_time(startTime)
|
|
460
|
+ while nextTime < endTime do
|
|
461
|
+ days = days + 1
|
|
462
|
+ nextTime = nextTime + 24 * 3600
|
|
463
|
+ end
|
|
464
|
+ return days
|
|
465
|
+end
|
|
466
|
+
|
|
467
|
+--#region ----------------------------------------- 时间的扩展:功能代码块
|
|
468
|
+-- 为什么重新实现?
|
|
469
|
+-- 部分功能实现得过于复杂,没必要过于遇合,需要考虑到lua的性能消耗.
|
|
470
|
+
|
|
471
|
+-- 获取当天0点时间戳
|
|
472
|
+function root.getTodayHourTimestamp(hour)
|
|
473
|
+ local t_date = os.date("*t")
|
|
474
|
+ return os.time(
|
|
475
|
+ {
|
|
476
|
+ year = t_date.year,
|
|
477
|
+ month = t_date.month,
|
|
478
|
+ day = t_date.day,
|
|
479
|
+ hour = hour or root.REFRESH_HOUR,
|
|
480
|
+ min = 0,
|
|
481
|
+ sec = 0
|
|
482
|
+ }
|
|
483
|
+ )
|
|
484
|
+end
|
|
485
|
+
|
|
486
|
+-- 跨天数
|
|
487
|
+-- 获取某个时间戳跨越了多少天(5点为分界线)
|
|
488
|
+function root.getDaysOfTimestamp(timestamp)
|
|
489
|
+ -- 错误的时间参数返回1天
|
|
490
|
+ if not timestamp or timestamp == 0 then
|
|
491
|
+ return 1
|
|
492
|
+ end
|
|
493
|
+
|
|
494
|
+ local dt = root.getTodayHourTimestamp()
|
|
495
|
+ if timestamp > dt then
|
|
496
|
+ -- 以一天来计算,可能
|
|
497
|
+ -- return 888
|
|
498
|
+ return math.ceil((timestamp - dt) / root.SEC_PER_DAY)
|
|
499
|
+ else
|
|
500
|
+ -- 逻辑刷新前面要加1.
|
|
501
|
+ return math.ceil((dt - timestamp) / root.SEC_PER_DAY) + 1
|
|
502
|
+ end
|
|
503
|
+end
|
|
504
|
+
|
|
505
|
+-- 是否已经跨天了
|
|
506
|
+function root.isOtherDay(uid, actData)
|
|
507
|
+ -- 刷新时间
|
|
508
|
+ local currTime = root.now(uid or 0)
|
|
509
|
+ if actData.nextUT == nil or currTime >= actData.nextUT then
|
|
510
|
+ actData.nextUT = root.get_next_c5_time(currTime)
|
|
511
|
+ return true
|
|
512
|
+ end
|
|
513
|
+ return false
|
|
514
|
+end
|
|
515
|
+
|
|
516
|
+--#endregion
|
|
517
|
+
|
|
518
|
+return root
|