libosmscout 1.1.1
Loading...
Searching...
No Matches
Time.h
Go to the documentation of this file.
1#ifndef OSMSCOUT_UTIL_TIME_H
2#define OSMSCOUT_UTIL_TIME_H
3
4/*
5 This source is part of the libosmscout library
6 Copyright (C) 2018 Lukas Karas
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21*/
22
23#include <chrono>
24
25namespace osmscout {
26
27 using Timestamp = std::chrono::system_clock::time_point;
28
29 using Duration = Timestamp::duration;
30
31 using HourDuration = std::chrono::duration<double, std::ratio<3600>>;
32
33 inline double DurationAsSeconds(Duration duration)
34 {
35 return std::chrono::duration_cast<std::chrono::duration<double>>(
36 duration).count();
37 }
38
39 inline double DurationAsHours(Duration duration)
40 {
41 return std::chrono::duration_cast<HourDuration>(duration).count();
42 }
43
44 inline Duration DurationOfHours(double hours)
45 {
46 return std::chrono::duration_cast<Duration>(HourDuration(hours));
47 }
48}
49
50#endif //OSMSCOUT_UTIL_TIME_H
Definition Area.h:39
std::chrono::system_clock::time_point Timestamp
Definition Time.h:27
double DurationAsHours(Duration duration)
Definition Time.h:39
Duration DurationOfHours(double hours)
Definition Time.h:44
std::chrono::duration< double, std::ratio< 3600 > > HourDuration
Definition Time.h:31
Timestamp::duration Duration
Definition Time.h:29
double DurationAsSeconds(Duration duration)
Definition Time.h:33