Antares Simulator
Power System Simulator
date.h
1 /*
2 ** Copyright 2007-2025, RTE (https://www.rte-france.com)
3 ** See AUTHORS.txt
4 ** SPDX-License-Identifier: MPL-2.0
5 ** This file is part of Antares-Simulator,
6 ** Adequacy and Performance assessment for interconnected energy networks.
7 **
8 ** Antares_Simulator is free software: you can redistribute it and/or modify
9 ** it under the terms of the Mozilla Public Licence 2.0 as published by
10 ** the Mozilla Foundation, either version 2 of the License, or
11 ** (at your option) any later version.
12 **
13 ** Antares_Simulator is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ** Mozilla Public Licence 2.0 for more details.
17 **
18 ** You should have received a copy of the Mozilla Public Licence 2.0
19 ** along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
20 */
21 #ifndef __ANTARES_LIBS_DATE_DATE_H__
22 #define __ANTARES_LIBS_DATE_DATE_H__
23 
24 #include <vector>
25 
26 #include <yuni/yuni.h>
27 #include <yuni/core/string.h>
28 
29 #include "antares/study/fwd.h"
30 
31 namespace Antares
32 {
34 enum DayOfTheWeek
35 {
36  monday = 0,
37  tuesday,
38  wednesday,
39  thursday,
40  friday,
41  saturday,
42  sunday
43 };
44 
46 enum MonthName
47 {
48  january = 0,
49  february,
50  march,
51  april,
52  may,
53  june,
54  july,
55  august,
56  september,
57  october,
58  november,
59  december
60 };
61 
62 } // namespace Antares
63 
64 namespace Antares::Date
65 {
69 const char* MonthToString(int m, int offset = 0);
70 
75 const char* MonthToLowerString(int m, int offset = 0);
76 
80 const char* MonthToShortString(int m, int offset = 0);
81 
85 const char* MonthToUpperShortString(int m, int offset = 0);
86 
90 bool StringToMonth(MonthName& out, AnyString text);
91 
95 const char* WeekdayToString(int m);
96 
100 const char* WeekdayToShortString(int m);
101 
105 const char* WeekdayToShortUpperString(int m);
106 
110 const char* WeekdayToShortLowerString(int m);
111 
115 const wchar_t* WeekdayToLShortString(int m);
116 
124 bool StringToDayOfTheWeek(DayOfTheWeek& v, const AnyString& text);
125 
132 const char* DayOfTheWeekToString(DayOfTheWeek d);
133 
134 enum Precision
135 {
137  stepNone = 0,
138  // stepSecond,
139  // stepMinute,
140  hourly,
141  daily,
142  weekly,
143  monthly,
144  annual,
146  stepAny,
147 };
148 
150 {
152  uint first;
154  uint end;
155 
156  void reset()
157  {
158  first = 0;
159  end = 0;
160  }
161 }; // class HourInterval
162 
164 {
166  uint first;
168  uint end;
169 
170  uint numberOfWeeks() const;
171 
172  void reset()
173  {
174  first = 0;
175  end = 0;
176  }
177 }; // class DayInterval
178 
179 class Calendar final
180 {
181 public:
183  using ShortString42 = Yuni::CString<41, false>;
185  using ShortString12 = Yuni::CString<11, false>;
187  using ShortString8 = Yuni::CString<7, false>;
188 
189  enum
190  {
192  maxHoursInYear = 24 * 366,
197  };
198 
200  // calendar settings
201  struct
202  {
204  DayOfTheWeek weekday;
206  uint dayYear;
208  uint dayMonth;
210  uint dayHour;
212  uint month;
214  uint week;
220 
222  // calendar settings
223  struct
224  {
226  DayOfTheWeek weekday;
230  uint month;
232  uint dayMonth;
234  uint week;
236 
242  struct
243  {
249  uint days;
251  // Final users prefer that weeks numbers are stable whatever the first month
252  // of simulation is. If the 1st january is the same than the first weekday,
253  // the week number for this day will be 1, 53 otherwise.
254  uint userweek;
256 
265  struct
266  {
270  uint days;
274  DayOfTheWeek firstWeekday;
276  MonthName realmonth;
277  } months[12 + 1]; // september..august for example
278 
282  struct
283  {
285  uint months[12 /*january..december*/];
287 
289  struct Settings
290  {
292  DayOfTheWeek weekday1rstJanuary;
294  DayOfTheWeek weekFirstDay;
296  MonthName firstMonth;
298  bool leapYear;
299  };
300 
302  struct
303  {
305  struct
306  {
313  } months[12];
314 
321  } text;
322 
323  struct
324  {
325  std::wstring hours[maxHoursInYear];
326  } wtext;
327 
328 public:
330 
331 
334  Calendar();
335 
338  {
339  }
340 
342 
346  void reset();
347 
354  void reset(Settings settings);
355 
361  bool saveToCSVFile(const AnyString& filename) const;
362 
363 private:
364  Settings settings_;
365 
366 }; // class Calendar
367 } // namespace Antares::Date
368 
369 #endif // __ANTARES_TOOLBOX_DATE_H__
Definition: date.h:180
bool firstHourInMonth
First hour in the current month.
Definition: date.h:218
struct Antares::Date::Calendar::@17 text
Human string representations for any time interval of our calendar.
ShortString12 weekdays[7]
Weekdays.
Definition: date.h:320
uint dayYear
The day year for a single hour in the year.
Definition: date.h:206
struct Antares::Date::Calendar::@14 weeks[maxWeeksInYear]
Informations about weeks according the current calendar settings.
uint userweek
User week number.
Definition: date.h:254
@ maxDaysInYear
The maximum number of days in a year.
Definition: date.h:194
@ maxHoursInYear
The maximum number of hours in a year.
Definition: date.h:192
@ maxWeeksInYear
The maximum number of weeks in a year.
Definition: date.h:196
~Calendar()
Destructor.
Definition: date.h:337
uint month
Month.
Definition: date.h:212
DayInterval daysYear
Days in the year.
Definition: date.h:247
uint dayHour
Hour in the day.
Definition: date.h:210
uint days
Total number of days of simulation for this week.
Definition: date.h:249
struct Antares::Date::Calendar::@16 mapping
Mappings between any expected calendar and our own calendar.
struct Antares::Date::Calendar::@12 hours[maxHoursInYear]
informations about hours in the year according the current
struct Antares::Date::Calendar::@13 days[maxDaysInYear]
Informations about days in the year according the current.
bool firstHourInDay
First hour in the current day.
Definition: date.h:216
ShortString8 shortUpperName
Short name (3 letters) and uppercase (JAN..DEC)
Definition: date.h:312
ShortString8 shortName
Short name (3 letters) and uppercase (Jan..Dec)
Definition: date.h:310
HourInterval hours
Hour interval.
Definition: date.h:228
uint dayMonth
The day in the month.
Definition: date.h:208
struct Antares::Date::Calendar::@15 months[12+1]
Informations about months according the current calendar settings.
uint week
Week.
Definition: date.h:214
MonthName realmonth
Real month index.
Definition: date.h:276
bool saveToCSVFile(const AnyString &filename) const
Export the whole calendar into a CSV file.
Yuni::CString< 7, false > ShortString8
Short string representation with maximum 8 characters.
Definition: date.h:187
void reset()
Reset the calendar from the given settings.
Definition: date.cpp:383
ShortString12 name
Month name (January..December)
Definition: date.h:308
Calendar()
Default constructor.
Definition: date.cpp:363
Yuni::CString< 11, false > ShortString12
Short string representation with maximum 12 characters.
Definition: date.h:185
DayOfTheWeek firstWeekday
Very First weekday of the month.
Definition: date.h:274
DayOfTheWeek weekday
Weekday.
Definition: date.h:204
Yuni::CString< 41, false > ShortString42
Short string representation with maximum 42 characters.
Definition: date.h:183
Command line settings for launching the simulation.
Definition: options.h:36
The calendar settings.
Definition: date.h:290
DayOfTheWeek weekday1rstJanuary
Day of the week for the 1rst January.
Definition: date.h:292
bool leapYear
Leap year ?
Definition: date.h:298
DayOfTheWeek weekFirstDay
First day of weeks (for Antares simulations)
Definition: date.h:294
MonthName firstMonth
Index (0..11) of the first month of the year.
Definition: date.h:296
Definition: date.h:164
uint first
The very first day.
Definition: date.h:166
uint end
The last day (not included)
Definition: date.h:168
Definition: date.h:150
uint first
The very first hour.
Definition: date.h:152
uint end
The last hour (not included)
Definition: date.h:154