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;
86 tp = localtime(&clock);
93 return hour(tp->tm_hour, tp->tm_min, tp->tm_sec);
96 /* An hour is a proper hour if it lies within the 24-hour clock. */
100 return hours >= 0 && hours < 24 &&
101 minutes >= 0 && minutes < 60 &&
102 seconds >= 0 && seconds < 60;
105 hour operator+(hour t1, hour t2)
109 t.seconds += t2.seconds;
115 t.minutes += t2.minutes;
126 hour operator+(hour t1, long sec)
130 s = t1.hours * 3600 + t1.minutes * 60 + t1.seconds;
138 hour hour::operator+=(hour t)
140 seconds += t.seconds;
146 minutes += t.minutes;
157 hour hour::increase()
174 hour operator-(hour t1, hour t2)
178 t.seconds -= t2.seconds;
185 t.minutes -= t2.minutes;
197 hour operator-(hour t1, long sec)
201 s = t1.hours * 3600 + t1.minutes * 60 + t1.seconds;
209 hour hour::operator-=(hour t)
211 seconds -= t.seconds;
218 minutes -= t.minutes;
230 hour hour::decrease()
248 std::ostream& operator<<(std::ostream &s, const hour &t)
255 s << t.minutes << ":";
263 std::istream &operator>>(std::istream &s, hour &h)
268 s >> H >> c >> M >> c >> S;
277 String hour::format(const char *fmt)
287 strftime(buf, 40, fmt, &t);