Commit c8fab667 authored by Liam M. Healy's avatar Liam M. Healy
Browse files

Put time-interval into connected system datime-pqd

New connected system datime-pqd loads when date-time and
physical-dimension load, and contains definitions that deal with time
intervals and their conversion to physical quantities with
dimension. This does not load correctly.
parent 012042d2
;; Physical dimension system definition
;; Liam Healy 2012-02-20 10:14:49EST physical-dimension.asd
;; Time-stamp: <2014-01-05 15:05:30EST date-time.asd>
;; Liam Healy
;; Time-stamp: <2014-01-13 23:07:00EST date-time.asd>
;; Copyright 2014 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -27,20 +27,30 @@
:license "GPL v3"
:serial t
:defsystem-depends-on (#:asdf-system-connections)
:depends-on (#:physical-dimension)
:depends-on (#:antik-base)
:components
((:module date-time
:serial t
:components
((:file "iso8601")
((:file "format-output")
(:file "iso8601")
(:file "dtspec")
(:file "time-interval")
(:file "timepoint")
(:file "relative-time")
(:file "read-time")
(:file "formats")
(:file "convert-timescale")
(:file "dtmath")))))
(:file "timepoint")
(:file "read-time")))))
(asdf:defsystem-connection #:datime-pqd
:serial t
:requires (#:date-time #:physical-dimension)
:components
((:module date-time
:components
((:file "time-interval")
(:file "relative-time")
(:file "linear-timepoint")
(:file "dtmath")
(:file "convert-timescale")))))
(asdf:defsystem-connection #:remote-phys-dim-data
:serial t
......@@ -49,3 +59,14 @@
((:module date-time
:components
((:file "eop")))))
;; Tests should be based on parse-time-interval-test,
(asdf:defsystem-connection #:date-time-tests
:serial t
:requires (#:date-time #:physical-dimension #:lisp-unit)
:components
((:module date-time
:components
((:file "time-interval-tests")))))
;; Convert time scales
;; Liam Healy Sat Feb 4 2006 - 18:00
;; Time-stamp: <2014-01-05 18:58:56EST convert-timescale.lisp>
;; Time-stamp: <2014-01-13 23:22:15EST convert-timescale.lisp>
;; Copyright 2011, 2013, 2014 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -252,19 +252,13 @@
(return-from convert-utc-ut1 timespec)))
(unless (or *ut1-utc-table* (read-eop-file)) ; Read EOP file if unread
(no-data))
(when (and
;; If requested time is too far beyond end of actual data, ...
(datime> timespec (antik:+ *ut1-utc-first-estimated* #_4_months))
;; ... there should be some newer data available, so ...
(datime> now (antik:+ *ut1-utc-first-estimated* #_2_months)))
;; Read a new EOP file.
(unless (read-eop-file) (no-data)))
;; Remove staleness check [[id:bc965ced-8e10-405f-becd-08d60f19a520][Split out system]]
;; Do the addition/subtraction
(add-uniform-time
timespec
(antik:* (if to-ut1 +1 -1)
(or (gethash (cl:+ 1/2 (datime-j2000day timespec)) *ut1-utc-table*)
(no-data))))))
(or (gethash (cl:+ 1/2 (datime-j2000day timespec)) *ut1-utc-table*)
(no-data))))))
;;; Round trip doesn't quite always come out even
;;; (convert-utc-ut1 (convert-utc-ut1 #D2005-01-01T00:00:00 t))
;;; #d2004-12-31T23:59:59.999556064605710
......
;; Parameters for nf related to date-time.
;; Liam Healy 2013-03-24 18:24:56EDT format-output.lisp
;; Time-stamp: <2014-01-13 21:47:14EST format-output.lisp>
;; Copyright 2013, 2014 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(in-package :antik)
(define-parameter nf :timepoint-linear
:value nil :type (or symbol list)
:documentation
"Convert timepoints to a linear scale if
specified as a list of epoch time and unit. For example
\computer{'(*midnight-2000* :year)} will present time points as a
real number of calendar years, including fractions, such as
3.3223. If the value is a symbol representing a unit, like :year,
the epoch is taken as 0.")
(define-parameter nf :ignore-day-only
:value nil :type t
:documentation "Datime specified day-only will still format with time.")
(define-parameter nf :date-time-separator
:value nil :type (or null character (member t))
;; Interpretation of nil, t determined by #'iso8601-string.
:documentation
"Character to place between date and time in ISO8601 datime output.
If nil, use a space, if T, use #\T.")
;; Datime formats, compatibility with non-iso8601.
;; Liam Healy Fri Oct 12 2001 - 16:27
;; Time-stamp: <2013-06-02 23:11:06EDT formats.lisp>
;; Time-stamp: <2014-01-13 21:55:47EST formats.lisp>
;; Copyright 2011, 2013 Liam M. Healy
;; Copyright 2011, 2013, 2014 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
;;
;; This program is free software: you can redistribute it and/or modify
......@@ -136,19 +136,3 @@
:scale :utc))
3/2)))
(when (eq format :org) (princ "|"))))
;;;;****************************************************************************
;;;; Date utilities for plotting
;;;;****************************************************************************
(defparameter *midnight-2000* (read-timepoint "2000-01-01T00:00:00"))
(defun linear-timepoint
(timepoint &optional (reference-point *midnight-2000*) (unit :year))
"Compute the timepoint on a linear (number) scale."
(cl:+ (with-nf-options (:system-of-units (make-sysunits (list unit) t))
(pqval (antik:- timepoint reference-point)))
(if (eq unit :year)
(timeparse-part (timeparse reference-point) unit)
0)))
;; ISO 8601:2000(E) time and date representation
;; Liam Healy Sat Aug 7 1999 - 18:07
;; Time-stamp: <2013-03-17 23:15:02EDT iso8601.lisp>
;; Time-stamp: <2014-01-13 22:03:16EST iso8601.lisp>
;; Copyright 2011, 2013 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -272,25 +272,3 @@
;;; It would be nice to have iso8601-string
;;; be able to generate "date only". Maybe this should be split in two,
;;; the same way parsing is?
;;;****************************************************************************
;;; Tests
;;;****************************************************************************
;;;; From before:
;;; Input formats automatically recognized
;;; Output formats should be specified with
;:calendar-date, :ordinal-date,:calendar-week-day, :calendar-week
;:day-of-week, :calendar-month, :calendar-year
;:extended-format, :basic-format
;;; parsed format, with all possible specifications
;;; (:year 1999 :month 8 :day 7 :hour 20 :minute 19 :second 12
;;; :year-of-century 99 :century 19
;;; :day-of-week 6 :week-of-year 33 :day-of-year 155)
;;; :second and :day-of-year may have a fractional component;
;;; the rest are integers.
;; Linear timepoint
;; Liam Healy 2014-01-13 21:52:20EST linear-timepoint.lisp
;; Time-stamp: <2014-01-13 21:53:05EST linear-timepoint.lisp>
;; Copyright 2011, 2013, 2014 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(in-package :antik)
(defparameter *midnight-2000* (read-timepoint "2000-01-01T00:00:00"))
(defun linear-timepoint
(timepoint &optional (reference-point *midnight-2000*) (unit :year))
"Compute the timepoint on a linear (number) scale."
(cl:+ (with-nf-options (:system-of-units (make-sysunits (list unit) t))
(pqval (antik:- timepoint reference-point)))
(if (eq unit :year)
(timeparse-part (timeparse reference-point) unit)
0)))
;; Tests for date-time
;; Liam Healy 2014-01-13 22:00:52EST tests.lisp
;; Time-stamp: <2014-01-13 22:27:07EST time-interval-tests.lisp>
;; Copyright 2011, 2013, 2014 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(in-package :antik)
;;;****************************************************************************
;;; Tests
;;;****************************************************************************
;;; (iso8601-string '(34.54 13 17 4 9 2003))
;;; "2003-09-04T17:13:34.540000"
;;; (iso8601-string '(34.54 13 17 4 9 2003) :tud)
;;; "2003Y9M4DT17H13M34.540000S"
;;; (iso8601-string '(34.54 0 17 0 1 0))
;;; "01-00T17:00:34.540000"
;;; (iso8601-string '(34.54 0 17 0 1 0) :tud)
;;; "1MT17H34.540000S"
;;; (iso8601-string '(34.54 0 17 0 0 0) :tud)
;;; "T17H34.540000S"
;;; (iso8601-string '(34.54 13 17 0 0 0) :tud)
;;; "T17H13M34.540000S"
;;;; From before:
;;; Input formats automatically recognized
;;; Output formats should be specified with
;:calendar-date, :ordinal-date,:calendar-week-day, :calendar-week
;:day-of-week, :calendar-month, :calendar-year
;:extended-format, :basic-format
;;; parsed format, with all possible specifications
;;; (:year 1999 :month 8 :day 7 :hour 20 :minute 19 :second 12
;;; :year-of-century 99 :century 19
;;; :day-of-week 6 :week-of-year 33 :day-of-year 155)
;;; :second and :day-of-year may have a fractional component;
;;; the rest are integers.
(defmacro piti (string)
`(ignore-errors (iso8601-parse-time-interval ,string)))
(lisp-unit:define-test time-interval
(lisp-unit:assert-numerical-equal
#dPT22h
(piti "T22")) ; 22 hours
(lisp-unit:assert-numerical-equal
#dPT22.000s
(piti "T22S")) ; 22 seconds
(lisp-unit:assert-numerical-equal
#dPT14h22m
(piti "T14M22S")) ; 14 minutes, 22 seconds
(lisp-unit:assert-numerical-equal
#dPT6h14m22.000s
(piti "T14:22")) ; 14 hours, 22 minutes
(lisp-unit:assert-numerical-equal
#dPT6h14m22.000s
(piti "T6H14M22S")) ; 6 hours, 14 minutes, 22 seconds
(lisp-unit:assert-numerical-equal
#dPT6h14m22.000s
(piti "T06:14:22")) ; 6 hours, 14 minutes, 22 seconds
(lisp-unit:assert-numerical-equal
#dP16dT6h14m22.000s
(piti "16DT6H14M22S")) ; 16 days, 6 hours, 14 minutes, 22 seconds
(lisp-unit:assert-numerical-equal
#dP8m16dT6h14m22.000s
(piti "8M16DT6H14M22S")) ; 8 months, 16 days, ...
(lisp-unit:assert-numerical-equal
#dP8mT6h14m22.000s
(piti "8MT6H14M22S")) ; 8 months, 0 days, ...
(lisp-unit:assert-numerical-equal
#dP2y8m16dT6h14m22.000s
(piti "2Y8M16DT6H14M22S")) ; 2 years, 8 months, ...
(lisp-unit:assert-numerical-equal
#dP2y8m16dT6h14m22.000s
(piti "0002-08-16T06:14:22"))) ; 2 years, 8 months, ...
;; not permitted yet
;;(piti "--16T06:14:22") ; 16 days, 6 hours, 14 minutes, 22 seconds
;; not permitted yet
;;(piti "P-08-16T06:14:22") ; 8 months, 16 days, ...
;; Time interval parsing and generating.
;; Liam Healy Thu May 2 2002 - 16:34
;; Time-stamp: <2013-03-24 19:01:33EDT time-interval.lisp>
;; Time-stamp: <2014-01-13 22:58:47EST time-interval.lisp>
;; Copyright 2011, 2013 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -24,7 +24,10 @@
(export '(timeparse-time-interval iso8601-time-interval time-interval-timeparse iso8601-parse-time-interval))
;;; Output
;;;;****************************************************************************
;;;; Output
;;;;****************************************************************************
(defun timeparse-time-interval
(time &optional (fractional-seconds-digits *iso8601-fractional-seconds-digits*))
"Convert the time interval to a timeparse."
......@@ -65,7 +68,10 @@
format
fractional-seconds-digits)))
;;; Input
;;;;****************************************************************************
;;;; Input
;;;;****************************************************************************
(defun time-interval-timeparse (timeparse)
"Convert the timeparse to a time interval."
(make-pq
......@@ -81,24 +87,27 @@
"Parse the time interval in ISO8601:2000(E) Section 5.5.4.2.1 format, representation of time-interval by duration only."
(time-interval-timeparse (iso8601-parse string)))
(defun parse-time-interval-test ()
"Test cases for parser."
(macrolet ((piti (string)
`(ignore-errors (iso8601-parse-time-interval ,string))))
(values
(piti "T22") ; 22 hours
(piti "T22S") ; 22 seconds
(piti "T14M22S") ; 14 minutes, 22 seconds
(piti "T14:22") ; 14 hours, 22 minutes
(piti "T6H14M22S") ; 6 hours, 14 minutes, 22 seconds
(piti "T06:14:22") ; 6 hours, 14 minutes, 22 seconds
(piti "16DT6H14M22S") ; 16 days, 6 hours, 14 minutes, 22 seconds
;; not permitted yet
;;(piti "--16T06:14:22") ; 16 days, 6 hours, 14 minutes, 22 seconds
(piti "8M16DT6H14M22S") ; 8 months, 16 days, ...
(piti "8MT6H14M22S") ; 8 months, 0 days, ...
;; not permitted yet
;;(piti "P-08-16T06:14:22") ; 8 months, 16 days, ...
(piti "2Y8M16DT6H14M22S") ; 2 years, 8 months, ...
(piti "0002-08-16T06:14:22")))) ; 2 years, 8 months, ...
;;;;****************************************************************************
;;;; Format using nf
;;;;****************************************************************************
(define-parameter nf :time
:value :tud :type (or null (member :tud :alternate))
:documentation
"How to format time intervals:
:tud = ISO8601 time-unit designator (like P10H7M23.726979085813582S)
:alternative = ISO8601 alternate (like P10:07:23.726979085813582)
nil = with the unit for time given by :system-of-units
(like #_36443.72697908581_S.")
(defun time-interval-format (pq)
"Format the time interval ISO8601."
(when (and (nf-option :time)
(not (grid:gridp (pq-magnitude pq)))
(check-dimension pq 'time nil nil))
(unless texstyle (when (nf-readably) (princ "#d" stream)))
(princn (iso8601-time-interval pq (nf-option :time))
stream)))
;;; Set hook for method (nf physical-quantity) to format time intervals using ISO8601 if the option is selected.
(setf *time-interval-format-function* #'time-interval-format)
;; Physical dimension system definition
;; Liam Healy 2012-02-20 10:14:49EST physical-dimension.asd
;; Time-stamp: <2014-01-07 23:27:18EST physical-dimension.asd>
;; Time-stamp: <2014-01-13 22:55:52EST physical-dimension.asd>
;; Copyright 2012, 2013, 2014 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -27,7 +27,7 @@
:license "GPL v3"
:serial t
:defsystem-depends-on (#:asdf-system-connections)
:depends-on (#:grid #:split-sequence)
:depends-on (#:grid #:split-sequence :fare-utils)
:components
((:module init
:serial t
......@@ -48,18 +48,6 @@
(:file "angle")
(:file "angle-component")
(:file "state")))
(:module date-time
:serial t
:components
((:file "iso8601")
(:file "dtspec")
(:file "time-interval")
(:file "timepoint")
(:file "relative-time")
(:file "read-time")
(:file "formats")
(:file "convert-timescale")
(:file "dtmath")))
(:module cartesian
:serial t
:components
......
;; Parameters for nf related to physical quanitites.
;; Liam Healy 2013-03-24 18:24:56EDT format-output.lisp
;; Time-stamp: <2013-05-26 18:37:51EDT format-output.lisp>
;; Time-stamp: <2014-01-13 22:57:23EST format-output.lisp>
;; Copyright 2013 Liam M. Healy
;; Copyright 2013, 2014 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
;;
;; This program is free software: you can redistribute it and/or modify
......@@ -25,38 +25,9 @@
:documentation
"The system of units used for output. If NIL, don't print units. Standard systems of units may be altered with #'make-sysunits.")
(define-parameter nf :timepoint-linear
:value nil :type (or symbol list)
:documentation
"Convert timepoints to a linear scale if
specified as a list of epoch time and unit. For example
\computer{'(*midnight-2000* :year)} will present time points as a
real number of calendar years, including fractions, such as
3.3223. If the value is a symbol representing a unit, like :year,
the epoch is taken as 0.")
(define-parameter nf :ignore-day-only
:value nil :type t
:documentation "Datime specified day-only will still format with time.")
(define-parameter nf :date-time-separator
:value nil :type (or null character (member t))
;; Interpretation of nil, t determined by #'iso8601-string.
:documentation
"Character to place between date and time in ISO8601 datime output.
If nil, use a space, if T, use #\T.")
(define-parameter nf :degrees
:value :decimal :type (member :decimal :dms)
:documentation
"Whether to format degrees as decimal degees or degrees, minutes, seconds.")
(define-parameter nf :time
:value :tud :type (or null (member :tud :alternate))
:documentation
"How to format time intervals:
:tud = ISO8601 time-unit designator (like P10H7M23.726979085813582S)
:alternative = ISO8601 alternate (like P10:07:23.726979085813582)
nil = with the unit for time given by :system-of-units
(like #_36443.72697908581_S.")
;; Objects that represent physical measurements.
;; Liam Healy Wed Mar 6 2002 - 09:04
;; Time-stamp: <2013-11-23 09:50:54EST physical-quantities.lisp>
;; Time-stamp: <2014-01-13 22:55:09EST physical-quantities.lisp>
;; Copyright 2011, 2012, 2013 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -150,6 +150,8 @@
;;;; Extracting values and printing
;;;;****************************************************************************
(defvar *time-interval-format-function* #'fare-utils:nilf)
(defmethod nf
((pq physical-quantity) &optional (stream *standard-output*))
(if (and (grid:gridp pq)
......@@ -158,15 +160,9 @@
;; dimensions, call the T method of nf, so that it will call
;; nf-grid.
(call-next-method)
(multiple-value-bind (val units)
(pqval pq)
(if (and (nf-option :time)
(not (grid:gridp (pq-magnitude pq)))
(check-dimension pq 'time nil nil))
(progn
(unless texstyle (when (nf-readably) (princ "#d" stream)))
(princn (iso8601-time-interval pq (nf-option :time))
stream))
(or (funcall *time-interval-format-function* pq)
(multiple-value-bind (val units)
(pqval pq)
(if (nf-option :system-of-units)
(format-units val units (scalar-dimension pq) stream)
(nf val stream)))))) ; format the number only
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment