forked from dyoo/stardate
/
tng-stardate.rkt
61 lines (45 loc) · 1.69 KB
/
tng-stardate.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#lang racket/base
(require racket/date)
(provide date->stardate)
;; http://trekguide.com/Stardates.htm
;; http://en.memory-alpha.org/wiki/Stardate
;; There are three ways to produce stardates, of which I'm choosing
;; TNG's approach.
;; According to trekguide.com, we get this constant:
(define days-per-year 365.2422)
;; According to trekguide.com, we get this constant:
(define stardate-units-per-year 1000)
(define stardate-units-per-day (/ stardate-units-per-year
days-per-year))
(define stardate-units-per-second
(/ stardate-units-per-day
(* 60 ;; 60 seconds per minutes
60 ;; 60 minutes per hour
24 ;; 24 hours per day
)))
;; Season 1 was in the 41000's
;; Season 2 was in the 42000's
;; ...
;; Season 1 Episode 1, Encounter at Farpoint was on September 28, 1987:
;; http://en.memory-alpha.org/wiki/Encounter_at_Farpoint_(episode)
;; Stardate 41153.7
;; According to:
;;
;; http://trekguide.com/stardateToday.js
;;
;; the stardate 41000 starts at July 15, 1987 00:00:00
(define the-epoch-seconds (find-seconds 00 00 00
15
7 ;; July
1987))
;; date-stardate-string: date -> string
(define (date->stardate a-date)
(stardate-string (date->stardate-number a-date)))
;; date->stardate: date -> number
(define (date->stardate-number a-date)
(define secs (date->seconds a-date))
(define the-stardate (+ 41000 (* stardate-units-per-second (- secs the-epoch-seconds))))
the-stardate)
;; stardate-string: number -> string
(define (stardate-string a-stardate)
(number->string (exact->inexact (/ (floor (* a-stardate 10)) 10))))