Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
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  //------------------------------------------------------------------------------------------------
32  static string GetDateString(int day, int month, int year, bool verbose = true)
33  {
34  string date;
35 
36  if (verbose)
37  date = WidgetManager.Translate("#AR-Date_Format_MonthFull", day, SCR_DateTimeHelper.GetMonthString(month), year);
38  else
39  date = WidgetManager.Translate("#AR-Date_Format", day, month, year);
40 
41  return date;
42  }
43 
44 
45  //------------------------------------------------------------------------------------------------
52  static string GetMonthString(int month, bool standalone = false)
53  {
54  if (month < 1 || month > 12)
55  return string.Empty;
56 
57  string months[12];
58 
59  if (standalone)
60  {
61  months = {
62  "#AR-Date_January_Standalone",
63  "#AR-Date_February_Standalone",
64  "#AR-Date_March_Standalone",
65  "#AR-Date_April_Standalone",
66  "#AR-Date_May_Standalone",
67  "#AR-Date_June_Standalone",
68  "#AR-Date_July_Standalone",
69  "#AR-Date_August_Standalone",
70  "#AR-Date_September_Standalone",
71  "#AR-Date_October_Standalone",
72  "#AR-Date_November_Standalone",
73  "#AR-Date_December_Standalone",
74  };
75  }
76  else
77  {
78  months = {
79  "#AR-Date_January",
80  "#AR-Date_February",
81  "#AR-Date_March",
82  "#AR-Date_April",
83  "#AR-Date_May",
84  "#AR-Date_June",
85  "#AR-Date_July",
86  "#AR-Date_August",
87  "#AR-Date_September",
88  "#AR-Date_October",
89  "#AR-Date_November",
90  "#AR-Date_December",
91  };
92  }
93 
94  return months[month -1];
95  }
96 
97  //------------------------------------------------------------------------------------------------
103  static string GetAbbreviatedMonthString(int month)
104  {
105  if (month < 1 || month > 12)
106  return string.Empty;
107 
108  // if it gets called often, cache it as a static array
109  array<string> months = {
110  "#AR-Date_January_StandaloneShort",
111  "#AR-Date_February_StandaloneShort",
112  "#AR-Date_March_StandaloneShort",
113  "#AR-Date_April_StandaloneShort",
114  "#AR-Date_May_StandaloneShort",
115  "#AR-Date_June_StandaloneShort",
116  "#AR-Date_July_StandaloneShort",
117  "#AR-Date_August_StandaloneShort",
118  "#AR-Date_September_StandaloneShort",
119  "#AR-Date_October_StandaloneShort",
120  "#AR-Date_November_StandaloneShort",
121  "#AR-Date_December_StandaloneShort",
122  };
123 
124  return months[month -1];
125  }
126 
127  //------------------------------------------------------------------------------------------------
129  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)
130  {
131  int time0 = GetSecondsFromHourMinuteSecond(hour0, minute0, second0);
132  int time1 = GetSecondsFromHourMinuteSecond(hour1, minute1, second1);
133 
134  int result = time0 - time1;
135  if (result < 0)
136  result *= -1;
137 
138  GetHourMinuteSecondFromSeconds(result, hour, minute, second);
139 
140  return result;
141  }
142 
143  //------------------------------------------------------------------------------------------------
145  static string GetTimeDifferenceFormatted(int hour0, int minute0, int second0, int hour1, int minute1, int second1)
146  {
147  int hour, minute, second;
148  GetTimeDifference(hour0, minute0, second0, hour1, minute1, second1, hour, minute, second);
149  return SCR_FormatHelper.FormatTime(hour, minute, second);
150  }
151 
152  //------------------------------------------------------------------------------------------------
154  static string GetTimeLocal()
155  {
156  int hour, minute, second;
157  System.GetHourMinuteSecond(hour, minute, second);
158  return SCR_FormatHelper.FormatTime(hour, minute, second);
159  }
160 
161  //------------------------------------------------------------------------------------------------
163  static string GetTimeUTC()
164  {
165  int hour, minute, second;
166  System.GetHourMinuteSecondUTC(hour, minute, second);
167  return SCR_FormatHelper.FormatTime(hour, minute, second);
168  }
169 
170  //------------------------------------------------------------------------------------------------
179  static void GetDayHourMinuteSecondFromSeconds(int totalSeconds, out int outDays, out int outHours, out int outMinutes, out int outSeconds)
180  {
181  if (totalSeconds < 0)
182  totalSeconds *= -1;
183 
184  outDays = totalSeconds / 86400;
185  outHours = (totalSeconds % 86400) / 3600;
186  outMinutes = (totalSeconds % 3600) / 60;
187  outSeconds = totalSeconds % 60;
188  }
189 
190  //------------------------------------------------------------------------------------------------
198  static void GetHourMinuteSecondFromSeconds(int totalSeconds, out int outHours, out int outMinutes, out int outSeconds)
199  {
200  if (totalSeconds < 0)
201  totalSeconds *= -1;
202 
203  outHours = totalSeconds / 3600;
204  outMinutes = (totalSeconds % 3600) / 60;
205  outSeconds = totalSeconds % 60;
206  }
207 
208  //------------------------------------------------------------------------------------------------
213  static int GetSecondsFromHourMinuteSecond(int hour = 0, int minute = 0, int second = 0)
214  {
215  return hour * 3600 + minute * 60 + second;
216  }
217 
218  //------------------------------------------------------------------------------------------------
227  static int ConvertDateIntoMinutes(int year = 0, int month = 0, int day = 0, int hour = 0, int minutes = 0)
228  {
229  return (year * 525600) + (month * 43800) + (day * 1440) + (hour * 60) + minutes;
230  }
231 
232  //------------------------------------------------------------------------------------------------
242  static void ConvertMinutesIntoDate(int totalDateMinutes, out int year, out int month, out int day, out int hour, out int minutes)
243  {
244  year = totalDateMinutes / 525600;
245  totalDateMinutes -= year * 525600;
246 
247  month = totalDateMinutes / 43800;
248  totalDateMinutes -= month * 43800;
249 
250  day = totalDateMinutes / 1440;
251  totalDateMinutes -= day * 1440;
252 
253  hour = totalDateMinutes / 60;
254  totalDateMinutes -= hour * 60;
255 
256  minutes = totalDateMinutes;
257  }
258 };
SCR_FormatHelper
Definition: SCR_FormatHelper.c:1
SCR_DateTimeHelper
Definition: SCR_DateTimeHelper.c:1