The Battle for Wesnoth  1.17.0-dev
irdya_datetime.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2017 - 2021
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/make_enum.hpp"
18 
19 #include <ostream>
20 #include <string>
21 #include <vector>
22 
24 {
25 public:
26  MAKE_ENUM(EPOCH, (BEFORE_WESNOTH, "BW")(WESNOTH, "YW")(BEFORE_FALL, "BF")(AFTER_FALL, "AF"))
27 
28  irdya_date() = default;
29 
30  irdya_date(EPOCH epoch, unsigned year)
31  : epoch(epoch)
32  , year(year)
33  {
34  }
35 
36  static irdya_date read_date(const std::string& date);
37 
38  EPOCH get_epoch() const
39  {
40  return epoch;
41  }
42 
43  unsigned int get_year() const
44  {
45  return year;
46  }
47 
48  /* There is no year 0, so use that to represent an "invalid" date. */
49  bool is_valid() const
50  {
51  return year != 0;
52  }
53 
54  /* Outputs a locale-dependent string describing the year. */
55  std::string to_string() const;
56 
57 private:
58  EPOCH epoch;
59 
60  unsigned int year = 0;
61 
62  // TODO: Decide how many months and days there are!
63  //unsigned int month = 0;
64  //unsigned int day = 0;
65 };
66 
67 bool operator<(const irdya_date& a, const irdya_date& b);
68 bool operator<=(const irdya_date& a, const irdya_date& b);
69 bool operator>(const irdya_date& a, const irdya_date& b);
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 
74 std::ostream& operator<<(std::ostream& s, const irdya_date& d);
bool is_valid() const
bool operator==(const irdya_date &a, const irdya_date &b)
#define a
bool operator<=(const irdya_date &a, const irdya_date &b)
#define d
irdya_date(EPOCH epoch, unsigned year)
std::string to_string() const
#define b
std::ostream & operator<<(std::ostream &s, const irdya_date &d)
static irdya_date read_date(const std::string &date)
bool operator>(const irdya_date &a, const irdya_date &b)
bool operator<(const irdya_date &a, const irdya_date &b)
unsigned int year
static map_location::DIRECTION s
bool operator!=(const irdya_date &a, const irdya_date &b)
unsigned int get_year() const
EPOCH get_epoch() const
MAKE_ENUM(EPOCH,(BEFORE_WESNOTH, "BW")(WESNOTH, "YW")(BEFORE_FALL, "BF")(AFTER_FALL, "AF")) irdya_date()=default
bool operator>=(const irdya_date &a, const irdya_date &b)
Defines the MAKE_ENUM macro.