The Battle for Wesnoth  1.19.5+dev
irdya_datetime.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2017 - 2024
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #pragma once
16 
17 #include "utils/wesnoth_epoch.hpp"
18 
19 #include <ostream>
20 #include <string>
21 
22 namespace utils
23 {
24 
25 /**
26  * Calendar for handling and comparing dates using the common epoches of the storyline.
27  */
29 {
30 public:
31  irdya_date() = default;
32 
34  : epoch(epoch)
35  , year(year)
36  {
37  }
38 
39  static irdya_date read_date(const std::string& date);
40 
42  {
43  return epoch;
44  }
45 
46  unsigned int get_year() const
47  {
48  return year;
49  }
50 
51  /* There is no year 0, so use that to represent an "invalid" date. */
52  bool is_valid() const
53  {
54  return year != 0;
55  }
56 
57  /* Outputs a locale-dependent string describing the year. */
58  std::string to_string() const;
59 
60 private:
62 
63  unsigned int year = 0;
64 
65  // TODO: Decide how many months and days there are!
66  //unsigned int month = 0;
67  //unsigned int day = 0;
68 };
69 
70 bool operator<(const irdya_date& a, const irdya_date& b);
71 bool operator<=(const irdya_date& a, const irdya_date& b);
72 bool operator>(const irdya_date& a, const irdya_date& b);
73 bool operator>=(const irdya_date& a, const irdya_date& b);
74 bool operator==(const irdya_date& a, const irdya_date& b);
75 bool operator!=(const irdya_date& a, const irdya_date& b);
76 
77 std::ostream& operator<<(std::ostream& s, const irdya_date& d);
78 
79 }
Calendar for handling and comparing dates using the common epoches of the storyline.
unsigned int get_year() const
static irdya_date read_date(const std::string &date)
wesnoth_epoch::type epoch
bool is_valid() const
std::string to_string() const
irdya_date(wesnoth_epoch::type epoch, unsigned year)
wesnoth_epoch::type get_epoch() const
irdya_date()=default
bool operator!=(const irdya_date &a, const irdya_date &b)
bool operator<=(const irdya_date &a, const irdya_date &b)
bool operator>(const irdya_date &a, const irdya_date &b)
bool operator==(const irdya_date &a, const irdya_date &b)
bool operator>=(const irdya_date &a, const irdya_date &b)
std::ostream & operator<<(std::ostream &s, const irdya_date &d)
bool operator<(const irdya_date &a, const irdya_date &b)
static map_location::direction s
#define d
#define b