libtime++: Date and time calculation

◆ main()

int main ( )

Definition at line 101 of file testtime++.cc.

References Ainit_from_value(), libtime::TAbsoluteTime::hierarchicalstring(), libtime::TRelativeTime::hierarchicalstring(), init_from_seconds(), libtime::now(), PRINTVALUE, Rinit_from_value(), libtime::time2double(), libtime::TBaseClassTime::timestring(), libtime::TAbsoluteTime::timestring(), and libtime::utc().

102 {
103  std::cout << "Hello world!\n";
104 
105  std::cout << "\nTesting constructors"
106  << "\n====================" << endl;
107 
108  std::cout << "\nTesting TAbsoluteTime"
109  << "\n---------------------" << endl;
110  init_from_string<libtime::TAbsoluteTime>("0/1/1");
111  init_from_string<libtime::TAbsoluteTime>("70/1/1");
112  init_from_string<libtime::TAbsoluteTime>("60/1/1");
113  init_from_string<libtime::TAbsoluteTime>("160/1/1");
114  init_from_string<libtime::TAbsoluteTime>("1978/1/1");
115  init_from_string<libtime::TAbsoluteTime>("1978/13/1");
116  init_from_string<libtime::TAbsoluteTime>("1978/1/2/3/4/5/6/7/8/9");
117 
118  std::cout << endl;
119  Ainit_from_value(2000,1,1);
120  Ainit_from_value(000,1,50);
121  Ainit_from_value(000,1,50,12,23,34,45,56);
122 
123  std::cout << "\nTesting TRelativeTime"
124  << "\n---------------------" << endl;
125  init_from_string<libtime::TRelativeTime>("0");
126  init_from_string<libtime::TRelativeTime>("8");
127  init_from_string<libtime::TRelativeTime>("123.23.34.45.56789");
128  init_from_string<libtime::TRelativeTime>("123.2345.34567.45678.56789");
129  init_from_seconds(1.e-6);
130  init_from_seconds(1.e-3);
131  init_from_seconds(1.);
132  init_from_seconds(60.);
133  init_from_seconds(3600.);
134  init_from_seconds(86400.);
135  init_from_seconds(123.345763);
136  init_from_seconds(871323.345763);
137 
138  std::cout << endl;
139  Rinit_from_value(0);
140  Rinit_from_value(2000,1,1);
141  Rinit_from_value(0,24,60,60,1000,1000);
142  Rinit_from_value(00,0,0,0,0,99999999L);
143 
144 // junk:
145  libtime::TRelativeTime Q(600,20,10,30,40,10);
146  libtime::TRelativeTime OneSecond(0,0,0,1);
147  libtime::TAbsoluteTime Now(2000,9,12,16,12);
148  libtime::TAbsoluteTime Then(2000,10,2,10,0);
149  cout << string(Q) << endl;
150  cout << string(OneSecond) << endl;
151  cout << string(Q%OneSecond) << endl;
152  long int numbo=Q/OneSecond;
153  cout << Q/OneSecond << endl;
154  cout << string(OneSecond*numbo) << endl;
155  numbo=(Now-Then)/OneSecond;
156  cout << numbo << " seconds from "
157  << string(Now) << endl << " to " << string(Then) << endl;
158  Q=numbo*OneSecond;
159  cout << "these are " << string(Q) << endl << " and lead to "
160  << string(Now+Q) << endl << " from " << string(Now) << endl;
161 
162  std::cout << "current time: " << libtime::now().timestring() << std::endl;
163  std::cout << "current time (UTC): " << libtime::utc().timestring() << std::endl;
164 
165  {
166  std::cout << "hierarchical strings:" << std::endl;
167  libtime::TAbsoluteTime Atime(2000,9,12,16,12,34,56,78);
168  libtime::TRelativeTime Rtime(514,16,12,34,56,78);
169  std::cout << Atime.timestring() << std::endl;
170  std::cout << Atime.hierarchicalstring() << std::endl;
171  std::cout << Rtime.timestring() << std::endl;
172  std::cout << Rtime.hierarchicalstring() << std::endl;
173  }
174 
175  std::cout << "\nSystematically test derived units"
176  << "\n---------------------------------" << endl;
177  PRINTVALUE( Days(25.5) );
178  PRINTVALUE( Hours(25.5) );
179  PRINTVALUE( Minutes(25.5) );
180  PRINTVALUE( Seconds(25.5) );
181  PRINTVALUE( Milliseconds(25.5) );
182  PRINTVALUE( Microseconds(25.5) );
183 
184  PRINTVALUE( Days(6) );
185  PRINTVALUE( Hours(6) );
186  PRINTVALUE( Minutes(6) );
187  PRINTVALUE( Seconds(6) );
188  PRINTVALUE( Milliseconds(6) );
189  PRINTVALUE( Microseconds(6) );
190 
191  PRINTVALUE( Days(180) );
192  PRINTVALUE( Hours(180) );
193  PRINTVALUE( Minutes(180) );
194  PRINTVALUE( Seconds(180) );
195  PRINTVALUE( Milliseconds(180) );
196  PRINTVALUE( Microseconds(180) );
197 
198  PRINTVALUE( Days(22,22,22,22,22,22) );
199  PRINTVALUE( Hours(22,22,22,22,22) );
200  PRINTVALUE( Minutes(22,22,22,22) );
201  PRINTVALUE( Seconds(22,22,22) );
202  PRINTVALUE( Milliseconds(22,22) );
203  PRINTVALUE( Microseconds(22) );
204 
205  PRINTVALUE( Hours(6) );
206  PRINTVALUE( 118*Days()+4*Hours()+10*Minutes()+Milliseconds(25.51) );
207  PRINTVALUE( Minutes(34.123456) );
208  PRINTVALUE( Minutes(34,123,456) );
209  PRINTVALUE( Seconds(34.123456) );
210  PRINTVALUE( Seconds(34,123,456) );
211  PRINTVALUE( Seconds(90072) );
212  PRINTVALUE( 2.5*Days() );
213  PRINTVALUE( Days(2.5) );
214  PRINTVALUE( Seconds(2.5*time2double(Days())) );
215 
217  PRINTVALUE( nowtime.timestring("%Y") );
218  PRINTVALUE( nowtime.timestring("/basedir/subdir/%Y/%m/%Y%m%d.dat") );
219  PRINTVALUE( libtime::now().timestring("%H:%M:%S") );
220  PRINTVALUE( libtime::now().timestring("time is %c") );
221  PRINTVALUE( libtime::utc().timestring("time is %c") );
222 }
double time2double(const TRelativeTime &rtime)
convert relative time to seconds
Definition: convert.cc:59
provide a convenient way to specify time intervals in the order of one hour
Definition: libtime++.h:550
provide a convenient way to specify time intervals in the order of one microsecond ...
Definition: libtime++.h:598
TAbsoluteTime utc()
return system time in UTC
Definition: now.cc:58
provide a convenient way to specify time intervals in the order of one day
Definition: libtime++.h:537
void Ainit_from_value(const long int &year, const long int &month, const long int &day, const long int &hour=0, const long int &minute=0, const long int &second=0, const long int &milsec=0, const long int &micsec=0)
Definition: testtime++.cc:58
class to contain relative times
Definition: libtime++.h:201
provide a convenient way to specify time intervals in the order of one minute
Definition: libtime++.h:563
std::string timestring(const std::string &format) const
return string representation of time.
provide a convenient way to specify time intervals in the order of one millisecond ...
Definition: libtime++.h:587
void Rinit_from_value(const long int &days, const long int &hour=0, const long int &minute=0, const long int &second=0, const long int &milsec=0, const long int &micsec=0)
Definition: testtime++.cc:73
TAbsoluteTime now()
return system time
Definition: now.cc:44
provide a convenient way to specify time intervals in the order of one second
Definition: libtime++.h:575
class to contain absolute times
Definition: libtime++.h:149
void init_from_seconds(const double &seconds)
Definition: testtime++.cc:87
#define PRINTVALUE(V)
Definition: testtime++.cc:43
Here is the call graph for this function: