Date conversions: std-date->cdate, ...


Synopsis

(std-date->cdate <date>) ; julian DATE to CDATE

(std-cdate->date <cdate>) ; CDATE to julian DATE

(std-date->datlst <date>) ; julian DATE to calendar datelist

(std-cdate->datlst <datlst>) ; CDATE to calendar datelist

(std-datlst->cdate <datlst>) ; calendar datelist to CDATE

(std-datlst->date <date>) ; calendar datelist to julian DATE

Description

These six date conversion functions convert between the three popular date representation formats.

DATE (julian date) may be used for subtraction and addition. It is the number of days (plus fractional seconds, UTC) in the julian calendar. This number is used to do arithmetic calculations like additions and subtraction. Such a number is returned by (getvar "DATE")

CDATE is a very AutoCAD specific readable number of the "calendar date". It's mainly a string representation of the calendar list DATLST, converted to a number. You may not use it for mathematical calculations (add, substract), but it may be used for sorting. The number is also not very accurate, max. to 1 millisecond but after some calculations this will degrade to 10 milliseconds. Such a number is returned by (getvar "CDATE")

DATLST is a a list of numbers in calendar format (yr mo day hh mm sec):
(year ; 4 digits like 1998

month ; [1-12]

day ; [1-31]

hour ; [0-23]

minute ; [0-59]

seconds ; [0-59.9] real number

[dow] ; [0-6] Monday-Sunday

)

Accuracy Problems

The CDATE format needs 14 digits to represent the number including seconds.

yyyymmdd.hhiiss [ttt]

Any 8-byte IEEE floating point number (lisp type REAL) has a theoretical limit of 16 digits, but after the first manipulation it decreases down to 15 significant places. So don't expect accurate representations of milliseconds with CDATE numbers, esp. not after doing some calculations with CDATE numbers.

Examples

;; (setq datlst '(1998 6 19 12 30 17.2253))

(STD-DATLST->CDATE '(1998 6 19 12 30 17.22))
=> 19980619.12301722 (STD-CDATE->DATE 19980619.1230172253)
=> 2450984.5210327 (STD-DATE->DATLST 2450984.521032)
=> (1998 6 19 12 30 17.22) (STD-CDATE->DATLST 19980619.12301722)
=> (1998 6 19 12 30 17.22) (STD-DATE->CDATE 2450984.5210327)
=> 19980619.12301722 (STD-DATLST->DATE '(1998 6 19 12 30 17.225))
=> 2450984.5210327 (std-date->datlst (std-datlst->date '(1998 6 19 14 38 30.0)))
=> (1998 6 19 14 38 30.0)

;; this is little more unprecise, but still okay: +-1/10 ms

(std-cdate->datlst
  (std-datlst->cdate '(1998 6 19 14 38 30.0)))
=> (1998 6 19 14 38 30.0)

Arguments

date: a real number in number of julian days plus fractional seconds

cdate: a real number, representing the readable calendar string

datlst: A list of six numbers: (year month day hh mm ss).

Return Value

On CDATE or DATE a real number, on DATLST a list of six numbers: (year month day hh mm ss)

Side Effects

None.

Module

(std-require 'STDTIME)

Defined in STDTIME