***********************
** FILE NAME : date.cpp
** SYSTEM NAME : AXE - Andromeda X-windows Encapsulation
-** VERSION NUMBER : $Revision: 1.2 $
+** VERSION NUMBER : $Revision: 1.3 $
**
** DESCRIPTION :
**
/*****************************
$Log: date.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:26 arjen
*****************************/
-static const char *RCSID = "$Id: date.cpp,v 1.2 2002-09-02 06:18:20 arjen Exp $";
+static const char *RCSID = "$Id: date.cpp,v 1.3 2002-09-28 06:58:45 arjen Exp $";
#include <iostream>
#include <time.h>
{
struct parseddate *pd;
- pd = parsedate(s);
- year = pd->year;
- month = pd->month;
- day = pd->day;
+ if (~s == 0)
+ {
+ year = 0;
+ month = 0;
+ day = 0;
+ }
+ else
+ {
+ pd = parsedate(s);
+ year = pd->year;
+ month = pd->month;
+ day = pd->day;
+ }
}
int date::Leap(void)
return *this;
}
+bool date::proper()
+{
+ return year != -1 && year != 0 &&
+ month > 0 && month <= 12 &&
+ day > 0 && day <= DaysInMonth();
+}
+
date operator+(date d1, date d2)
{
d1.add(d2);
return d1.julian() - d2.julian();
}
-ostream &operator<<(ostream &s, const date &d)
+std::ostream &operator<<(std::ostream &s, const date &d)
{
s.width(2);
s.fill('0');
return s;
}
-istream &operator>>(istream &s, date &d)
+std::istream &operator>>(std::istream &s, date &d)
{
char c;
int D, M, Y;