The Battle for Wesnoth  1.17.17+dev
irdya_datetime.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2017 - 2023
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 #include <vector>
22 
23 namespace utils
24 {
25 
26 /**
27  * Calendar for handling and comparing dates using the common epoches of the storyline.
28  */
30 {
31 public:
32  irdya_date() = default;
33 
35  : epoch(epoch)
36  , year(year)
37  {
38  }
39 
40  static irdya_date read_date(const std::string& date);
41 
43  {
44  return epoch;
45  }
46 
47  unsigned int get_year() const
48  {
49  return year;
50  }
51 
52  /* There is no year 0, so use that to represent an "invalid" date. */
53  bool is_valid() const
54  {
55  return year != 0;
56  }
57 
58  /* Outputs a locale-dependent string describing the year. */
59  std::string to_string() const;
60 
61 private:
63 
64  unsigned int year = 0;
65 
66  // TODO: Decide how many months and days there are!
67  //unsigned int month = 0;
68  //unsigned int day = 0;
69 };
70 
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 bool operator!=(const irdya_date& a, const irdya_date& b);
77 
78 std::ostream& operator<<(std::ostream& s, const irdya_date& d);
79 
80 }
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 a
#define b