38 #define PRINTVALUE( V ) \ 39 cout << #V << ":\n " << string(V) << endl; 46 <<
"Example 1: How many seconds are there within a day?\n" 49 <<
" First we create a relative time span of one day length:\n";
52 cout <<
" " << string(oneday) << endl;
55 <<
" Then we create a relative time span of one second length:\n";
58 cout <<
" " << string(onesecond) << endl;
61 <<
" Then we divide the one by the other:\n" 62 <<
" " << oneday/onesecond << endl;
64 cout <<
" So there are " << oneday/onesecond
65 <<
" seconds within one day.\n" 77 <<
"Example 2: Which is the time of the last sample?\n" 81 cout <<
" We have a time series that starts with a first sample at:\n";
82 std::string startstring(
"2000/12/20 22:34:53.241");
83 cout <<
" " << startstring << endl;
86 <<
" We create an absolute time for the first sample:\n";
88 cout <<
" " << string(starttime) << endl;
91 <<
" The sampling interval of the time series is:\n";
93 cout <<
" " << string(interval) << endl;
96 <<
" The total series has " << nsamples <<
" samples" 97 <<
" with " << nsamples-1 <<
" intervals.\n" 98 <<
" That is a time span of:\n";
99 timespan=interval*(nsamples-1);
100 cout <<
" " << string(timespan) << endl;
103 <<
" Hence the last sample was taken at:\n" 104 <<
" " << string(starttime+timespan) << endl;
106 cout <<
" You'd like a more advanced one?\n";
117 <<
" So " << s1 <<
" is ";
118 t1 < t2 ? cout <<
"earlier" : cout <<
"later";
120 cout <<
" than " << s2 <<
"." << endl;;
121 cout <<
" The time span between them is " << std::string(t2-t1) << endl;
123 t2-t1 < i/2 ? cout <<
"smaller" : cout <<
"larger";
124 cout <<
" than half a sampling interval.\n";
130 reqstart(
"2000/12/8 12:37:14"),
131 reqend(
"2000/12/8 12:43:52"),
136 <<
"Example 3: Serving a data request\n" 140 cout <<
" Imagine that you might have a database file that starts\n" 141 <<
" with a first sample at " 142 << std::string(first) <<
".\n" 143 <<
" A client requests a time series that should start at\n" 144 <<
" " << std::string(reqstart) <<
" and end at " 145 <<
" " << std::string(reqend) <<
".\n" 146 <<
" The sampling interval is " << std::string(interval) << endl;
148 long int offset1=(reqstart-first)/interval;
149 long int offset2=(reqend-first)/interval;
150 exstart=first+interval*(offset1);
151 exend=first+interval*(offset2);
152 reqspan=reqend-reqstart;
153 exspan=exend-exstart;
155 cout <<
" The requested time span is " 156 << std::string(reqspan) << endl;
159 <<
" The client will receive a data segment from offset " 160 << offset1 <<
" to " << offset2 <<
".\n";
162 cout <<
" The segment's first sample is at " << std::string(exstart) <<
"\n" 163 <<
" and it's last one is at " << std::string(exend) << endl;
166 "the first delivered sample",
167 reqstart, exstart, interval);
170 "the last delivered sample",
171 reqend, exend, interval);
174 "the sample before the first delivered one",
175 reqstart, exstart-interval, interval);
178 "the sample after the first delivered one",
179 reqstart, exstart+interval, interval);
190 <<
"Example 4: How about leap-years?\n" 194 first=
"1979/02/15"; second=
"1979/03/01";
196 <<
" The time span between " << string(first) << endl
197 <<
" and " << string(second) << endl
198 <<
" is " << string(second-first) << endl;
200 first=
"1980/02/15"; second=
"1980/03/01";
202 <<
" The time span between " << string(first) << endl
203 <<
" and " << string(second) << endl
204 <<
" is " << string(second-first) << endl;
206 first=
"2000/02/15"; second=
"2000/03/01";
208 <<
" The time span between " << string(first) << endl
209 <<
" and " << string(second) << endl
210 <<
" is " << string(second-first) << endl;
212 first=
"2100/02/15"; second=
"2100/03/01";
214 <<
" The time span between " << string(first) << endl
215 <<
" and " << string(second) << endl
216 <<
" is " << string(second-first) << endl;
226 <<
"Example 5: What is a spurious year value?\n" 230 cout <<
" If you set an absolute time to a year for which I do not\n" 231 <<
" expect any digital seismological data to be available, I\n" 232 <<
" will regard this as a spurious year value. However any\n" 233 <<
" calculations with such values will lead to the expected\n" 234 <<
" results apart from the annoying warning message.\n";
237 <<
" I do not expect digital data for years before 1970:\n";
239 exampletime=
"1972/1/1";
240 exampletime=
"1971/1/1";
241 exampletime=
"1970/1/1";
242 exampletime=
"1969/1/1";
243 exampletime=
"1968/1/1";
251 cout <<
" " << exampledate <<
" means " 260 <<
"Example 6: How about year value abbreviation?\n" 264 cout <<
" You may abbreviate year values by two digits. The year\n" 265 <<
" will be automatically expanded to a full qualified value.\n" 266 <<
" The initial date is " 276 <<
" This means that you can not set the year to values below 100:\n";
289 <<
"Example 7: Convenient ways to specify times\n" 309 cout <<
"Example++\n\n" 310 <<
"This is an example program for the libtime++.a library.\n";
313 <<
"Time comes in two different flavours:\n" 314 <<
"1. absolute time (like today at 10 o'clock)\n" 315 <<
"2. relative times (like the time span between now and christmas)\n" 316 <<
"The following examples will show how to use and combine these\n" 317 <<
"two flavours.\n";
328 <<
"That's it... any questions?\n";
double time2double(const TRelativeTime &rtime)
convert relative time to seconds
provide a convenient way to specify time intervals in the order of one hour
provide a convenient way to specify time intervals in the order of one day
class to contain relative times
void example6sub(std::string exampledate)
provide a convenient way to specify time intervals in the order of one minute
provide a convenient way to specify time intervals in the order of one second
class to contain absolute times
void example3sub1(std::string s1, std::string s2, libtime::TAbsoluteTime t1, libtime::TAbsoluteTime t2, libtime::TRelativeTime i)