time.c File Reference

Classes and functions dealing with the semantics of time. More...

#include <cassert>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cerrno>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include "hash.h"
#include "id.h"
#include "data.h"
#include "trace.h"
#include "kbase.h"
#include "dictionary.h"
#include "util.h"
#include "ondisk.h"
#include "calendar.h"
#include "gabbie.h"
#include "time.h"

Classes

struct  TimeContext

Functions

int DayOfWeek (int day)
int IdToDayOfWeek (Id dayId)
double StrToDate (char *s)
 Convert string with date in format YYYYMMDDHHMMSS to date in double.
int IsLeapYear (int year)
double EdtToTime (ExpandedDateTime *p)
 Convert ExpandedDateTime struct to date+time represented as a double.
void TimeToEdt (ExpandedDateTime *p, double time)
 Expand date+time represented as a double to ExandedDateTime struct.
double GetCurrentTime ()
 Returns a double representing the current date+time.
void PrintTime (double d, int full)
 Print time.
void TestTime (char *timeStr)
 For test purposes, force current time to timeStr in YYYYMMDDHHMMSS format.
char * HourToText (int hour, int minute)
DataTimeAct (Context *p)

Variables

int sMonthDayTotal []
char * sMonthTab []
char * sDowTab []


Detailed Description

Classes and functions dealing with the semantics of time.

Author:
Bryan Jacobson, 2006.

Function Documentation

int DayOfWeek int  day  ) 
 

Calculate day-of-week, where Sunday==0, Monday==1 .. Saturday=6 The day parameter is the integer part of a time (in double format).

double EdtToTime ExpandedDateTime p  ) 
 

Convert ExpandedDateTime struct to date+time represented as a double.

Convert ExpandedDateTime struct to date+time represented as a double. See TimeToEdt() for explanation of date+time as a double. The value in p->mLeapFlag is ignored. Values are not checked to confirm they are in their appropriate ranges. TODO: This should be a method of EDT.

double GetCurrentTime  ) 
 

Returns a double representing the current date+time.

Returns a double representing the current date+time. Note: If a value is specified by TestTime() it will overide local current time.

char* HourToText int  hour,
int  minute
 

int IdToDayOfWeek Id  dayId  ) 
 

Convert gIdSunday=0, gIdMonday=1 .. gIdSaturday=6 Return -1 if Id doesn not match gIdSunday .. gIdSaturday

int IsLeapYear int  year  ) 
 

void PrintTime double  d,
int  full
 

Print time.

double StrToDate char *  s  ) 
 

Convert string with date in format YYYYMMDDHHMMSS to date in double.

void TestTime char *  timeStr  ) 
 

For test purposes, force current time to timeStr in YYYYMMDDHHMMSS format.

For test purposes, force current time to time specificied by timeStr in YYYYMMDDHHMMSS format. This is accomplished by forcing GetCurrentTime() to return the time specified rather than the current time.

Data* TimeAct Context p  ) 
 

void TimeToEdt ExpandedDateTime p,
double  time
 

Expand date+time represented as a double to ExandedDateTime struct.

Expand date+time represented as a double to ExpandedDateTime struct. When date+time is represented as a double, the integer portion (which can be negative) represents the number of days since Jan 1, 1900. The fractional part of the double represents the fraction of the 24 hour day that has elapsed. Example: 0.5 == 12:00 noon, 0.25 = 6:00 AM.

Note: This conversion takes into account the fairly complicated rule for leap days (leap year if divisible by 4, but not 100, unless also divisible by 400). So 2000 is a leap year, while 1900 and 1800 were not.

Limitations:

  • No accomodation is made for leap seconds.
  • Currently, no accomodation is made for timezones.
  • This leap year implementation represents a Gregorian calendar. Note that Great Brittain was on the Julian calendar until September 1752, when Great Brittain dropped 11 days to align with the Gregorian calendar. The Gregorian calendar was introduced in Italy, Poland, Portugal and Spain in 1582, by dropping 10 days in October. Prior to 1582, the Julian calendar was in use. No accomodation is made for Julian calendar dates. The only negative consequence of this is that calculcation of number of *days* between events can be off by a few days if one of the dates is Julian (Battle of Hastings Oct 14, 1066), and the other is date is Gregorian (first Moon landing July 20, 1969).

TODO: This should be a method of EDT.


Variable Documentation

char* sDowTab[]
 

Initial value:

 { "Sunday", "Monday", "Tuesday", "Wednesday",
  "Thursday", "Friday", "Saturday" }

int sMonthDayTotal[]
 

Initial value:

 { 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273,
                         304, 334 }

char* sMonthTab[]
 

Initial value:

 { "Unused", "January", "February", "March", "April",
  "May", "June", "July", "August", "September", "October", "November",
  "December" }


Generated on Sun Oct 8 09:32:10 2006 for gabbie by  doxygen 1.4.6