1 /**************************************************************************
2 ** (c) Copyright 1999, Andromeda Technology & Automation
3 ***************************************************************************
4 ** MODULE INFORMATION *
5 ***********************
6 ** FILE NAME : hour.cpp
7 ** SYSTEM NAME : AXE - Andromeda X-windows Encapsulation
8 ** VERSION NUMBER : $Revision: 1.3 $
15 ***************************************************************************
16 ** ADMINISTRATIVE INFORMATION *
17 ********************************
18 ** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
19 ** CREATION DATE : Feb 06, 1998
20 ** LAST UPDATE : Oct 16, 1999
21 **************************************************************************/
23 /*****************************
25 Revision 1.3 2002-09-28 06:58:45 arjen
26 Bugfix: conversion of an empty string to a date or hour object
27 now makes the values of such an object 0 (null) instead of giving
29 The class UTC combines the date and hour classes. The most basic
30 functions of the UTC class are now implemented.
31 These include constructors and conversion to and from String objects.
32 New functions: date::proper(), hour::proper() and UTC::proper().
33 Return true if the object holds a proper clock time and/or calendar
34 date; false if at least one value is out of range.
36 Revision 1.2 2002/09/02 06:18:20 arjen
37 Fixed some date and time conversion functions
39 Revision 1.1 2002/07/25 08:01:27 arjen
40 First checkin, AXE release 0.2
42 *****************************/
44 static const char *RCSID = "$Id: hour.cpp,v 1.3 2002-09-28 06:58:45 arjen Exp $";
49 #include "parsedate.h"
53 struct parseddate *pd;
76 tp = localtime(&clock);
78 return hour(tp->tm_hour, tp->tm_min, tp->tm_sec);
81 /* An hour is a proper hour if it lies within the 24-hour clock. */
85 return hours >= 0 && hours < 24 &&
86 minutes >= 0 && minutes < 60 &&
87 seconds >= 0 && seconds < 60;
90 hour operator+(hour &t1, hour &t2)
94 t.seconds += t2.seconds;
100 t.minutes += t2.minutes;
111 hour hour::operator+=(hour t)
113 seconds += t.seconds;
119 minutes += t.minutes;
130 hour operator-(hour &t1, hour &t2)
134 t.seconds -= t2.seconds;
141 t.minutes -= t2.minutes;
153 std::ostream& operator<<(std::ostream &s, const hour &t)
160 s << t.minutes << ":";
168 std::istream &operator>>(std::istream &s, hour &h)
173 s >> H >> c >> M >> c >> S;
182 String hour::format(const char *fmt)
192 strftime(buf, 40, fmt, &t);