Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
source_date_epoch.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
/*
6 * Authors:
7 * Patrick Storz <eduard.braun2@gmx.de>
8 *
9 * Copyright (C) 2019 Authors
10 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
11 */
12
13#include <sstream>
14#include <iostream>
15#include <cstdlib>
16#include <ctime>
17#include <glibmm/ustring.h>
18
20
21time_t now()
22{
23 time_t now = 0;
24
25 char *source_date_epoch = std::getenv("SOURCE_DATE_EPOCH");
26 if (source_date_epoch) {
27 std::istringstream iss(source_date_epoch);
28 iss >> now;
29 if (iss.fail() || !iss.eof()) {
30 std::cerr << "Error: Cannot parse SOURCE_DATE_EPOCH as integer\n";
31 std::terminate();
32 }
33 }
34
35 return now;
36}
37
38Glib::ustring now_iso_8601()
39{
40 Glib::ustring now_formatted;
41
43 if (now) {
44 const tm *now_struct;
45 char buffer[25];
46
47 now_struct = gmtime(&now);
48 if (strftime(buffer, 25, "%Y-%m-%dT%H:%M:%S", now_struct)) {
49 now_formatted = buffer;
50 }
51 }
52
53 return now_formatted;
54}
55
56} // namespace ReproducibleBuilds
57
Glib::ustring now_iso_8601()
like ReproducibleBuilds::now() but returns a ISO 8601 formatted string
time_t now()
parse current time from SOURCE_DATE_EPOCH environment variable