BB2 C port
API reference: Blitz libraries in C and the shared code
Loading...
Searching...
No Matches
datelib.c File Reference
#include "blitzlib.h"
#include <dos/dos.h>
#include <proto/dos.h>

Macros

#define __NOLIBBASE__
#define DOS_BASE_NAME   dosbase
#define DAYSINQUADYR   (365 * 4 + 1) /* 4 year cycle */
#define DAYSP1978   (DAYSINQUADYR * 494 + 366 + 365) /* 0/0/0 to 1/1/78 */

Functions

ULONG date_c (struct Library *dosbase)
 SystemDate: the system date as days since 1/1/1978.
ULONG datestr_c (LONG days)
 Date$(days.l): days since 1/1/1978 as a date string.
ULONG calcdays_c (const UBYTE *s)
 NumDays(date$): a date string as days since 1/1/1978.
void dateformat_c (UWORD f)
 DateFormat 0|1: the string format of Date$ and NumDays.
UWORD days_c (void)
 Days: the day of the month of the last Date$.
UWORD months_c (void)
 Months: the month of the last Date$.
UWORD years_c (void)
 Years: the year of the last Date$.
ULONG weekday_c (void)
 WeekDay: the day of the week of the last Date$ (0 = Sunday).
ULONG hours_c (struct Library *dosbase)
 Hours: get the system time, the hour of the day.
ULONG mins_c (void)
 Mins: the minutes of the time of the last Hours call.
ULONG secs_c (void)
 Secs: the seconds of the time of the last Hours call.
static ULONG divu32 (ULONG n, UWORD d, ULONG *rem)
static LONG gregskips (LONG days)
static LONG gregskips_year (UWORD year, int early)
static void put2 (ULONG r)

Variables

static UWORD dateformat
static ULONG totday = DAYSP1978
struct { 
   UWORD   day 
   UWORD   year 
   UWORD   month 
} dym
struct { 
   struct DateStamp   stamp 
   UWORD   months [13] 
} dt

Macro Definition Documentation

◆ __NOLIBBASE__

#define __NOLIBBASE__

◆ DAYSINQUADYR

#define DAYSINQUADYR   (365 * 4 + 1) /* 4 year cycle */

◆ DAYSP1978

#define DAYSP1978   (DAYSINQUADYR * 494 + 366 + 365) /* 0/0/0 to 1/1/78 */

◆ DOS_BASE_NAME

#define DOS_BASE_NAME   dosbase

Function Documentation

◆ calcdays_c()

ULONG calcdays_c ( const UBYTE * s)

NumDays(date$): a date string as days since 1/1/1978.

