***********************
** FILE NAME : hour.cpp
** SYSTEM NAME : AXE - Andromeda X-windows Encapsulation
-** VERSION NUMBER : $Revision: 1.2 $
+** VERSION NUMBER : $Revision: 1.3 $
**
** DESCRIPTION :
**
/*****************************
$Log: hour.cpp,v $
- Revision 1.2 2002-09-02 06:18:20 arjen
+ Revision 1.3 2002-09-28 06:58:45 arjen
+ Bugfix: conversion of an empty string to a date or hour object
+ now makes the values of such an object 0 (null) instead of giving
+ a segmentation fault.
+ The class UTC combines the date and hour classes. The most basic
+ functions of the UTC class are now implemented.
+ These include constructors and conversion to and from String objects.
+ New functions: date::proper(), hour::proper() and UTC::proper().
+ Return true if the object holds a proper clock time and/or calendar
+ date; false if at least one value is out of range.
+
+ 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
*****************************/
-static const char *RCSID = "$Id: hour.cpp,v 1.2 2002-09-02 06:18:20 arjen Exp $";
+static const char *RCSID = "$Id: hour.cpp,v 1.3 2002-09-28 06:58:45 arjen Exp $";
#include <time.h>
{
struct parseddate *pd;
- pd = parsedate(s);
- hours = pd->hour;
- minutes = pd->minute;
- seconds = pd->second;
+ if (~s == 0)
+ {
+ hours = 0;
+ minutes = 0;
+ seconds = 0;
+ }
+ else
+ {
+ pd = parsedate(s);
+ hours = pd->hour;
+ minutes = pd->minute;
+ seconds = pd->second;
+ }
}
hour now()
return hour(tp->tm_hour, tp->tm_min, tp->tm_sec);
}
+/* An hour is a proper hour if it lies within the 24-hour clock. */
+
+bool hour::proper()
+{
+ return hours >= 0 && hours < 24 &&
+ minutes >= 0 && minutes < 60 &&
+ seconds >= 0 && seconds < 60;
+}
+
hour operator+(hour &t1, hour &t2)
{
hour t = t1;
return t;
}
-ostream& operator<<(ostream &s, const hour &t)
+std::ostream& operator<<(std::ostream &s, const hour &t)
{
s.width(2);
s.fill('0');
return s;
}
-istream &operator>>(istream &s, hour &h)
+std::istream &operator>>(std::istream &s, hour &h)
{
char c;
int H, M, S;