</para>
<description>
<item tag='hour()'>
+The default value is 0 hours, 0 minutes and 0 seconds.
</item>
<item tag='hour(long)'>
A number of seconds.
<item tag='hour(int hour, short minute, short second)'>
</item>
<item tag='hour(const String)'>
-
-Format is HH:MM:SS
-
+A time can be written in various formats, such as "1134", meaning
+11 hours and 34 minutes.
+The same time can be written as "11:34" or "11.34".
+A number of seconds can be added in the same manner.
+For example "11:34:25", "113425" or 11.34.25".
</item>
<item tag='operator=(hour &)'>
</item>
-<item tag='operator=(string &)'>
+<item tag='operator=(String &)'>
</item>
<item tag='operator=(long)'>
+Assing a number of seconds.
</item>
</description>
<description>
<item tag='long()'>
-
Converts to a number of seconds.
</item>
<item tag='String()'>
+Converts to a textual representation of the hour in the format "hh:mm:ss".
</item>
</description>
<description>
<item tag='operator==(hour &)'>
</item>
-<item tag='>operator!=(hour &)'>
+<item tag='operator!=(hour &)'>
</item>
<item tag='operator<(hour &)'>
</item>
<heading>Attributes</heading>
<description>
-<item tag='int hour()'>
+<item tag='int Hour()'>
</item>
-<item tag='short minute()'>
+<item tag='short Minute()'>
</item>
-<item tag='short second()'>
+<item tag='short Second()'>
</item>
</description>
<description>
<item tag='hour operator+(hour &t1, hour &t2)'>
+ Add two hour objects, for example:
+ <example>
+ 11:45:30 + 1:20:40 = 13:06:10
+ </example>
</item>
<item tag='hour operator-(hour &t1, hour &t2)'>
+ Subtract two hour objects, for example:
+ <example>
+ 11:05:30 - 1:20:40 = 9:44:50
+ </example>
</item>
<item tag='hour &operator+=(hour &t)'>
</item>
<item tag='hour &operator-=(hour &t)'>
</item>
<item tag='hour &operator++()'>
+Add one second.
</item>
<item tag='hour &operator--()'>
+Subtract one second.
</item>
</description>
lib_LTLIBRARIES = libACL.la
-libACL_la_SOURCES = string.cpp regex.cpp date.cpp parsedate.c dateyacc.y datelex.c
+libACL_la_SOURCES = string.cpp regex.cpp date.cpp parsedate.c dateyacc.y datelex.c \
+ hour.cpp
include_HEADERS = String.h date.h
long date::julian(void)
{
- register long cent;
- register int yr, mn, dy;
+ long cent;
+ int yr, mn, dy;
yr = year;
mn = month;
int operator==(date d)
{
- register int cm;
+ int cm;
cm = this->year - d.year;
cm = (cm != 0) ? cm : this->month - d.month;
int operator!=(date d)
{
- register int cm;
+ int cm;
cm = this->year - d.year;
cm = (cm != 0) ? cm : this->month - d.month;
int operator<=(date d)
{
- register int cm;
+ int cm;
cm = this->year - d.year;
cm = (cm != 0) ? cm : this->month - d.month;
int operator>=(date d)
{
- register int cm;
+ int cm;
cm = this->year - d.year;
cm = (cm != 0) ? cm : this->month - d.month;
int operator>(date d)
{
- register int cm;
+ int cm;
cm = this->year - d.year;
cm = (cm != 0) ? cm : this->month - d.month;
int operator<(date d)
{
- register int cm;
+ int cm;
cm = this->year - d.year;
cm = (cm != 0) ? cm : this->month - d.month;
friend class UTC;
+ int compare(hour h)
+ {
+ int cm;
+
+ cm = this->hours - h.hours;
+ cm = (cm != 0) ? cm : this->minutes - h.minutes;
+ cm = (cm != 0) ? cm : this->seconds - h.seconds;
+
+ return cm;
+ }
+
public:
hour()
bool proper(); // Check wether this is a proper clock time
+ // Attributes.
+
+ short Second()
+ {
+ return seconds;
+ }
+
+ short Minute()
+ {
+ return minutes;
+ }
+
+ int Hour()
+ {
+ return hours;
+ }
+
+ bool operator==(hour h)
+ {
+ return compare(h) == 0;
+ }
+
friend hour operator+(hour &, hour &);
hour operator += (hour h);
friend hour operator-(hour &, hour &);
minutes = pd->minute;
seconds = pd->second;
}
+ if (minutes == -1)
+ {
+ minutes = 0;
+ }
+ if (seconds == -1)
+ {
+ seconds = 0;
+ }
}
hour now()
AM_CPPFLAGS = -I../src
LDADD = ../src/.libs/libACL.la
check_PROGRAMS = string_assign string_basics string_compare string_cat string_substring string_regex \
- date_assign date_parse date_compare date_arithmetic date_attributes date_check_today
+ date_assign date_parse date_compare date_arithmetic date_attributes date_check_today \
+ hour_assign hour_parse
string_assign_SOURCES = string_assign.cpp
string_basics_SOURCES = string_basics.cpp
date_check_today_SOURCES = date_check_today.cpp
date_today : date_check_today
+
+hour_assign_SOURCES = hour_assign.cpp
+hour_parse_SOURCES = hour_parse.cpp
--- /dev/null
+/*******************************************************
+ * Unit test for the hour class
+ *
+ * test contrustor and assignment of hour objects
+ ******************************************************
+ *
+ */
+
+#include "date.h"
+#include <assert.h>
+
+int main()
+{
+ // Default contructor: all zero
+ hour h0;
+
+ std::cout << "The default contructor makes a zero hour: \"" << h0 << "\"\n";
+ assert(h0.Hour() == 0);
+ assert(h0.Minute() == 0);
+ assert(h0.Second() == 0);
+
+ hour h1(15, 20, 45);
+
+ std::cout << "Contructor with hour = 15 minure = 20, and second = 45: \"" << h1 << "\"\n";
+ assert(h1.Hour() == 15);
+ assert(h1.Minute() == 20);
+ assert(h1.Second() == 45);
+
+ hour h2(88, 55, 1000);
+
+ std::cout << "Contructor with hour = 88 minute = 55, and second = 1000: \"" << h2 << "\"\n";
+ assert(h2.Hour() == 88);
+ assert(h2.Minute() == 55);
+ assert(h2.Second() == 1000);
+
+ // The copy constructor is just a bitwise copy
+
+ hour h3(h1);
+
+ std::cout << "Copy contructor from " << h1 << ": \"" << h3 << "\"\n";
+ assert(h3.Hour() == 15);
+ assert(h3.Minute() == 20);
+ assert(h3.Second() == 45);
+
+ // Also assignment is just a bitwise copy
+
+ hour h4;
+
+ h4 = h1;
+ std::cout << "Assigned from " << h1 << ": \"" << h4 << "\"\n";
+ assert(h4.Hour() == 15);
+ assert(h4.Minute() == 20);
+ assert(h4.Second() == 45);
+
+ return 0;
+}
+
--- /dev/null
+The default contructor makes a zero hour: "00:00:00"
+Contructor with hour = 15 minure = 20, and second = 45: "15:20:45"
+Contructor with hour = 88 minute = 55, and second = 1000: "88:55:1000"
+Copy contructor from 15:20:45: "15:20:45"
+Assigned from 15:20:45: "15:20:45"
+PASS hour_assign (exit status: 0)
--- /dev/null
+/*******************************************************
+ * Unit test for the hour class
+ *
+ * test the date parser that converts String to hour
+ ******************************************************
+ *
+ */
+
+#include "date.h"
+#include <assert.h>
+
+int main()
+{
+ hour h0;
+ String the_time;
+
+
+ the_time = "1134";
+ h0 = hour(the_time);
+ std::cout << "String \"" << the_time << "\" converts to: \"" << h0 << "\"\n";
+ std::cout.flush();
+ assert(h0 == hour(11, 34, 0));
+
+ the_time = "11:34";
+ h0 = hour(the_time);
+ std::cout << "String \"" << the_time << "\" converts to: \"" << h0 << "\"\n";
+ assert(h0 == hour(11, 34, 0));
+
+ the_time = "11.34";
+ h0 = hour(the_time);
+ std::cout << "String \"" << the_time << "\" converts to: \"" << h0 << "\"\n";
+ assert(h0 == hour(11, 34, 0));
+
+ the_time = "113427";
+ h0 = hour(the_time);
+ std::cout << "String \"" << the_time << "\" converts to: \"" << h0 << "\"\n";
+ assert(h0 == hour(11, 34, 27));
+
+ the_time = "11:34:27";
+ h0 = hour(the_time);
+ std::cout << "String \"" << the_time << "\" converts to: \"" << h0 << "\"\n";
+ assert(h0 == hour(11, 34, 27));
+
+ the_time = "11.34.27";
+ h0 = hour(the_time);
+ std::cout << "String \"" << the_time << "\" converts to: \"" << h0 << "\"\n";
+ assert(h0 == hour(11, 34, 27));
+
+ // TODO: test for invalid houts and syntax errors
+
+ return 0;
+}
+
--- /dev/null
+String "1134" converts to: "11:34:00"
+String "11:34" converts to: "11:34:00"
+String "11.34" converts to: "11:34:00"
+String "113427" converts to: "11:34:27"
+String "11:34:27" converts to: "11:34:27"
+String "11.34.27" converts to: "11:34:27"
+PASS hour_parse (exit status: 0)