24#if defined(__WIN32__) || defined(__UNIX__)
25 #include <sys/timeb.h>
40#ifdef DEBUG_EARTH_TIME
41 #define LOG(tpr) printf("%s", (astring("earth_time::") + func + ": " + tpr + parser_bits::platform_eol_to_chars()).s())
49 = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
52 = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
55 = { 31, 29, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30 };
59 = { 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30 };
82#define EASY_LT(x, y) \
83 if (x < y) return true; \
84 if (x > y) return false
119 if (uhr > 12) uhr -= 12;
127 if (
hour >= 12) to_return +=
"PM";
128 else to_return +=
"AM";
134#define limit_value(val, max) \
138 val += max * -rolls; \
139 } else if (val >= max) { \
141 val -= max * rolls; \
142 } else { rolls = 0; }
154 to_fix.
hour += rolls;
175 if (!
detach(packed_form, temp))
return false;
177 if (!
detach(packed_form, temp))
return false;
180 if (!
detach(packed_form, temp))
return false;
222 }
else if (day < 1) {
223 day += days_in_prev_month;
235 if (prev_month < 0) prev_month = 11;
271 if (!s2_cast)
throw "error: time_locus::==: unknown type";
279 if (!s2_cast)
throw "error: time_locus::<: unknown type";
281 if (day_in_year::operator < (*s2_cast))
return true;
282 if (!(day_in_year::operator == (*s2_cast)))
return false;
283 if (clock_time::operator < (*s2_cast))
return true;
313 bool leaping = !(to_fix.
year % 4);
314 if (!(to_fix.
year % 100)) leaping =
false;
315 if (!(to_fix.
year % 400)) leaping =
true;
318 to_fix.
year += rolls;
326#define static_class_name() "time_locus"
329 const tm &cal_values)
337 r.
hour = cal_values.tm_hour;
338 r.
minute = cal_values.tm_min;
339 r.
second = cal_values.tm_sec;
342 r.
year = cal_values.tm_year + 1900;
360 LOG(
"failed to gettimeofday!?");
362 time_t currtime_secs = currtime.tv_sec;
364 tm *tz_ptr = localtime_r(&currtime_secs, &result);
365 if (tz_ptr != &result) {
366 LOG(
"failed to get time for local area with localtime_r");
368 return convert(currtime.tv_sec, currtime.tv_usec, result);
377 LOG(
"failed to gettimeofday!?");
379 time_t currtime_secs = currtime.tv_sec;
381 tm *tz_ptr = gmtime_r(&currtime_secs, &result);
382 if (tz_ptr != &result) {
383 LOG(
"failed to get time for local area with gmtime_r");
385 return convert(currtime.tv_sec, currtime.tv_usec, result);
401 case SUNDAY:
return "Sunday";
402 case MONDAY:
return "Monday";
403 case TUESDAY:
return "Tuesday";
406 case FRIDAY:
return "Friday";
408 default:
return "Not_a_day";
415 case JANUARY:
return "January";
417 case MARCH:
return "March";
418 case APRIL:
return "April";
419 case MAY:
return "May";
420 case JUNE:
return "June";
421 case JULY:
return "July";
422 case AUGUST:
return "August";
424 case OCTOBER:
return "October";
427 default:
return "Not_a_month";
436 case MARCH:
return "Mar";
437 case APRIL:
return "Apr";
438 case MAY:
return "May";
439 case JUNE:
return "Jun";
440 case JULY:
return "Jul";
441 case AUGUST:
return "Aug";
446 default:
return "Not";
450#undef static_class_name
a_sprintf is a specialization of astring that provides printf style support.
Provides a dynamically resizable ASCII character string.
const char * s() const
synonym for observe. the 's' stands for "string", if that helps.
A very common template for a dynamic array of bytes.
Base class for object that can tell itself apart from other instances.
A base for objects that can be alphabetically (lexicographically) ordered.
A specific point in time as represented by a 24 hour clock.
bool operator<(const clock_time &to_compare) const
Returns true if this clock_time is earlier than "to_compare".
time_number minute
The number of minutes after the hour.
basis::astring text_form(int how=MERIDIAN) const
Prints the clock_time according to "how".
static time_number normalize(clock_time &to_fix)
@ MERIDIAN
default: uses 12 hour with AM/PM and no seconds.
@ MILITARY
use military 24 hour time.
@ MILLISECONDS
milliseconds are fourth field (after secs).
@ SECONDS
include the number of seconds as a third field.
virtual bool unpack(basis::byte_array &packed_form)
Unpacks a clock time from an array of bytes.
virtual void pack(basis::byte_array &packed_form) const
Packs a clock time into an array of bytes.
bool operator==(const clock_time &to_compare) const
Returns true if this clock_time is equal to "to_compare".
time_number second
The number of seconds after the current minute.
time_number microsecond
Number of microseconds elapsed in this millisecond.
time_number hour
The hour represented in military time: 0 through 23.
time_number millisecond
The number of milliseconds elapsed in this second.
An object that represents a particular day in a year.
bool operator==(const day_in_year &to_compare) const
Returns true if this day is equal to "to_compare".
time_number day_of_year
Numerical day, where January 1st is equal to zero.
@ LONG_MONTH
uses full month name.
@ INCLUDE_DAY
adds the name of the day.
time_number day_in_month
The day number within the month (starting at one).
basis::astring text_form(int how=SHORT_MONTH) const
Prints the day according to "how".
days day_of_week
The day of the week.
virtual void pack(basis::byte_array &packed_form) const
Packs a day object into an array of bytes.
static time_number normalize(day_in_year &to_fix, bool leap_year=false)
normalizes the day as needed and returns the adjustment in years.
months month
The current month.
virtual bool unpack(basis::byte_array &packed_form)
Unpacks a day object from an array of bytes.
bool operator<(const day_in_year &to_compare) const
Returns true if this day is earlier than "to_compare".
An object that represents a particular point in time.
virtual bool less_than(const basis::orderable &s2) const
static time_number normalize(time_locus &to_fix)
Same as text_form() above, but stores into "to_stuff".
@ SHORT_YEAR
use only last two digits of year. ugh–Y2K danger.
@ LONG_YEAR
default: full four digit year (problems in 9999).
virtual void pack(basis::byte_array &packed_form) const
Packs a time_locus object into an array of bytes.
basis::astring text_form_long(int t=clock_time::MERIDIAN, int d=day_in_year::SHORT_MONTH, int y=LONG_YEAR) const
time_number year
The year, using the gregorian calendar.
virtual bool equal_to(const basis::equalizable &s2) const
virtual bool unpack(basis::byte_array &packed_form)
Unpacks a time_locus object from an array of bytes.
#define NULL_POINTER
The value representing a pointer to nothing.
#define limit_value(val, max)
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
The guards collection helps in testing preconditions and reporting errors.
unsigned char abyte
A fairly important unit which is seldom defined...
void attach(byte_array &packed_form, const char *to_attach)
Packs a character string "to_attach" into "packed_form".
bool detach(byte_array &packed_form, astring &to_detach)
Unpacks a character string "to_attach" from "packed_form".
A dynamic container class that holds any kind of object via pointers.
const char * month_name(months to_name)
Returns the name of the month "to_name".
basis::signed_long time_number
time_locus greenwich_now()
returns Greenwich Mean Time (their now).
time_locus now()
returns our current locus in the time continuum.
const char * day_name(days to_name)
Returns the name of the day "to_name".
time_number year_now()
what year is it?
const time_number leap_days_in_month[12]
The number of days in each month in a leap year.
const time_number julian_days_in_month[12]
Number of days in each month based on the julian calendar.
clock_time time_now()
what time is it?
days day_now()
Returns the current local day.
const char * short_month_name(months to_name)
Returns a shorter, constant-length (3 characters) month name.
time_locus convert(time_number seconds, time_number useconds, const tm &cal_values)
day_in_year date_now()
what day on the calendar is it?
const time_number julian_leap_days_in_month[12]
Number of days in each month of a leap year in the julian calendar.
const time_number days_in_month[12]
The number of days in each month in the standard year.
months month_now()
returns the local month.
time_number limit_day_of_month(time_number &day, time_number days_in_month, time_number days_in_prev_month)
Support for unicode builds.