Fesapi 2.3.0.0
This project provides C++ classes which allow an easy access in import and export to the Energistics standards.
TimeTools.h
1/*-----------------------------------------------------------------------
2Licensed to the Apache Software Foundation (ASF) under one
3or more contributor license agreements. See the NOTICE file
4distributed with this work for additional information
5regarding copyright ownership. The ASF licenses this file
6to you under the Apache License, Version 2.0 (the
7"License"; you may not use this file except in compliance
8with the License. You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12Unless required by applicable law or agreed to in writing,
13software distributed under the License is distributed on an
14"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15KIND, either express or implied. See the License for the
16specific language governing permissions and limitations
17under the License.
18-----------------------------------------------------------------------*/
19#pragma once
20
21#include "date.h"
22
23namespace timeTools
24{
28 // No more used because DAS support has been removed
29 // Disabled because it needs to include <cmath> which creates a conflict with gsoap 2.8.81 : see https://github.com/F2I-Consulting/fesapi/issues/90
30 //std::string convertMicrosecondUnixTimestampToIso(long long ts);
31
39 std::string convertUnixTimestampToIso(time_t ts);
40
49 time_t convertIsoToUnixTimestamp(const std::string & s);
50
58 time_t timegm(std::tm const& t);
59
68 template <typename Clock, typename Duration>
69 std::tm to_calendar_time(std::chrono::time_point<Clock, Duration> tp)
70 {
71 using namespace date;
72 auto date = floor<days>(tp);
73 auto ymd = year_month_day(date);
74 auto weekday = year_month_weekday(date).weekday_indexed().weekday();
75 auto tod = make_time(tp - date);
76 days daysSinceJan1 = date - sys_days(ymd.year() / 1 / 1);
77
78 std::tm result;
79 result.tm_sec = tod.seconds().count();
80 result.tm_min = tod.minutes().count();
81 result.tm_hour = tod.hours().count();
82 result.tm_mday = (ymd.day() - 0_d).count();
83 result.tm_mon = (ymd.month() - January).count();
84 result.tm_year = (ymd.year() - 1900_y).count();
85 result.tm_wday = (weekday - Sunday).count();
86 result.tm_yday = daysSinceJan1.count();
87 result.tm_isdst = -1; // Information not available
88 return result;
89 }
90}
91
Definition: date.h:444
Definition: date.h:693
Definition: date.h:823
The timeTools namespace.
time_t timegm(std::tm const &t)
time_t convertIsoToUnixTimestamp(const std::string &s)
std::string convertUnixTimestampToIso(time_t ts)
std::tm to_calendar_time(std::chrono::time_point< Clock, Duration > tp)
Definition: TimeTools.h:69