+++ /dev/null
-/**************************************************************************
-** (c) Copyright 1999, Andromeda Technology & Automation
-***************************************************************************
-** MODULE INFORMATION *
-***********************
-** FILE NAME : hour.cpp
-** SYSTEM NAME : AXE - Andromeda X-windows Encapsulation
-** VERSION NUMBER : $Revision: 1.3 $
-**
-** DESCRIPTION :
-**
-** EXPORTED OBJECTS :
-** LOCAL OBJECTS :
-** MODULES USED :
-***************************************************************************
-** ADMINISTRATIVE INFORMATION *
-********************************
-** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
-** CREATION DATE : Feb 06, 1998
-** LAST UPDATE : Oct 16, 1999
-**************************************************************************/
-
-/*****************************
- $Log: hour.cpp,v $
- 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:27 arjen
- First checkin, AXE release 0.2
-
-*****************************/
-
-static const char *RCSID = "$Id: hour.cpp,v 1.3 2002-09-28 06:58:45 arjen Exp $";
-
-#include <time.h>
-
-#include "date.h"
-#include "parsedate.h"
-
-hour::hour(String s)
-{
- struct parseddate *pd;
-
- if (~s == 0)
- {
- hours = 0;
- minutes = 0;
- seconds = 0;
- }
- else
- {
- pd = parsedate(s);
- hours = pd->hour;
- minutes = pd->minute;
- seconds = pd->second;
- }
-}
-
-hour now()
-{
- long clock;
- struct tm *tp;
-
- time(&clock);
- tp = localtime(&clock);
-
- return hour(tp->tm_hour, tp->tm_min, tp->tm_sec);
-}
-
-/* An hour is a proper hour if it lies within the 24-hour clock. */
-
-bool hour::proper()
-{
- return hours >= 0 && hours < 24 &&
- minutes >= 0 && minutes < 60 &&
- seconds >= 0 && seconds < 60;
-}
-
-hour operator+(hour &t1, hour &t2)
-{
- hour t = t1;
-
- t.seconds += t2.seconds;
- if (t.seconds >= 60)
- {
- t.minutes++;
- t.seconds -= 60;
- }
- t.minutes += t2.minutes;
- if (t.minutes >= 60)
- {
- t.hours++;
- t.minutes -= 60;
- }
- t.hours += t2.hours;
-
- return t;
-}
-
-hour hour::operator+=(hour t)
-{
- seconds += t.seconds;
- if (seconds >= 60)
- {
- minutes++;
- seconds -= 60;
- }
- minutes += t.minutes;
- if (minutes >= 60)
- {
- hours++;
- minutes -= 60;
- }
- hours += t.hours;
-
- return *this;
-}
-
-hour operator-(hour &t1, hour &t2)
-{
- hour t = t1;
-
- t.seconds -= t2.seconds;
- if (t.seconds < 0)
- {
- t.minutes--;
- t.seconds += 60;
- }
-
- t.minutes -= t2.minutes;
- if (t.minutes < 0)
- {
- t.hours--;
- t.minutes += 60;
- }
-
- t.hours -= t2.hours;
-
- return t;
-}
-
-std::ostream& operator<<(std::ostream &s, const hour &t)
-{
- s.width(2);
- s.fill('0');
- s << t.hours << ":";
- s.width(2);
- s.fill('0');
- s << t.minutes << ":";
- s.width(2);
- s.fill('0');
- s << t.seconds;
-
- return s;
-}
-
-std::istream &operator>>(std::istream &s, hour &h)
-{
- char c;
- int H, M, S;
-
- s >> H >> c >> M >> c >> S;
-
- h.hours = H;
- h.minutes = M;
- h.seconds = S;
-
- return s;
-}
-
-String hour::format(const char *fmt)
-{
- String s;
- char buf[40];
- struct tm t;
-
- t.tm_sec = seconds;
- t.tm_min = minutes;
- t.tm_hour = hours;
-
- strftime(buf, 40, fmt, &t);
- s = buf;
-
- return s;
-}
-