filedialog.cpp \
parsedate.c datelex.c dateyacc.y \
button.cpp edit.cpp scroll.cpp table.cpp geometry.cpp icon.cpp \
- string.cpp regex.cpp integer.cpp date.cpp hour.cpp amount.cpp out.cpp \
+ string.cpp regex.cpp integer.cpp date.cpp hour.cpp utc.cpp \
+ amount.cpp out.cpp \
configuration.cpp
include_HEADERS = table.h menu.h button.h edit.h scroll.h pixmap.h \
filedialog.cpp \
parsedate.c datelex.c dateyacc.y \
button.cpp edit.cpp scroll.cpp table.cpp geometry.cpp icon.cpp \
- string.cpp regex.cpp integer.cpp date.cpp hour.cpp amount.cpp out.cpp \
+ string.cpp regex.cpp integer.cpp date.cpp hour.cpp utc.cpp \
+ amount.cpp out.cpp \
configuration.cpp
libAXE_a_LIBADD =
libAXE_a_OBJECTS = xappl.o xwindow.o font.o menu.o frame.o filedialog.o \
parsedate.o datelex.o dateyacc.o button.o edit.o scroll.o table.o \
-geometry.o icon.o string.o regex.o integer.o date.o hour.o amount.o \
-out.o configuration.o
+geometry.o icon.o string.o regex.o integer.o date.o hour.o utc.o \
+amount.o out.o configuration.o
AR = ar
CXXFLAGS = @CXXFLAGS@
CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
.deps/filedialog.P .deps/font.P .deps/frame.P .deps/geometry.P \
.deps/hour.P .deps/icon.P .deps/integer.P .deps/menu.P .deps/out.P \
.deps/parsedate.P .deps/regex.P .deps/scroll.P .deps/string.P \
-.deps/table.P .deps/xappl.P .deps/xwindow.P
+.deps/table.P .deps/utc.P .deps/xappl.P .deps/xwindow.P
SOURCES = $(libAXE_a_SOURCES)
OBJECTS = $(libAXE_a_OBJECTS)
***********************
** FILE NAME : date.cpp
** SYSTEM NAME : AXE - Andromeda X-windows Encapsulation
-** VERSION NUMBER : $Revision: 1.2 $
+** VERSION NUMBER : $Revision: 1.3 $
**
** DESCRIPTION :
**
/*****************************
$Log: date.cpp,v $
- Revision 1.2 2002-09-02 06:18:20 arjen
+ 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:26 arjen
*****************************/
-static const char *RCSID = "$Id: date.cpp,v 1.2 2002-09-02 06:18:20 arjen Exp $";
+static const char *RCSID = "$Id: date.cpp,v 1.3 2002-09-28 06:58:45 arjen Exp $";
#include <iostream>
#include <time.h>
{
struct parseddate *pd;
- pd = parsedate(s);
- year = pd->year;
- month = pd->month;
- day = pd->day;
+ if (~s == 0)
+ {
+ year = 0;
+ month = 0;
+ day = 0;
+ }
+ else
+ {
+ pd = parsedate(s);
+ year = pd->year;
+ month = pd->month;
+ day = pd->day;
+ }
}
int date::Leap(void)
return *this;
}
+bool date::proper()
+{
+ return year != -1 && year != 0 &&
+ month > 0 && month <= 12 &&
+ day > 0 && day <= DaysInMonth();
+}
+
date operator+(date d1, date d2)
{
d1.add(d2);
return d1.julian() - d2.julian();
}
-ostream &operator<<(ostream &s, const date &d)
+std::ostream &operator<<(std::ostream &s, const date &d)
{
s.width(2);
s.fill('0');
return s;
}
-istream &operator>>(istream &s, date &d)
+std::istream &operator>>(std::istream &s, date &d)
{
char c;
int D, M, Y;
***********************
** FILE NAME : date.h
** SYSTEM NAME : AXE - Andromeda X-windows Encapsulation
-** VERSION NUMBER : $Revision: 1.2 $
+** VERSION NUMBER : $Revision: 1.3 $
**
** DESCRIPTION :
**
/*****************************
$Log: date.h,v $
- Revision 1.2 2002-09-02 06:18:20 arjen
+ 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:26 arjen
*****************************/
-/* static const char *RCSID = "$Id: date.h,v 1.2 2002-09-02 06:18:20 arjen Exp $"; */
+/* static const char *RCSID = "$Id: date.h,v 1.3 2002-09-28 06:58:45 arjen Exp $"; */
#ifndef AXE_DATE_H
#define AXE_DATE_H
date subtract(unsigned long days);
+ friend class UTC;
+
public:
date()
date(String s);
+ bool proper(); // Check wether this is a proper calendar date
+
friend date operator+(date, date);
friend date operator+(unsigned long, date);
friend date operator+(date, unsigned long);
// date operator/(double)
// date& operator/=(double)
- friend ostream& operator<<(ostream&, const date&);
- friend istream& operator>>(istream&, date&);
+ friend std::ostream& operator<<(std::ostream&, const date&);
+ friend std::istream& operator>>(std::istream&, date&);
String format(const char *fmt = "%F");
};
int hours;
short minutes, seconds;
+ friend class UTC;
+
public:
hour()
hour(String s);
+ bool proper(); // Check wether this is a proper clock time
+
friend hour operator+(hour &, hour &);
hour operator += (hour h);
friend hour operator-(hour &, hour &);
- friend ostream& operator<<(ostream &, const hour &);
- friend istream& operator>>(istream &, hour &);
+ friend std::ostream& operator<<(std::ostream &, const hour &);
+ friend std::istream& operator>>(std::istream &, hour &);
String format(const char *fmt = "%T");
};
UTC()
{
+ /* Leave everything to the default hour and date constructors */
+ }
+
+ UTC(const String s);
+ UTC(date dt, hour tm)
+ {
+ d = dt;
+ t = tm;
+ }
+
+ operator date()
+ {
+ return d;
}
+
+ operator hour()
+ {
+ return t;
+ }
+
+ bool proper()
+ {
+ return d.proper() && t.proper();
+ }
+
+ friend std::ostream& operator<<(std::ostream &, const UTC &);
+ friend std::istream& operator>>(std::istream &, UTC &);
+
+ String format(const char *fmt = "%F %T");
};
+UTC Now();
+
#endif /* AXE_DATE_H */
/*$Log: datelex.c,v $
-/*Revision 1.1 2002-07-25 08:01:26 arjen
-/*First checkin, AXE release 0.2
+/*Revision 1.2 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.1 2002/07/25 08:01:26 arjen
+ *First checkin, AXE release 0.2
+ *
* Revision 1.1 84/09/01 15:01:14 wales
* Initial revision
*
/* AJB, Aug 28 1999: Added month names in Dutch */
#ifdef RCSIDENT
-static char rcsident[] = "$Header: /cvsroot/lib/AXE/src/datelex.c,v 1.1 2002-07-25 08:01:26 arjen Exp $";
+static char rcsident[] = "$Header: /cvsroot/lib/AXE/src/datelex.c,v 1.2 2002-09-28 06:58:45 arjen Exp $";
#endif /* RCSIDENT */
#include <stdio.h>
c = buffer; d = yyinbuf;
/* Skip over blanks, tabs, commas, and parentheses. */
- do { *c = *d++; }
- while (*c == ' ' || *c == '\t' || *c == ','
- || *c == '(' || *c == ')');
+ do
+ {
+ *c = *d++;
+ }
+ while (*c != '\0' && (*c == ' ' || *c == '\t' || *c == ','
+ || *c == '(' || *c == ')'));
/* A zero (null) byte signals the end of the input. */
if (*c == 0)
/*$Log: dateyacc.y,v $
-/*Revision 1.1 2002-07-25 08:01:26 arjen
+/*Revision 1.2 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.1 2002/07/25 08:01:26 arjen
/*First checkin, AXE release 0.2
/*
* Revision 1.1 84/09/01 15:01:22 wales
%{
#ifdef RCSIDENT
-static char rcsident[] = "$Header: /cvsroot/lib/AXE/src/dateyacc.y,v 1.1 2002-07-25 08:01:26 arjen Exp $";
-#endif RCSIDENT
+static char rcsident[] = "$Header: /cvsroot/lib/AXE/src/dateyacc.y,v 1.2 2002-09-28 06:58:45 arjen Exp $";
+#endif /*RCSIDENT*/
#include <stdio.h>
#include "parsedate.h"
***********************
** FILE NAME : hour.cpp
** SYSTEM NAME : AXE - Andromeda X-windows Encapsulation
-** VERSION NUMBER : $Revision: 1.2 $
+** VERSION NUMBER : $Revision: 1.3 $
**
** DESCRIPTION :
**
/*****************************
$Log: hour.cpp,v $
- Revision 1.2 2002-09-02 06:18:20 arjen
+ 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
*****************************/
-static const char *RCSID = "$Id: hour.cpp,v 1.2 2002-09-02 06:18:20 arjen Exp $";
+static const char *RCSID = "$Id: hour.cpp,v 1.3 2002-09-28 06:58:45 arjen Exp $";
#include <time.h>
{
struct parseddate *pd;
- pd = parsedate(s);
- hours = pd->hour;
- minutes = pd->minute;
- seconds = pd->second;
+ if (~s == 0)
+ {
+ hours = 0;
+ minutes = 0;
+ seconds = 0;
+ }
+ else
+ {
+ pd = parsedate(s);
+ hours = pd->hour;
+ minutes = pd->minute;
+ seconds = pd->second;
+ }
}
hour now()
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;
return t;
}
-ostream& operator<<(ostream &s, const hour &t)
+std::ostream& operator<<(std::ostream &s, const hour &t)
{
s.width(2);
s.fill('0');
return s;
}
-istream &operator>>(istream &s, hour &h)
+std::istream &operator>>(std::istream &s, hour &h)
{
char c;
int H, M, S;
#include <stdio.h>
#include "parsedate.h"
-static char *RCSID = "$Id: parsedate.c,v 1.1 2002-07-25 08:01:27 arjen Exp $";
+static char *RCSID = "$Id: parsedate.c,v 1.2 2002-09-28 06:58:45 arjen Exp $";
extern int yyparse();
/* Parse the argument string. */
yyinbuf = date;
+
if (yyparse () != 0 && yyans.error == NULL)
yyans.error = yyinbuf;
--- /dev/null
+/**************************************************************************
+** (c) Copyright 1999, Andromeda Technology & Automation
+***************************************************************************
+** MODULE INFORMATION *
+***********************
+** FILE NAME : utc.cpp
+** SYSTEM NAME : AXE - Andromeda X-windows Encapsulation
+** VERSION NUMBER : $Revision: 1.1 $
+**
+** DESCRIPTION :
+**
+** EXPORTED OBJECTS :
+** LOCAL OBJECTS :
+** MODULES USED :
+***************************************************************************
+** ADMINISTRATIVE INFORMATION *
+********************************
+** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
+** CREATION DATE : Sep 16, 2002
+** LAST UPDATE : Sep 16, 2002
+**************************************************************************/
+
+/*****************************
+ $Log: utc.cpp,v $
+ Revision 1.1 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.
+
+
+*****************************/
+
+static const char *RCSID = "$Id: utc.cpp,v 1.1 2002-09-28 06:58:45 arjen Exp $";
+
+#include <time.h>
+
+#include "date.h"
+#include "parsedate.h"
+
+UTC::UTC(String s)
+{
+ struct parseddate *pd;
+
+ if (~s == 0)
+ {
+ t.hours = 0;
+ t.minutes = 0;
+ t.seconds = 0;
+ d.year = 0;
+ d.month = 0;
+ d.day = 0;
+ }
+ else
+ {
+ pd = parsedate(s);
+ t.hours = pd->hour;
+ t.minutes = pd->minute;
+ t.seconds = pd->second;
+ d.year = pd->year;
+ d.month = pd->month;
+ d.day = pd->day;
+ }
+}
+
+UTC Now()
+{
+ long clock;
+ struct tm *tp;
+ date d;
+ hour t;
+
+ time(&clock);
+ tp = localtime(&clock);
+
+ t = hour(tp->tm_hour, tp->tm_min, tp->tm_sec);
+ d = date(tp->tm_mday, tp->tm_mon+1, tp->tm_year+1900);
+
+ return UTC(d, t);
+}
+
+std::ostream& operator<<(std::ostream &s, const UTC &t)
+{
+ s << t.d << " " << t.t;
+
+ return s;
+}
+
+std::istream &operator>>(std::istream &s, UTC &t)
+{
+ s >> t.d >> t.t;
+
+ return s;
+}
+
+String UTC::format(const char *fmt)
+{
+ String s;
+ char buf[80];
+ struct tm ut;
+
+ ut.tm_sec = t.seconds;
+ ut.tm_min = t.minutes;
+ ut.tm_hour = t.hours;
+ ut.tm_year = d.year - 1900;
+ ut.tm_mon = d.month - 1;
+ ut.tm_mday = d.day;
+
+ strftime(buf, 80, fmt, &ut);
+ s = buf;
+
+ return s;
+}
+