EDate, fast, advanced date handling

EDate is a Date unit in plain 32-bit AT&T assembler, and should be fast enough for most applications. The originals were used to process dates in log-compression and log-analysers, which is the reason the procedure were written in assembler (386SX-20!). Of course there are Pascal equivalents, which right now are enabled over assembler because of the Smartlink problems of the compiler.

All date procedures have been checked for problems around 2000. Some old routines didn't consider the year 2000 to be a leapyear. Fixed



Types and constants

The constants used are the days of the week, and the abbreviations of the months. You can change these if you wish, but keep them exactly 3 characters long, since these constants are used by DatiToStr.

TYPE    MonthStr    = ARRAY[1..12] OF String[3];
         DowsStr     = ARRAY[0..6] OF String[3];

CONST
   Months:MonthStr=('Jan','Feb','Mar','Apr','May','Jun','Jul',
                     'Aug','Sep','Oct','Nov','Dec');
   Dows  :DowsStr=('Sun','Mon','Tue','Wed','Thu','Fri','Sat');

The following type is used by MovableCeremony

TYPE    Ceremony =   (AshWednesday,GoodFriday,EasterSunday,
                      EasterMonday,AscensionDay,Whitsunday,
                      WhitsunMonday,CorpusChristiDay,RepentanceDay,
                      FirstAdvent,SecondAdvent,MothersDay);


PROCEDURES

Primitives (very basic routines, used by the other procedures)

The procedures marked with PAS are always Pascal

Normal procedures



LeapYr

Declaration

FUNCTION LeapYr( Year : WORD ) : BOOLEAN;

Description

Returns TRUE when the year is a leapyear. FALSE otherwise.
A leapyear is defined as (Year and 3=0) AND ((Year DIV 100)<>0 OR (Year DIV 400)=0) which will be correct until the year 4000 or so.



DayNr

Declaration

FUNCTION DayNr( Day,Month,Year : WORD) : WORD;

Description

Calculates daynumber, January 1st =1. Februari 1st=32, accounts for leapyears.

Easy way to subtract days within a year, or (DayNr(31,12,Year-1) is the number of days in last year. Use DayNrBack to convert a day number back to a real date

Note: Remember, a DayNr is NOT corresponding to a date. A year and a DayNr is sufficient however

Uses LeapYr



DayNrBack

Declaration

PROCEDURE DayNrBack( Year,DayNr:WORD; VAR Month,Day : WORD);

Description

Converts a daynumber(created with DayNr back to day and month format.

Note: Expires Feb 28th, 2100



DOW

Declaration

FUNCTION DOW( Year,Month,Day:WORD): WORD;

Description

Day of week (Sunday,Monday etc) for a given date. DOW(a Sunday)=0; DOW( a Monday)=1 etc.

Note: Expires Feb 28th, 2100



ToUnix

Declaration

FUNCTION ToUnix(Year, Month, Day, Hrs, Mins, Secs : WORD):CARDINAL;

Description

Calculates unixdate, which is defined as the number of seconds after 1-1-70.

Note:

  1. Expires Feb 28th, 2100
  2. This value is big endian, while some platforms use little endian unix dates. So if you want to compare your calculated unix date with a date retrieved from a filesystem, make sure that the dates are both in the same 'endian' format.

Uses DayNr and (via DayNr) LeapYr

See Also FromUnix



FromUnix

Declaration

PROCEDURE FromUnix(Unix : LONGINT;VAR Year,Month,Day,Hour,Min,Sec:WORD);

Description

Retrieves DD-MM-YY HH:MM:SS back the from unixdate, which is defined as the number of seconds after 1-1-70.

Note:

  1. Expires Feb 28th, 2100
  2. All values are big endian, while some platforms use little endian unix dates. So if you want to compare your calculated unix date with a date retrieved from a filesystem, make sure that the dates are both in the same 'endian' format.

Uses None

See Also ToUnix



WeekNr

Declaration

FUNCTION WeekNr(Year,Mnth,Day:WORD):WORD;

Description

Returns weeknumber (in year) for a certain date. Remember this isn't simply DayNr DIV 7. Jan 1st is not necessarily the first day of week 1.

Note:

  1. Expires Feb 28th, 2100, because DOW does
Uses DOW and DayNr



Easter

Declaration

FUNCTION Easter (Year : WORD) : WORD;

Description

Returns the date of Easter for a given year. 1=March 1st. 32= April 1st etc.

Note:

  1. Expires Feb 28th, 2100, because DOW does
Uses None



DaTiToStr

Declaration

PROCEDURE DaTiToStr(Hour,Min,Sec,Day,Month,Year:WORD; CONST Format:String; VAR DateStr : String);

Description

DaTiToStr is a complex configurable date-formatting routine, and the biggest EDate procedure by far

Basically it copies "Format" to "DateStr", while replacing some switches. Padding character is default (when the procedure starts) 0, but can be changed to space

Replaces withpadding with padchar?
%HHourno
%MMinno
%SSecno
%DDayno
%OMonthno
%YYear MOD 100Yes
%hHour Yes
%mMin Yes
%sSecYes
%dDayYes
%oMonthYes
%YDayYes
%yYear (all 4 characters)no
%J or %j3 character month (Jan,Feb)n/a
%W or %w3 character day of week (Sun,Mon)n/a
%Lsuffix of day (st,nd,rd,th)n/a
%ipadding character to spaceNo output,internal
%Ipadding character to zeroNo output,internal
%UHour MOD 13 (1..12)No
%uHour MOD 13 (1..12)Yes
%AAM or PMn/a
%aam or pmn/a

Format-string to see all options, use this string twice (once prefixed with %i to see padding) to see all options:

'%H:%M:%S %h:%m:%s %U:%m %a %u:%m %A %D-%O-%Y %d-%o-%y, %W %J %D%L, %y';

Note:

  1. Make sure DateStr is big enough
  2. If you don't have day switches in your Format-string, you can specify anything for day

Uses DOW



MovableCeremony

Declaration

PROCEDURE MovableCeremony (MovableCeremon : Ceremony; Year: WORD; VAR Day, Month : WORD);

Description

Returns day and month of a certain movable ceremony in a certain year.

Note:

Uses