Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_DateTimeHelper.c
Go to the documentation of this file.
2{
3 //------------------------------------------------------------------------------------------------
5 static string GetDateTimeLocal()
6 {
7 int year, month, day, hour, minute, second;
8 System.GetYearMonthDay(year, month, day);
9 System.GetHourMinuteSecond(hour, minute, second);
10 return SCR_FormatHelper.FormatDateTime(year, month, day, hour, minute, second);
11 }
12
13 //------------------------------------------------------------------------------------------------
15 static string GetDateTimeUTC()
16 {
17 int year, month, day, hour, minute, second;
18 System.GetYearMonthDayUTC(year, month, day);
19 System.GetHourMinuteSecondUTC(hour, minute, second);
20 return SCR_FormatHelper.FormatDateTime(year, month, day, hour, minute, second);
21 }
22
23 //------------------------------------------------------------------------------------------------
30 static int GetDayNumber(int year, int month, int day)
31 {
32 if (month < 1 || month > 12 || day < 1 || day > 31)
33 return -1;
34
35 int monthDays[12] = {
36 31, 28, 31, 30, 31, 30,
37 31, 31, 30, 31, 30, 31,
38 };
39
40 if (month > 2 && IsLeapYear(year))
41 monthDays[1] = 29;
42
43 if (day > monthDays[month - 1])
44 return -1;
45
46 int result;
47 for (int i; i < month - 1; ++i)
48 {
49 result += monthDays[i];
50 }
51
52 result += day;
53
54 return result;
55 }
56
57 //------------------------------------------------------------------------------------------------
60 static bool IsLeapYear(int year)
61 {
62 return year % 400 == 0 || (year % 100 != 0 && year % 4 == 0);
63 }
64
65 //------------------------------------------------------------------------------------------------
72 static string GetDateString(int day, int month, int year, bool verbose = true)
73 {
74 if (verbose)
75 return WidgetManager.Translate("#AR-Date_Format_MonthFull", day, SCR_DateTimeHelper.GetMonthString(month), year);
76 else
77 return WidgetManager.Translate("#AR-Date_Format", day, month, year);
78 }
79
80 //------------------------------------------------------------------------------------------------
85 static string GetMonthString(int month, bool standalone = false)
86 {
87 if (standalone)
88 {
89 switch (month)
90 {
91 case 1: return "#AR-Date_January_Standalone";
92 case 2: return "#AR-Date_February_Standalone";
93 case 3: return "#AR-Date_March_Standalone";
94 case 4: return "#AR-Date_April_Standalone";
95 case 5: return "#AR-Date_May_Standalone";
96 case 6: return "#AR-Date_June_Standalone";
97 case 7: return "#AR-Date_July_Standalone";
98 case 8: return "#AR-Date_August_Standalone";
99 case 9: return "#AR-Date_September_Standalone";
100 case 10: return "#AR-Date_October_Standalone";
101 case 11: return "#AR-Date_November_Standalone";
102 case 12: return "#AR-Date_December_Standalone";
103 }
104 }
105 else
106 {
107 switch (month)
108 {
109 case 1: return "#AR-Date_January";
110 case 2: return "#AR-Date_February";
111 case 3: return "#AR-Date_March";
112 case 4: return "#AR-Date_April";
113 case 5: return "#AR-Date_May";
114 case 6: return "#AR-Date_June";
115 case 7: return "#AR-Date_July";
116 case 8: return "#AR-Date_August";
117 case 9: return "#AR-Date_September";
118 case 10: return "#AR-Date_October";
119 case 11: return "#AR-Date_November";
120 case 12: return "#AR-Date_December";
121 }
122 }
123
124 return string.Empty;
125 }
126
127 //------------------------------------------------------------------------------------------------
131 static string GetAbbreviatedMonthString(int month)
132 {
133 switch (month)
134 {
135 case 1: return "#AR-Date_January_StandaloneShort";
136 case 2: return "#AR-Date_February_StandaloneShort";
137 case 3: return "#AR-Date_March_StandaloneShort";
138 case 4: return "#AR-Date_April_StandaloneShort";
139 case 5: return "#AR-Date_May_StandaloneShort";
140 case 6: return "#AR-Date_June_StandaloneShort";
141 case 7: return "#AR-Date_July_StandaloneShort";
142 case 8: return "#AR-Date_August_StandaloneShort";
143 case 9: return "#AR-Date_September_StandaloneShort";
144 case 10: return "#AR-Date_October_StandaloneShort";
145 case 11: return "#AR-Date_November_StandaloneShort";
146 case 12: return "#AR-Date_December_StandaloneShort";
147 }
148
149 return string.Empty;
150 }
151
152 //------------------------------------------------------------------------------------------------
157 static int GetMaxDayFromMonth(int month, int year = -1)
158 {
159 if (month < 1 || month > 12)
160 return -1;
161
162 // February specific
163 if (year > 0 && month == 2)
164 {
165 if (IsLeapYear(year))
166 return 29;
167 else
168 return 28;
169 }
170
171 if (month == 2)
172 return 28;
173 else if (month == 4 || month == 6 || month == 9 || month == 11)
174 return 30;
175 else
176 return 31;
177 }
178
179 //------------------------------------------------------------------------------------------------
190 static int GetTimeDifference(int hour0, int minute0, int second0, int hour1, int minute1, int second1, out int hour = 0, out int minute = 0, out int second = 0)
191 {
192 int time0 = GetSecondsFromHourMinuteSecond(hour0, minute0, second0);
193 int time1 = GetSecondsFromHourMinuteSecond(hour1, minute1, second1);
194
195 int result = time0 - time1;
196 if (result < 0)
197 result = -result;
198
199 GetHourMinuteSecondFromSeconds(result, hour, minute, second);
200
201 return result;
202 }
203
204 //------------------------------------------------------------------------------------------------
212 static string GetTimeDifferenceFormatted(int hour0, int minute0, int second0, int hour1, int minute1, int second1)
213 {
214 int hour, minute, second;
215 GetTimeDifference(hour0, minute0, second0, hour1, minute1, second1, hour, minute, second);
216 return SCR_FormatHelper.FormatTime(hour, minute, second);
217 }
218
219 //------------------------------------------------------------------------------------------------
221 static string GetTimeLocal()
222 {
223 int hour, minute, second;
224 System.GetHourMinuteSecond(hour, minute, second);
225 return SCR_FormatHelper.FormatTime(hour, minute, second);
226 }
227
228 //------------------------------------------------------------------------------------------------
230 static string GetTimeUTC()
231 {
232 int hour, minute, second;
233 System.GetHourMinuteSecondUTC(hour, minute, second);
234 return SCR_FormatHelper.FormatTime(hour, minute, second);
235 }
236
237 //------------------------------------------------------------------------------------------------
244 static void GetDayHourMinuteSecondFromSeconds(int totalSeconds, out int outDays, out int outHours, out int outMinutes, out int outSeconds)
245 {
246 if (totalSeconds < 0)
247 totalSeconds = -totalSeconds;
248
249 outDays = totalSeconds / 86400;
250 outHours = (totalSeconds % 86400) / 3600;
251 outMinutes = (totalSeconds % 3600) / 60;
252 outSeconds = totalSeconds % 60;
253 }
254
255 //------------------------------------------------------------------------------------------------
261 static void GetHourMinuteSecondFromSeconds(int totalSeconds, out int outHours, out int outMinutes, out int outSeconds)
262 {
263 if (totalSeconds < 0)
264 totalSeconds = -totalSeconds;
265
266 outHours = totalSeconds / 3600;
267 outMinutes = (totalSeconds % 3600) / 60;
268 outSeconds = totalSeconds % 60;
269 }
270
271 //------------------------------------------------------------------------------------------------
276 static int GetSecondsFromHourMinuteSecond(int hour = 0, int minute = 0, int second = 0)
277 {
278 return hour * 3600 + minute * 60 + second;
279 }
280
281 //------------------------------------------------------------------------------------------------
288 static int ConvertDateIntoMinutes(int year = 0, int month = 0, int day = 0, int hour = 0, int minutes = 0)
289 {
290 return (year * 525600) + (month * 43800) + (day * 1440) + (hour * 60) + minutes;
291 }
292
293 //------------------------------------------------------------------------------------------------
301 static void ConvertMinutesIntoDate(int totalDateMinutes, out int year, out int month, out int day, out int hour, out int minutes)
302 {
303 if (totalDateMinutes < 0)
304 totalDateMinutes = -totalDateMinutes;
305
306 year = totalDateMinutes / 525600;
307 totalDateMinutes -= year * 525600;
308
309 month = totalDateMinutes / 43800;
310 totalDateMinutes -= month * 43800;
311
312 day = totalDateMinutes / 1440;
313 totalDateMinutes -= day * 1440;
314
315 hour = totalDateMinutes / 60;
316 totalDateMinutes -= hour * 60;
317
318 minutes = totalDateMinutes;
319 }
320}