- added src/endian.h... still need to add configure support to
[barry.git] / src / time.cc
bloba2f4154ab02275e75808ef2137f1b6c0c6a80b49
1 ///
2 /// \file time.cc
3 /// Conversion between time_t and cenmin_t and back.
4 /// time_t is the POSIX time, seconds from Jan 1, 1970
5 /// min1900_t is the minutes from Jan 1, 1900
6 ///
8 /*
9 Copyright (C) 2005-2006, Net Direct Inc. (http://www.netdirect.ca/)
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 See the GNU General Public License in the COPYING file at the
21 root directory of this project for more details.
24 #include "time.h"
28 #ifdef __TEST_MODE__
30 #include <iostream>
31 #include <iomanip>
33 using namespace std;
34 using namespace Barry;
36 void display(const char *msg, time_t t)
38 cout << msg << ": " << ctime(&t);
39 cout << msg << " seconds: "
40 << setbase(10) << t
41 << "(0x" << setbase(16) << t << ")"
42 << endl;
43 cout << msg << " minutes: "
44 << setbase(10) << (t/60)
45 << "(0x" << setbase(16) << (t/60) << ")"
46 << endl;
47 cout << endl;
50 void calc(const char *msg, time_t t, min1900_t dbval)
52 cout << msg << endl;
53 display(" Initial time", t);
54 display(" DB Val", min2time(dbval));
57 int main()
59 struct tm start;
60 time_t t;
62 // set to Oct 4, 2005, 2pm;
63 start.tm_sec = 0;
64 start.tm_min = 0;
65 start.tm_hour = 14;
66 start.tm_mday = 4;
67 start.tm_mon = 9;
68 start.tm_year = 105;
69 start.tm_isdst = -1;
70 t = mktime(&start);
71 calc("Oct 4", t, 0x0350c118);
73 // comparison
74 t = time(NULL);
75 min1900_t m = time2min(t);
76 time_t tc = min2time(m);
77 cout << "Original time: " << t << endl;
78 cout << "time2min: " << m << endl;
79 cout << "min2time: " << tc << endl;
80 if( t == (tc + t % 60) )
81 cout << "Success! (orig == converted + mod)" << endl;
82 else
83 cout << "Failed!" << endl;
86 #endif