***********************
** FILE NAME : hour.cpp
** SYSTEM NAME : AXE - Andromeda X-windows Encapsulation
-** VERSION NUMBER : $Revision: 1.1 $
+** VERSION NUMBER : $Revision: 1.2 $
**
** DESCRIPTION :
**
/*****************************
$Log: hour.cpp,v $
- Revision 1.1 2002-07-25 08:01:27 arjen
+ Revision 1.2 2002-09-02 06:18:20 arjen
+ Fixed some date and time conversion functions
+
+ Revision 1.1 2002/07/25 08:01:27 arjen
First checkin, AXE release 0.2
*****************************/
-static const char *RCSID = "$Id: hour.cpp,v 1.1 2002-07-25 08:01:27 arjen Exp $";
+static const char *RCSID = "$Id: hour.cpp,v 1.2 2002-09-02 06:18:20 arjen Exp $";
+
+#include <time.h>
#include "date.h"
#include "parsedate.h"
seconds = pd->second;
}
+hour now()
+{
+ long clock;
+ struct tm *tp;
+
+ time(&clock);
+ tp = localtime(&clock);
+
+ return hour(tp->tm_hour, tp->tm_min, tp->tm_sec);
+}
+
hour operator+(hour &t1, hour &t2)
{
hour t = t1;
ostream& operator<<(ostream &s, const hour &t)
{
- s << t.hours << ":" << t.minutes << ":" << t.seconds;
+ s.width(2);
+ s.fill('0');
+ s << t.hours << ":";
+ s.width(2);
+ s.fill('0');
+ s << t.minutes << ":";
+ s.width(2);
+ s.fill('0');
+ s << t.seconds;
+
+ return s;
+}
+
+istream &operator>>(istream &s, hour &h)
+{
+ char c;
+ int H, M, S;
+
+ s >> H >> c >> M >> c >> S;
+
+ h.hours = H;
+ h.minutes = M;
+ h.seconds = S;
+
+ return s;
+}
+
+String hour::format(const char *fmt)
+{
+ String s;
+ char buf[40];
+ struct tm t;
+
+ t.tm_sec = seconds;
+ t.tm_min = minutes;
+ t.tm_hour = hours;
+
+ strftime(buf, 40, fmt, &t);
+ s = buf;
return s;
}