_calcdays: "dd/mm/yyyy" (or mm/dd/yyyy after DateFormat 1). Day and month: 1 or 2 digits, year: up to 4 (ends at "/", at the end of the string or after 4 characters). "Digits" are not checked: every character counts as char-48. d1 is the field being read, later the year / 4; d2 the character, later the leap days; d3 and d4 hold the first and second field, after the EXG for mm/dd/yyyy the day and the month. Fixed (#122): ADDQ.l #1 / SUBQ.l #1 on the day count (the original's word operations had no carry/borrow: NumDays("31/12/1977") = 65535). Fixed (#123): an empty field (a "/" as its first character) gives 0; the original took the "/" as the value 47. Fixed (#124): a month outside 1-12 gives 0 (the original indexed the month table with it: month 0 read the low word of the tick count of the last DateStamp, 13 the end mark, 14 and up the memory behind). Fixed (#125): the year ends at the end of the string too, an empty year gives 0 (the original read a short year on past the end). Fixed (#1029): a day or month field that ends at the end of the string gives 0 (the original read the 0 byte as a digit and the bytes behind it: NumDays("") or NumDays("1") parsed on into the memory behind the string when a "/" followed). Fixed (#1001): the days of the cycles are corrected by the century leap days the Gregorian calendar does not have (gregskips_year); the original's NumDays("1/3/2100") was one day too high.

Parameters
sd0: the date string
Returns
d0: the days since 1/1/1978; 0 if day or month are not followed by "/", a field is empty or the month is not 1-12

◆ date_c()

ULONG date_c ( struct Library * dosbase)

SystemDate: the system date as days since 1/1/1978.

_date: JSR _DateStamp(a6) into the library's DateStamp.

Parameters
dosbasea6: dos.library
Returns
d0: ds_Days

◆ dateformat_c()

void dateformat_c ( UWORD f)

DateFormat 0|1: the string format of Date$ and NumDays.

_dateformat: MOVE d0,dateformat.

Parameters
fd0.w: 0 = dd/mm/yyyy, otherwise mm/dd/yyyy

◆ datestr_c()

ULONG datestr_c ( LONG days)

Date$(days.l): days since 1/1/1978 as a date string.

_datestr: "dd/mm/yyyy" (or mm/dd/yyyy after DateFormat 1) at a3; keeps day, year and month for Days, Years, Months and the day count for WeekDay. Dates are counted from day 0 = 1/1/0000 in 4 year cycles of 1461 days. d1 holds the 4 year cycles first, d2 the days of the cycles; for mm/dd/yyyy day and month are exchanged (EXG) before the output. Values outside 0..99 per two digits give other characters. Fixed (#120): day 366 of a cycle (1/1 of the year after a leap year, e.g. 1/1/1981) is the first day of the next year; the original showed it as 32/12 of the leap year (CMP #366: BLE instead of BLT). Fixed (#1001): the day count of the cycles is corrected by the century leap days the Gregorian calendar does not have (gregskips): the date is Gregorian (the original showed 29/2/2100 for 1/3/2100). WeekDay keeps the uncorrected count (the weekday follows from the days alone).

Parameters
daysd0: the days since 1/1/1978
Returns
d0: the length of the string, 10

◆ days_c()

UWORD days_c ( void )

Days: the day of the month of the last Date$.

Returns
d0.w: the day

◆ divu32()

ULONG divu32 ( ULONG n,
UWORD d,
ULONG * rem )
static

◆ gregskips()

LONG gregskips ( LONG days)
static

◆ gregskips_year()

LONG gregskips_year ( UWORD year,
int early )
static

◆ hours_c()

ULONG hours_c ( struct Library * dosbase)

Hours: get the system time, the hour of the day.

_hours: JSR _DateStamp(a6) into the library's DateStamp (also for Mins and Secs), then minutes / 60 (DIVU).

Parameters
dosbasea6: dos.library
Returns
d0: the hours in the low word, the minutes in the high word

◆ mins_c()

ULONG mins_c ( void )

Mins: the minutes of the time of the last Hours call.

_mins: of the last DateStamp (no DateStamp of its own; documented, not a bug): minutes / 60, SWAP.

Returns
d0: the minutes in the low word, the hours in the high word

◆ months_c()

UWORD months_c ( void )

Months: the month of the last Date$.

Returns
d0.w: the month

◆ put2()

void put2 ( ULONG r)
static

◆ secs_c()

ULONG secs_c ( void )

Secs: the seconds of the time of the last Hours call.

_secs: of the last DateStamp (no DateStamp of its own): ticks / 50.

Returns
d0: the seconds in the low word, the remaining ticks in the high word

◆ weekday_c()

ULONG weekday_c ( void )

WeekDay: the day of the week of the last Date$ (0 = Sunday).

Fixed (#121): SUBQ.l #2 on the day count; the original's SUBQ.w had no borrow from the high word (the weekday 2 too large when the low word of the count is 0 or 1).

Returns
d0.w: the day of the week, 0..6

◆ years_c()

UWORD years_c ( void )

Years: the year of the last Date$.

Returns
d0.w: the year

Variable Documentation

◆ dateformat

UWORD dateformat
static

◆ day

UWORD day

◆ [struct]

struct { ... } dt
Initial value:
= {
{ 0, 0, 0 },
{ 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 1000 },
}

◆ [struct]

struct { ... } dym

◆ month

UWORD month

◆ months

UWORD months[13]

◆ stamp

struct DateStamp stamp

◆ totday

ULONG totday = DAYSP1978
static

◆ year

UWORD year