My Project
Loading...
Searching...
No Matches
TimeService.hpp
1/*
2 Copyright 2019 Equinor ASA.
3
4 This file is part of the Open Porous Media Project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef OPM_TIMESERVICE_HEADER_INCLUDED
21#define OPM_TIMESERVICE_HEADER_INCLUDED
22
23#include <chrono>
24#include <ctime>
25#include <string>
26#include <unordered_map>
27
28namespace Opm {
29
30 class DeckRecord;
31
32 using time_point = std::chrono::time_point<std::chrono::system_clock, std::chrono::duration<int64_t, std::ratio<1,1000>>>;
33
34 namespace TimeService {
35 std::time_t to_time_t(const time_point& tp);
36 time_point from_time_t(std::time_t t);
37 time_point now();
38
39 std::time_t advance(const std::time_t tp, const double sec);
40 std::time_t makeUTCTime(std::tm timePoint);
41 const std::unordered_map<std::string , int>& eclipseMonthIndices();
42 const std::unordered_map<int, std::string>& eclipseMonthNames();
43 int eclipseMonth(const std::string& name);
44 bool valid_month(const std::string& month_name);
45
46 std::time_t mkdatetime(int in_year, int in_month, int in_day, int hour, int minute, int second);
47 std::time_t mkdate(int in_year, int in_month, int in_day);
48 std::time_t portable_timegm(const std::tm* t);
49 std::time_t timeFromEclipse(const DeckRecord &dateRecord);
50 }
51
53 {
54 public:
55 struct YMD {
56 int year{0};
57 int month{0};
58 int day{0};
59
60 bool operator==(const YMD& data) const
61 {
62 return year == data.year &&
63 month == data.month &&
64 day == data.day;
65 }
66
67 template<class Serializer>
68 void serializeOp(Serializer& serializer)
69 {
70 serializer(year);
71 serializer(month);
72 serializer(day);
73 }
74 };
75
76 TimeStampUTC() = default;
77
78 explicit TimeStampUTC(const std::time_t tp);
79 explicit TimeStampUTC(const YMD& ymd);
80 TimeStampUTC(int year, int month, int day);
81 TimeStampUTC(const YMD& ymd,
82 int hour,
83 int minutes,
84 int seconds,
85 int usec);
86
87 TimeStampUTC& operator=(const std::time_t tp);
88 bool operator==(const TimeStampUTC& data) const;
89
90 TimeStampUTC& hour(const int h);
91 TimeStampUTC& minutes(const int m);
92 TimeStampUTC& seconds(const int s);
93 TimeStampUTC& microseconds(const int us);
94
95 const YMD& ymd() const { return ymd_; }
96 int year() const { return this->ymd_.year; }
97 int month() const { return this->ymd_.month; }
98 int day() const { return this->ymd_.day; }
99 int hour() const { return this->hour_; }
100 int minutes() const { return this->minutes_; }
101 int seconds() const { return this->seconds_; }
102 int microseconds() const { return this->usec_; }
103
104 template<class Serializer>
105 void serializeOp(Serializer& serializer)
106 {
107 serializer(ymd_);
108 serializer(hour_);
109 serializer(minutes_);
110 serializer(seconds_);
111 serializer(usec_);
112 }
113
114 private:
115
116 YMD ymd_{};
117 int hour_{0};
118 int minutes_{0};
119 int seconds_{0};
120 int usec_{0};
121 };
122
123 TimeStampUTC operator+(const TimeStampUTC& lhs, std::chrono::duration<double> delta);
124 std::time_t asTimeT(const TimeStampUTC& tp);
125 std::time_t asLocalTimeT(const TimeStampUTC& tp);
126 time_point asTimePoint(const TimeStampUTC& tp);
127
128
129} // namespace Opm
130
131#endif // OPM_TIMESERVICE_HEADER_INCLUDED
Class for (de-)serializing.
Definition Serializer.hpp:84
Definition TimeService.hpp:53
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30
Definition TimeService.hpp:55