The Battle for Wesnoth  1.15.2+dev
irdya_datetime.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2017-2018 by the Battle for Wesnoth Project https://www.wesnoth.org/
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY.
10 
11  See the COPYING file for more details.
12 */
13 
14 #pragma once
15 
16 #include "utils/make_enum.hpp"
17 
18 #include <ostream>
19 #include <string>
20 #include <vector>
21 
23 {
24 public:
25  MAKE_ENUM(EPOCH, (BEFORE_WESNOTH, "BW")(WESNOTH, "YW")(BEFORE_FALL, "BF")(AFTER_FALL, "AF"))
26 
27  irdya_date() = default;
28 
29  irdya_date(EPOCH epoch, unsigned year)
30  : epoch(epoch)
31  , year(year)
32  {
33  }
34 
35  static irdya_date read_date(const std::string& date);
36 
37  EPOCH get_epoch() const
38  {
39  return epoch;
40  }
41 
42  unsigned int get_year() const
43  {
44  return year;
45  }
46 
47  /* There is no year 0, so use that to represent an "invalid" date. */
48  bool is_valid() const
49  {
50  return year != 0;
51  }
52 
53  /* Outputs a locale-dependent string describing the year. */
54  std::string to_string() const;
55 
56 private:
57  EPOCH epoch;
58 
59  unsigned int year = 0;
60 
61  // TODO: Decide how many months and days there are!
62  //unsigned int month = 0;
63  //unsigned int day = 0;
64 };
65 
66 bool operator<(const irdya_date& a, const irdya_date& b);
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 
73 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.