Skip to content

Commit a9946b7

Browse files
author
Dave Gurnell
committed
Times rendered using unlib/date.ss; added .externals, build.ss and autoplanet.ss.
1 parent 64fef96 commit a9946b7

18 files changed

+182
-71
lines changed

.externals

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[.]
2+
scm = svn
3+
4+
[planetdev/unlib]
5+
path = planetdev/unlib
6+
repository = http://svn.untyped.com/unlib/trunk/src
7+
scm = svn

autoplanet.ss

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#lang scheme
2+
3+
(require scheme/runtime-path
4+
(planet untyped/autoplanet:1))
5+
6+
(define-runtime-path dev-path
7+
"planetdev")
8+
9+
(remove-hard-links)
10+
11+
(install-local "owner" "unlib.plt" 3 99 (build-path dev-path "unlib"))

base.ss

+3-5
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@
88
(define-library-aliases javascript (planet dherman/javascript:9:2) #:provide)
99
(define-library-aliases pprint (planet dherman/pprint:4) #:provide)
1010
(define-library-aliases schemeunit (planet schematics/schemeunit:3) #:provide)
11-
(define-library-aliases spgsql (planet schematics/spgsql:2) #:provide)
12-
(define-library-aliases unlib (planet untyped/unlib:3:13) #:provide)
11+
(define-library-aliases unlib (planet untyped/unlib:3) #:provide)
1312

1413
(require net/url
1514
scheme/contract
1615
scheme/match
17-
srfi/19
1816
srfi/26
19-
(except-in (unlib-in debug exn time) time-utc->string time-tai->string))
17+
(unlib-in debug exn date))
2018

2119
; Configuration --------------------------------
2220

@@ -52,7 +50,7 @@
5250
scheme/contract
5351
scheme/match
5452
srfi/26)
55-
(unlib-out debug exn time))
53+
(unlib-out debug exn date))
5654

5755
(provide/contract
5856
[quote-case-restriction (parameter/c (or/c 'lower 'upper))]

build.ss

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env mzscheme -q
2+
#lang scheme
3+
4+
(require scheme/runtime-path
5+
scheme/system)
6+
7+
; Configuration ----------------------------------
8+
9+
; string
10+
(define plt-version "4.2.1.5")
11+
12+
; path
13+
(define-runtime-path planet-path "planet")
14+
15+
; Tasks ------------------------------------------
16+
17+
(define (env)
18+
(putenv "PLTVERSION" plt-version)
19+
(putenv "PLTPLANETDIR" (path->string planet-path)))
20+
21+
(define (autoplanet)
22+
(env)
23+
(system "mzscheme autoplanet.ss"))
24+
25+
(define (envvars)
26+
(autoplanet)
27+
(let ([path (make-temporary-file "mzscheme-envvars-~a.sh")])
28+
(with-output-to-file path
29+
(lambda ()
30+
(printf #<<ENDSCRIPT
31+
export PLTVERSION=~a
32+
export PLTPLANETDIR="~a"
33+
34+
ENDSCRIPT
35+
plt-version
36+
(path->string planet-path)))
37+
#:exists 'replace)
38+
(display (path->string path))))
39+
40+
(define (compile)
41+
(autoplanet)
42+
(system "mzc -v main.ss"))
43+
44+
(define (test-compile)
45+
(autoplanet)
46+
(system "mzc -v run-tests.ss"))
47+
48+
(define (test)
49+
(test-compile)
50+
(system "mzscheme run-tests.ss"))
51+
52+
(match (vector-ref (current-command-line-arguments) 0)
53+
["envvars" (envvars)]
54+
["compile" (compile)]
55+
["test-compile" (test-compile)]
56+
["test" (test)])

csv/render-test.ss

+18-8
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22

33
(require "../test-base.ss")
44

5-
(require srfi/19
6-
"render.ss"
5+
(require "render.ss"
76
"struct.ss")
87

98
; Helpers ----------------------------------------
109

11-
(define utc-date (date->time-utc (make-date 0 56 34 12 01 02 2003 0)))
12-
(define tai-date (date->time-tai (make-date 0 56 34 12 01 02 2003 0)))
10+
; GMT:
11+
(define utc-winter-date (date->time-utc (make-date 0 56 34 12 01 02 2003)))
12+
(define tai-winter-date (date->time-tai (make-date 0 56 34 12 01 02 2003)))
13+
14+
; BST:
15+
(define utc-summer-date (date->time-utc (make-date 0 56 34 12 01 07 2003)))
16+
(define tai-summer-date (date->time-tai (make-date 0 56 34 12 01 07 2003)))
1317

1418
; Tests ------------------------------------------
1519

@@ -28,10 +32,16 @@
2832
(check-equal? (csv->string (cell #"bytes")) "\"bytes\"")
2933
(check-equal? (csv->string (cell (string->url "/u/r/l"))) "\"/u/r/l\"")
3034
(check-equal? (csv->string (cell "\"string\" with quotes")) "\"\"\"string\"\" with quotes\"")
31-
; These checks give different results depending on your time zone and DST settings:
32-
(let ([hour (+ 12 (floor (/ (current-time-zone-offset) (* 60 60))))])
33-
(check-equal? (csv->string (cell utc-date)) (format "\"2003-02-01 ~a:34:56\"" hour))
34-
(check-equal? (csv->string (cell tai-date)) (format "\"2003-02-01 ~a:34:56\"" hour))))
35+
; Times are rendered in the correct immediate time zone:
36+
(check-equal? (csv->string (cell utc-winter-date)) "\"2003-02-01 12:34:56\"" "time-utc (GMT)")
37+
(check-equal? (csv->string (cell tai-winter-date)) "\"2003-02-01 12:34:56\"" "time-utc (GMT)")
38+
(check-equal? (csv->string (cell utc-summer-date)) "\"2003-07-01 12:34:56\"" "time-utc (BST)")
39+
(check-equal? (csv->string (cell tai-summer-date)) "\"2003-07-01 12:34:56\"" "time-utc (BST)")
40+
(parameterize ([current-tz "PST8PDT"])
41+
(check-equal? (csv->string (cell utc-winter-date)) "\"2003-02-01 04:34:56\"" "time-utc (PST)")
42+
(check-equal? (csv->string (cell tai-winter-date)) "\"2003-02-01 04:34:56\"" "time-utc (PST)")
43+
(check-equal? (csv->string (cell utc-summer-date)) "\"2003-07-01 04:34:56\"" "time-utc (PDT)")
44+
(check-equal? (csv->string (cell tai-summer-date)) "\"2003-07-01 04:34:56\"" "time-utc (PDT)")))
3545

3646
(test-equal? "single row"
3747
(csv->string (row (cell 1) (cell "2") (cell 3)))

info.ss

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
(define release-notes
99
'((p "Changes and additions:")
10-
(ul (li "nothing as yet..."))))
10+
(ul (li "time rendering is based off of unlib/date.ss: times are rendered in daylight saving time for the current locale (as set by current-tz from bzlib/date-tz.plt)."))))
1111

1212
(define primary-file "mirrors.ss")
1313

@@ -21,6 +21,10 @@
2121

2222
(define repositories '("4.x"))
2323

24-
(define compile-omit-files '("sql"))
24+
(define compile-omit-files
25+
'("autoplanet.ss"
26+
"build.ss"
27+
"planet"
28+
"planetdev"))
2529

2630

javascript/lang.ss

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#lang scheme/base
1+
#lang scheme
22

3-
(require (only-in srfi/1 drop-right take-right)
4-
"../base.ss"
5-
"op-util.ss"
3+
(require "../base.ss")
4+
5+
(require "op-util.ss"
66
"quote.ss"
77
"struct.ss")
88

javascript/op-util-internal.ss

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
1-
#lang scheme/base
1+
#lang scheme
22

3-
(require "../base.ss"
4-
(for-template scheme/base
5-
"../base.ss"))
3+
(require "../base.ss")
64

75
(require (only-in srfi/1 append-map iota make-list)
86
srfi/26
97
(unlib-in syntax)
108
"op.ss"
11-
(for-template (only-in srfi/1 drop-right take-right)
9+
(for-template (except-in scheme/base
10+
make-date
11+
date?
12+
date-year
13+
date-month
14+
date-day
15+
date-week-day
16+
date-hour
17+
date-minute
18+
date-second)
19+
scheme/list
1220
(unlib-in syntax)
21+
"../base.ss"
1322
"struct.ss"
1423
"quote.ss"))
1524

javascript/op-util.ss

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#lang scheme/base
1+
#lang scheme
22

3-
(require (for-syntax scheme/base
4-
"op-util-internal.ss"
3+
(require "../base.ss")
4+
5+
(require (for-syntax "op-util-internal.ss"
56
"op.ss")
6-
scheme/contract
77
"struct.ss")
88

99
; Syntax -----------------------------------------

javascript/sexp/module.ss

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#lang scheme/base
22

3+
(require "../../base.ss")
4+
35
(require (for-syntax scheme/base
4-
(planet untyped/unlib:3/debug)
5-
(planet untyped/unlib:3/syntax))
6+
(unlib-in debug syntax))
67
"../javascript.ss"
78
"../javascript-registry.ss")
89

javascript/syntax-test.ss

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
#lang scheme/base
1+
#lang scheme
22

3-
(require (for-syntax scheme/base
4-
"../test-base.ss"
3+
(require (for-syntax "../test-base.ss"
54
"syntax-internal.ss")
6-
(prefix-in scheme: scheme/pretty)
75
srfi/13
86
"../test-base.ss"
97
"expander.ss"

javascript/syntax.ss

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
#lang scheme/base
1+
#lang scheme
22

33
(require "../base.ss")
44

5-
(require (for-syntax scheme/base
6-
"../base.ss"
5+
(require (for-syntax "../base.ss"
76
"syntax-internal.ss"))
87

98
; Lowercase --------------------------------------

plain/render.ss

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
(require "../base.ss")
44

5-
(require srfi/19)
6-
75
; quotable-value [boolean] -> string
86
(define (quotable-value->string val [pretty? #t])
97
(cond [(string? val) val]

scribblings/mirrors.scrbl

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#lang scribble/doc
22

3-
@(require (file "base.ss"))
3+
@(require "base.ss")
4+
5+
@(require (for-label srfi/19
6+
(only-in (planet bzlib/date-tz)
7+
current-tz
8+
tz-names)))
49

510
@title{@bold{Mirrors}: Programmatic Assembly of XML, Javascript and CSV Data}
611

@@ -10,13 +15,23 @@ Dave Gurnell
1015

1116
@italic{Mirrors} is a collection of macro-based syntaxes for rendering content for web applications. The library currently supports the rendering of XML (including browser-compatible XHTML), Javascript 1.5 and CSV data. Future support is planned for CSS level 3.
1217

18+
@bold{Important: changes to time rendering in Mirrors 2.4:}
19+
20+
Mirrors 2.4 makes a subtle change in the way SRFI 19 times are rendered in XML and CSV output. The old behaviour was to use SRFI 19's @scheme[time-utc->date] and @scheme[time-tai->date] functions to convert the time to a @scheme[date], and then use @scheme[date->string] to render the date as a string.
21+
22+
The disadvantage of that approach is the original approach is that it always creates dates according to the @italic{current} time zone offset. This means that, for example, @scheme[time-utc]@schemeidfont{s} representing timestamps in the middle of winter, can be rendered using daylight saving time if your application is running in the middle of Summer.
23+
24+
Mirrors' new approach is to use the wrapped time/date handling functions from @scheme[(planet untyped/unlib/date)]. This module, which is essentially a wrapper for @scheme[(planet bzlib/date-tz)], converts times to dates using the immediate time zone for the current @italic{locale}. Winter times will always be rendered using a winter time zone offset, and summer times will always be rendered using a summer time zone offset.
25+
26+
The default locale is @scheme["GB"] but it can be overridden using the @scheme[current-tz] parameter. A complete list of locales can be obtained using the @scheme[tz-names] procedure. Both of these forms are provided by @scheme[(planet bzlib/date-tz)] and reprovided by @scheme[(planet untyped/unlib/date)].
27+
1328
@include-section{xml.scrbl}
1429
@include-section{javascript.scrbl}
1530
@include-section{csv.scrbl}
1631
@include-section{plain.scrbl}
1732

1833
@section{Acknowledgements}
1934

20-
Many thanks to Dave Herman for Javascript.plt and PPrint.plt, both of which are used extensively in Mirrors.
35+
Many thanks to Dave Herman for @scheme[(planet dherman/javascript)] and @scheme[(planet dherman/pprint)], both of which are used extensively in Mirrors.
2136

2237
Thanks also to the following for their contributions: David Brooks, Matt Jadud, Fausto LS, Jay McCarthy, Karsten Patzwaldt and Noel Welsh.

xml/render-test.ss

+27-18
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
#lang scheme/base
22

3-
(require (for-syntax scheme/base)
4-
"../test-base.ss")
3+
(require "../test-base.ss")
54

6-
(require (for-syntax "syntax-prerender.ss"
5+
(require (for-syntax scheme/base
6+
"syntax-prerender.ss"
77
"syntax-expand.ss")
8-
srfi/19
9-
(unlib-in time)
10-
"../test-base.ss"
118
"../javascript/javascript.ss"
129
"expander.ss"
1310
"render.ss"
@@ -20,8 +17,14 @@
2017
(define url2 (string->url "http://www.example.com?a=b&c=d"))
2118
(define text "Text")
2219
(define sym 'symbol)
23-
(define utc-date (date->time-utc (make-date 0 56 34 12 01 02 2003 0)))
24-
(define tai-date (date->time-tai (make-date 0 56 34 12 01 02 2003 0)))
20+
21+
; GMT:
22+
(define utc-winter-date (date->time-utc (make-date 0 56 34 12 01 02 2003)))
23+
(define tai-winter-date (date->time-tai (make-date 0 56 34 12 01 02 2003)))
24+
25+
; BST:
26+
(define utc-summer-date (date->time-utc (make-date 0 56 34 12 01 07 2003)))
27+
(define tai-summer-date (date->time-tai (make-date 0 56 34 12 01 07 2003)))
2528

2629
(define-xml-syntax (!wrap expr1 expr2)
2730
(xml expr1 expr2 expr1))
@@ -44,16 +47,22 @@
4447
(test-suite "render.ss"
4548

4649
(test-case "literals"
47-
(check-xml #t "yes" "true")
48-
(check-xml #f "" "false")
49-
(check-xml 12345 "12345" "number")
50-
(check-xml "blah &\"<>" "blah &amp;&quot;&lt;&gt;" "string")
51-
(check-xml 'blah\&\"<> "blah&amp;&quot;&lt;&gt;" "symbol")
52-
(check-xml #"blah &\"<>" "blah &amp;&quot;&lt;&gt;" "bytes")
53-
; These checks give different results depending on your time zone and DST settings:
54-
(let ([hour (+ 12 (floor (/ (current-time-zone-offset) (* 60 60))))])
55-
(check-xml ,utc-date (format "2003-02-01 ~a:34:56" hour) "time-utc")
56-
(check-xml ,tai-date (format "2003-02-01 ~a:34:56" hour) "time-tai")))
50+
(check-xml #t "yes" "true")
51+
(check-xml #f "" "false")
52+
(check-xml 12345 "12345" "number")
53+
(check-xml "blah &\"<>" "blah &amp;&quot;&lt;&gt;" "string")
54+
(check-xml 'blah\&\"<> "blah&amp;&quot;&lt;&gt;" "symbol")
55+
(check-xml #"blah &\"<>" "blah &amp;&quot;&lt;&gt;" "bytes")
56+
; Times are rendered in the correct immediate time zone:
57+
(check-xml ,utc-winter-date "2003-02-01 12:34:56" "time-utc (GMT)")
58+
(check-xml ,tai-winter-date "2003-02-01 12:34:56" "time-tai (GMT)")
59+
(check-xml ,utc-summer-date "2003-07-01 12:34:56" "time-utc (BST)")
60+
(check-xml ,tai-summer-date "2003-07-01 12:34:56" "time-tai (BST)")
61+
(parameterize ([current-tz "PST8PDT"])
62+
(check-xml ,utc-winter-date "2003-02-01 04:34:56" "time-utc (PST)")
63+
(check-xml ,tai-winter-date "2003-02-01 04:34:56" "time-tai (PST)")
64+
(check-xml ,utc-summer-date "2003-07-01 04:34:56" "time-utc (PDT)")
65+
(check-xml ,tai-summer-date "2003-07-01 04:34:56" "time-tai (PDT)")))
5766

5867
(test-case "raw"
5968
(check-xml (!raw "&\"<>") "&\"<>" "string")

xml/syntax-expand-test.ss

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
(require "../test-base.ss")
44

5-
(require srfi/19
6-
"struct.ss"
5+
(require "struct.ss"
76
"syntax.ss"
87
"syntax-expand.ss")
98

@@ -12,8 +11,8 @@
1211
(define test-url "http://www.example.com")
1312
(define text "Text")
1413
(define sym 'symbol)
15-
(define utc-date (date->time-utc (make-date 0 56 34 12 01 02 2003 0)))
16-
(define tai-date (date->time-tai (make-date 0 56 34 12 01 02 2003 0)))
14+
(define utc-date (date->time-utc (make-date 0 56 34 12 01 02 2003)))
15+
(define tai-date (date->time-tai (make-date 0 56 34 12 01 02 2003)))
1716

1817
; Tests ------------------------------------------
1918

0 commit comments

Comments
 (0)