forked from mcoquet642/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCCDBTimeStampUtils.cxx
More file actions
56 lines (49 loc) · 1.77 KB
/
CCDBTimeStampUtils.cxx
File metadata and controls
56 lines (49 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
//
// Created by Sandro Wenzel on 2019-08-20.
//
#include <CCDB/CCDBTimeStampUtils.h>
#include <chrono>
#include <ctime>
namespace o2::ccdb
{
long getFutureTimestamp(int secondsInFuture)
{
std::chrono::seconds sec(secondsInFuture);
auto future = std::chrono::system_clock::now() + sec;
auto future_ms = std::chrono::time_point_cast<std::chrono::milliseconds>(future);
auto epoch = future_ms.time_since_epoch();
auto value = std::chrono::duration_cast<std::chrono::milliseconds>(epoch);
return value.count();
}
/// returns the timestamp in long corresponding to "now"
long getCurrentTimestamp()
{
auto now = std::chrono::system_clock::now();
auto now_ms = std::chrono::time_point_cast<std::chrono::milliseconds>(now);
auto epoch = now_ms.time_since_epoch();
auto value = std::chrono::duration_cast<std::chrono::milliseconds>(epoch);
return value.count();
}
/// \brief Converting time into numerical time stamp representation
long createTimestamp(int year, int month, int day, int hour, int minutes, int seconds)
{
struct tm timeinfo;
timeinfo.tm_year = year;
timeinfo.tm_mon = month;
timeinfo.tm_mday = day;
timeinfo.tm_hour = hour;
timeinfo.tm_min = minutes;
timeinfo.tm_sec = seconds;
time_t timeformat = mktime(&timeinfo);
return static_cast<long>(timeformat);
}
} // namespace o2::ccdb