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 hour::operator+=(hour t)
128 seconds += t.seconds;
134 minutes += t.minutes;
145 hour hour::increase()
162 hour operator-(hour t1, hour t2)
166 t.seconds -= t2.seconds;
173 t.minutes -= t2.minutes;
185 hour hour::operator-=(hour t)
187 seconds -= t.seconds;
194 minutes -= t.minutes;
206 hour hour::decrease()
224 std::ostream& operator<<(std::ostream &s, const hour &t)
231 s << t.minutes << ":";
239 std::istream &operator>>(std::istream &s, hour &h)
244 s >> H >> c >> M >> c >> S;
253 String hour::format(const char *fmt)
263 strftime(buf, 40, fmt, &t);