libtime++: Date and time calculation
convert.cc
Go to the documentation of this file.
1 
35 #define TF_CONVERT_CC_VERSION \
36  "TF_CONVERT_CC V1.1"
37 
38 #include <libtime++.h>
39 
40 namespace libtime {
41 
42 TRelativeTime double2time(const double& seconds)
43 {
44  libtime_assert(seconds>=0,
45  "ERROR (double2time): only positive values are accepted");
46  time_kernel::time_Ts thetime_Ts(TRelativeTime(0));
47  double remain=seconds;
48  typedef timeint li;
49  thetime_Ts.second=li(seconds);
50  remain-=double(thetime_Ts.second);
51  remain*=1.e3;
52  thetime_Ts.milsec=li(remain);
53  remain-=double(thetime_Ts.milsec);
54  remain*=1.e3;
55  thetime_Ts.micsec=li(remain);
56  return(TRelativeTime(thetime_Ts));
57 } // TRelativeTime double2time(const double& seconds)
58 
59 double time2double(const TRelativeTime& rtime)
60 {
61  double retval(0.);
62  retval=rtime.float_second();
63  retval += 60.*rtime.minute();
64  retval += 3600.*rtime.hour();
65  retval += 24.*3600.*rtime.days();
66  return(retval);
67 } // double time2float(const TRelativeTime&)
68 
69 } // namespace libtime
70 
71 /* ----- END OF convert.cc ----- */
timeint days() const
Definition: libtime++.h:408
#define libtime_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: libtime++.h:714
double float_second() const
Definition: libtime++.h:295
double time2double(const TRelativeTime &rtime)
convert relative time to seconds
Definition: convert.cc:59
TRelativeTime double2time(const double &seconds)
convert seconds to relative time
Definition: convert.cc:42
class to contain relative times
Definition: libtime++.h:201
integer timeint
Definition: libtime.h:77
timeint hour() const
Definition: libtime++.h:290
timeint minute() const
Definition: libtime++.h:291