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;
84 tp = localtime(&clock);
86 return hour(tp->tm_hour, tp->tm_min, tp->tm_sec);
89 /* An hour is a proper hour if it lies within the 24-hour clock. */
93 return hours >= 0 && hours < 24 &&
94 minutes >= 0 && minutes < 60 &&
95 seconds >= 0 && seconds < 60;
98 hour operator+(hour &t1, hour &t2)
102 t.seconds += t2.seconds;
108 t.minutes += t2.minutes;
119 hour hour::operator+=(hour t)
121 seconds += t.seconds;
127 minutes += t.minutes;
138 hour hour::increase()
155 hour operator-(hour &t1, hour &t2)
159 t.seconds -= t2.seconds;
166 t.minutes -= t2.minutes;
178 hour hour::operator-=(hour t)
180 seconds -= t.seconds;
187 minutes -= t.minutes;
199 hour hour::decrease()
217 std::ostream& operator<<(std::ostream &s, const hour &t)
224 s << t.minutes << ":";
232 std::istream &operator>>(std::istream &s, hour &h)
237 s >> H >> c >> M >> c >> S;
246 String hour::format(const char *fmt)
256 strftime(buf, 40, fmt, &t);