+ - Add parameter bool localtime to now() and today()
- String: Boundary checking on index and subtring operators
- Ported class Integer from the Gnu libg++ library.
- date: test parser for invalid dates and syntax errors
- date: Parser for stream input
-- date: Weekday and week number
+- date: Yearday, Weekday and week number
- UTC: Convert to and from time_t, struct tm
-- Add classes: configuration, Integer, amount
+- Add classes: configuration, amount
Returns the number of days in this month, or zero if the month is not
between 1 and 12.
</item>
+<item tag="unsigned YearDay()">
+Calculate the day of the year, starting from January 1st.
+For example, 1 means January 1st and the 22nd of February is 53.
+If the date is not a proper calendar date, return 0.
+</item>
<item tag="unsigned WeekDay()">
Calculate the day of the week, where 1 is Monday and 7 is Sunday.
If the date is not a proper calendar date, return 0.
<heading>Arithmetic</heading>
<description>
-<item tag='hour operator+(hour &t1, hour &t2)'>
+<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)'>
+<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 tag='hour &operator+=(hour t)'>
</item>
-<item tag='hour &operator-=(hour &t)'>
+<item tag='hour &operator-=(hour t)'>
</item>
<item tag='hour &operator++()'>
Add one second.
return d;
}
-date today()
+date today(bool local)
{
long clock;
struct tm *tp;
time(&clock);
- tp = localtime(&clock);
+ if (local)
+ {
+ tp = localtime(&clock);
+ }
+ else
+ {
+ tp = gmtime(&clock);
+ }
return date(tp->tm_mday, tp->tm_mon+1, tp->tm_year+1900);
}
String format(const char *fmt = "%F");
};
-date today();
+date today(bool localtime = true);
class hour
{
return compare(h) >= 0;
}
- friend hour operator+(hour &, hour &);
+ friend hour operator+(hour, hour);
hour operator += (hour h);
hour operator ++ () // prefix
return increase();
}
- friend hour operator-(hour &, hour &);
+ friend hour operator-(hour, hour);
hour operator -= (hour h);
hour operator -- () // prefix
String format(const char *fmt = "%T");
};
-hour now();
+hour now(bool localtime = true);
class UTC
{
String format(const char *fmt = "%F %T");
};
-UTC Now();
+UTC Now(bool localtime = true);
#endif /* AXE_DATE_H */
}
}
-hour now()
+hour now(bool local)
{
long clock;
struct tm *tp;
time(&clock);
- tp = localtime(&clock);
+ if (local)
+ {
+ tp = localtime(&clock);
+ }
+ else
+ {
+ tp = gmtime(&clock);
+ }
return hour(tp->tm_hour, tp->tm_min, tp->tm_sec);
}
seconds >= 0 && seconds < 60;
}
-hour operator+(hour &t1, hour &t2)
+hour operator+(hour t1, hour t2)
{
hour t = t1;
return *this;
}
-hour operator-(hour &t1, hour &t2)
+hour operator-(hour t1, hour t2)
{
hour t = t1;
}
}
-UTC Now()
+UTC Now(bool local)
{
long clock;
struct tm *tp;
hour t;
time(&clock);
- tp = localtime(&clock);
+ if (local)
+ {
+ tp = localtime(&clock);
+ }
+ else
+ {
+ tp = gmtime(&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);
{
date d0;
- if (argc == 2)
+ if (argc >= 2)
{
String system_date(argv[1]);
date d1(system_date);
- d0 = today();
+ if (argc == 3)
+ {
+ // Use UTC
+ d0 = today(false);
+ }
+ else
+ {
+ // Use local time
+ d0 = today();
+ }
+ std::cout << "Date of today() = " << d0 << "\n";
assert(d0 == d1);
}
STATUS=0
TODAY=`date`
+echo "System time = $TODAY"
./date_check_today "$TODAY"
-exit $?
+RESULT=$?
+if [ $STATUS == 0 ]
+then
+ STATUS=${RESULT}
+fi
+
+TODAY=`date -u`
+echo "System time = $TODAY"
+./date_check_today "$TODAY" utc
+RESULT=$?
+if [ $STATUS == 0 ]
+then
+ STATUS=${RESULT}
+fi
+
+exit $STATUS
{
hour d0;
- if (argc == 2)
+ if (argc >= 2)
{
+ hour one_second(0, 0, 1);
String system_date(argv[1]);
hour d1(system_date);
+ if (argc == 3)
+ {
+ // Use UTC
+ d0 = now(false);
+ }
+ else
+ {
+ // Use local time
+ d0 = now();
+ }
+ std::cout << "Hour of now() = " << d0 << "\n";
+ std::cout.flush();
- d0 = now();
- assert(d0 == d1);
+ // Allow for 1 second delay
+ assert(d0 == d1 || d0 == d1 + hour(0, 0, 1));
}
return 0;
STATUS=0
TODAY=`date`
+echo "System time = $TODAY"
./hour_check_now "$TODAY"
-exit $?
+RESULT=$?
+if [ $STATUS == 0 ]
+then
+ STATUS=${RESULT}
+fi
+
+TODAY=`date -u`
+echo "System time = $TODAY"
+./hour_check_now "$TODAY" utc
+RESULT=$?
+if [ $STATUS == 0 ]
+then
+ STATUS=${RESULT}
+fi
+exit $STATUS