ARTS  2.3.1285(git:92a29ea9-dirty)
m_artstime.cc
Go to the documentation of this file.
1 /* Copyright (C) 2020
2  * Richard Larsson <larsson@mps.mpg.de>
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2, or (at your option) any
7  * later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17  * USA. */
18 
27 #include <thread>
28 
29 #include "matpackI.h"
30 #include "artstime.h"
31 #include "messages.h"
32 #include "sorting.h"
33 
34 
35 void timeNow(Time& time, const Verbosity&)
36 {
37  time = Time();
38 }
39 
40 
41 void Duration(Numeric& duration, const Time& t0, const Time& t1, const Verbosity&)
42 {
43  duration = std::chrono::duration_cast<TimeStep>(t1 - t0).count();
44 }
45 
46 
47 void Sleep(const Numeric& duration, const Verbosity&)
48 {
49  std::this_thread::sleep_for(TimeStep(duration));
50 }
51 
52 
53 void timeSleep(const Time& time, const Verbosity&)
54 {
55  std::this_thread::sleep_until(time.Data());
56 }
57 
58 
60 {
61  const Time time;
62  const Time localtime = Time(time.toStruct());
63  const Time gmtime = Time(time.toGMTStruct());
64  dt = std::chrono::duration_cast<TimeStep>(localtime - gmtime).count();
65 }
66 
67 
68 void timeOffset(Time& time, const Numeric& offset, const Verbosity&)
69 {
70  time += TimeStep(offset);
71 }
72 
73 
74 void time_gridOffset(ArrayOfTime& time_grid, const Numeric& offset, const Verbosity& verbosity)
75 {
76  for (Time& time: time_grid)
77  timeOffset(time, offset, verbosity);
78 }
void timeOffset(Time &time, const Numeric &offset, const Verbosity &)
WORKSPACE METHOD: timeOffset.
Definition: m_artstime.cc:68
std::tm toStruct() const
Definition: artstime.h:60
void Duration(Numeric &duration, const Time &t0, const Time &t1, const Verbosity &)
WORKSPACE METHOD: Duration.
Definition: m_artstime.cc:41
Declarations having to do with the four output streams.
Class to handle time in ARTS.
Definition: artstime.h:40
std::chrono::duration< Numeric > TimeStep
A duration of time, 1 full tick should be 1 second.
Definition: artstime.h:37
void time_gridOffset(ArrayOfTime &time_grid, const Numeric &offset, const Verbosity &verbosity)
WORKSPACE METHOD: time_gridOffset.
Definition: m_artstime.cc:74
void Sleep(const Numeric &duration, const Verbosity &)
WORKSPACE METHOD: Sleep.
Definition: m_artstime.cc:47
Contains sorting routines.
void LocalTimeOffset(Numeric &dt, const Verbosity &)
WORKSPACE METHOD: LocalTimeOffset.
Definition: m_artstime.cc:59
const std::chrono::system_clock::time_point & Data() const
Definition: artstime.h:56
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
Implementation of Matrix, Vector, and such stuff.
This can be used to make arrays out of anything.
Definition: array.h:40
std::tm toGMTStruct() const
Definition: artstime.h:61
Stuff related to time in ARTS.
void timeSleep(const Time &time, const Verbosity &)
WORKSPACE METHOD: timeSleep.
Definition: m_artstime.cc:53
void timeNow(Time &time, const Verbosity &)
WORKSPACE METHOD: timeNow.
Definition: m_artstime.cc:35