marsdate 1.0.9 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/marsdate +86 -0
- data/bin/marsdate-version +5 -0
- data/bin/meh.html +2941 -0
- data/lib/marsdate.rb +54 -37
- data/test/spec/marsdate_spec.rb +382 -0
- data/test/test.rb +377 -0
- metadata +8 -3
data/test/test.rb
ADDED
@@ -0,0 +1,377 @@
|
|
1
|
+
require './lib/marsdate'
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'minitest/autorun'
|
5
|
+
require 'shoulda'
|
6
|
+
require 'pp'
|
7
|
+
|
8
|
+
class MarsDateTest < MiniTest::Unit::TestCase
|
9
|
+
|
10
|
+
def my_assert(expr)
|
11
|
+
if !expr && block_given?
|
12
|
+
puts "\n--- DEBUG: "
|
13
|
+
yield
|
14
|
+
end
|
15
|
+
assert(expr)
|
16
|
+
end
|
17
|
+
|
18
|
+
def my_assert_equal(e1, e2)
|
19
|
+
if e1 != e2 && block_given?
|
20
|
+
puts "\n--- DEBUG: "
|
21
|
+
yield
|
22
|
+
end
|
23
|
+
assert_equal(e1, e2)
|
24
|
+
end
|
25
|
+
|
26
|
+
## experimenting...
|
27
|
+
|
28
|
+
context "Mars date 1/1/1" do
|
29
|
+
md = MarsDateTime.new(1,1,1)
|
30
|
+
should "compute backwards to same result" do
|
31
|
+
assert_equal([1,1,1,0,0,0],md.ymshms)
|
32
|
+
end
|
33
|
+
should "be a Sunday" do
|
34
|
+
assert_equal(0,md.dow)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "Mars date 2/3/4" do
|
39
|
+
md = MarsDateTime.new(2,3,4)
|
40
|
+
should "compute backwards to same result" do
|
41
|
+
assert_equal([2,3,4,0,0,0],md.ymshms)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "Mars date 5/4/24" do
|
46
|
+
md = MarsDateTime.new(5,4,24)
|
47
|
+
should "compute backwards to same result" do
|
48
|
+
assert_equal([5,4,24,0,0,0],md.ymshms)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "Mars date 1054/20/20" do
|
53
|
+
md = MarsDateTime.new(1054,20,20)
|
54
|
+
should "compute backwards to same result" do
|
55
|
+
assert_equal([1054,20,20,0,0,0],md.ymshms)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "Earth date 1/1/22" do
|
60
|
+
ed = DateTime.new(1,1,22)
|
61
|
+
md = MarsDateTime.new(ed)
|
62
|
+
should "be approximately M-date 1/1/1" do
|
63
|
+
assert_equal([1,1,1],md.ymshms[0..2])
|
64
|
+
end
|
65
|
+
should "yield a Martian Sunday" do
|
66
|
+
assert_equal(md.day_of_week,"Sunday")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "Earth date May 23, 1961" do
|
71
|
+
e = DateTime.new(1961,5,23)
|
72
|
+
m = MarsDateTime.new(e)
|
73
|
+
should "yield a Martian Friday" do
|
74
|
+
assert_equal(m.day_of_week,"Friday")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context "Earth date May 24, 1961" do
|
79
|
+
e = DateTime.new(1961,5,24)
|
80
|
+
m = MarsDateTime.new(e)
|
81
|
+
should "yield a Martian Saturday" do
|
82
|
+
assert_equal(m.day_of_week,"Saturday")
|
83
|
+
# my_assert_equal(m.day_of_week,"Friday") { p m }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context "A Martian date/time (y,m,s,h,m,s)" do ###
|
88
|
+
m = MarsDateTime.new(1043,2,15,12,34,45)
|
89
|
+
should "set all its accessors properly" do
|
90
|
+
assert_equal(1043,m.myear)
|
91
|
+
assert_equal(2,m.month)
|
92
|
+
assert_equal(15,m.sol)
|
93
|
+
assert_equal(12,m.hr)
|
94
|
+
assert_equal(34,m.min)
|
95
|
+
assert_equal(45,m.sec)
|
96
|
+
assert_equal(4,m.dow)
|
97
|
+
assert_equal("Thursday",m.day_of_week)
|
98
|
+
assert_equal(43,m.year_sol)
|
99
|
+
assert_equal(696715,m.epoch_sol)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context "The 2007 Martian equinox" do ###
|
104
|
+
e = DateTime.new(2007,12,9,17,20,0)
|
105
|
+
m = MarsDateTime.new(e)
|
106
|
+
m11 = MarsDateTime.new(1068,1,1)
|
107
|
+
should "fall on or near 1/1 (MCE)" do
|
108
|
+
diff = (m11-m).abs
|
109
|
+
flag = diff < 1.5
|
110
|
+
assert(flag)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context "Constructing without parameters" do
|
115
|
+
m = MarsDateTime.new
|
116
|
+
e = DateTime.now
|
117
|
+
m2e = m.earth_date
|
118
|
+
should "default to today" do
|
119
|
+
diff = (e-m2e).abs # m - e doesn't work!
|
120
|
+
assert(diff < 1.0)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
context "Constructing with a DateTime" do
|
125
|
+
should "convert from Gregorian to MCE" do
|
126
|
+
e = DateTime.new(1902,8,12,7,0,0)
|
127
|
+
m = MarsDateTime.new(e)
|
128
|
+
diff = (m.earth_date - e).abs # days as a float
|
129
|
+
x = assert(diff < 1.0)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context "A Martian date/time (933,1,2)" do
|
134
|
+
m = MarsDateTime.new(933,1,2)
|
135
|
+
should "set the three obvious accessors properly" do
|
136
|
+
assert_equal(933,m.myear)
|
137
|
+
assert_equal(1,m.month)
|
138
|
+
assert_equal(2,m.sol)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
context "A Martian date/time (933,1,1)" do
|
143
|
+
m = MarsDateTime.new(933,1,1)
|
144
|
+
should "set the three obvious accessors properly" do
|
145
|
+
assert_equal(933,m.myear)
|
146
|
+
assert_equal(1,m.month)
|
147
|
+
assert_equal(1,m.sol)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
context "The Martian date 24/25" do
|
152
|
+
context "in a leap year" do
|
153
|
+
year = 1067
|
154
|
+
should "exist" do
|
155
|
+
assert( MarsDateTime.leap?(year) )
|
156
|
+
assert_nothing_raised { MarsDateTime.new(year,24,25) }
|
157
|
+
end
|
158
|
+
end
|
159
|
+
context "in a non-leap year" do
|
160
|
+
year = 1066
|
161
|
+
should "not exist" do
|
162
|
+
assert( ! MarsDateTime.leap?(year) )
|
163
|
+
assert_raise(RuntimeError) { MarsDateTime.new(year,24,25) }
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
context "The earth_date convertor" do
|
169
|
+
m = MarsDateTime.new(1,1,1)
|
170
|
+
should "convert to a Gregorian date" do
|
171
|
+
e = m.earth_date
|
172
|
+
assert_equal(1,e.year)
|
173
|
+
assert_equal(1,e.month)
|
174
|
+
assert((e.day-22).abs <= 1)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
context "An Earthly date" do
|
179
|
+
e1 = DateTime.new(1961,5,31)
|
180
|
+
should "(approximately) make the conversion roundtrip" do
|
181
|
+
m1 = MarsDateTime.new(e1)
|
182
|
+
e2 = m1.earth_date
|
183
|
+
diff = e2 - e1
|
184
|
+
assert(diff.abs <= 0.01)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
context "A Martian date" do
|
189
|
+
m1 = MarsDateTime.new(1067,1,1)
|
190
|
+
should "(approximately) make the conversion roundtrip" do
|
191
|
+
e1 = m1.earth_date
|
192
|
+
m2 = MarsDateTime.new(e1)
|
193
|
+
diff = m2 - m1
|
194
|
+
assert(diff.abs < 0.01)
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
context "An arbitrary Martian date" do
|
199
|
+
m1 = MarsDateTime.new(1069,15,24)
|
200
|
+
m2 = MarsDateTime.new(933,6,4)
|
201
|
+
m3 = MarsDateTime.new(1055,14,1)
|
202
|
+
should "format well with strftime" do
|
203
|
+
assert_equal("Mon",m1.strftime("%a"))
|
204
|
+
assert_equal("Monday",m1.strftime("%A"))
|
205
|
+
assert_equal("Aug",m1.strftime("%b"))
|
206
|
+
assert_equal("August",m1.strftime("%B"))
|
207
|
+
assert_equal("24",m1.strftime("%d"))
|
208
|
+
assert_equal("24",m1.strftime("%e"))
|
209
|
+
assert_equal("1069-15-24",m1.strftime("%F"))
|
210
|
+
assert_equal("416",m1.strftime("%j"))
|
211
|
+
assert_equal("15",m1.strftime("%m"))
|
212
|
+
assert_equal("0",m1.strftime("%s"))
|
213
|
+
assert_equal("2",m1.strftime("%u"))
|
214
|
+
assert_equal("60",m1.strftime("%U"))
|
215
|
+
assert_equal("1",m1.strftime("%w"))
|
216
|
+
assert_equal("1069/15/24",m1.strftime("%x"))
|
217
|
+
assert_equal("1069",m1.strftime("%Y"))
|
218
|
+
assert_equal("\n",m1.strftime("%n"))
|
219
|
+
assert_equal("\t",m1.strftime("%t"))
|
220
|
+
assert_equal("%",m1.strftime("%%"))
|
221
|
+
|
222
|
+
assert_equal("Wed",m2.strftime("%a"))
|
223
|
+
assert_equal("Wednesday",m2.strftime("%A"))
|
224
|
+
assert_equal("Leo",m2.strftime("%b"))
|
225
|
+
assert_equal("Leo",m2.strftime("%B"))
|
226
|
+
assert_equal("04",m2.strftime("%d"))
|
227
|
+
assert_equal(" 4",m2.strftime("%e"))
|
228
|
+
assert_equal("933-6-4",m2.strftime("%F"))
|
229
|
+
assert_equal("144",m2.strftime("%j"))
|
230
|
+
assert_equal("6",m2.strftime("%m"))
|
231
|
+
assert_equal("0",m2.strftime("%s"))
|
232
|
+
assert_equal("4",m2.strftime("%u"))
|
233
|
+
assert_equal("21",m2.strftime("%U"))
|
234
|
+
assert_equal("3",m2.strftime("%w"))
|
235
|
+
assert_equal("933/06/04",m2.strftime("%x"))
|
236
|
+
assert_equal("933",m2.strftime("%Y"))
|
237
|
+
|
238
|
+
assert_equal("Sag",m3.strftime("%b"))
|
239
|
+
assert_equal("Sagittarius",m3.strftime("%B"))
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
context "An Earthly date with h:m:s" do
|
244
|
+
e1 = DateTime.new(1976,7,4,16,30,0) # July 4, 1976 16:30
|
245
|
+
m1 = MarsDateTime.new(e1)
|
246
|
+
should "make the conversion roundtrip" do
|
247
|
+
30.times do
|
248
|
+
m1 = MarsDateTime.new(e1)
|
249
|
+
e2 = m1.earth_date
|
250
|
+
diff = e2 - e1
|
251
|
+
assert(diff.abs <= 0.01) { STDERR.puts " diff = #{diff}" }
|
252
|
+
e1 += 1
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
context "Martian dates" do
|
258
|
+
m1 = MarsDateTime.new(1068,14,22)
|
259
|
+
m2 = MarsDateTime.new(1068,14,21)
|
260
|
+
e1 = DateTime.new(2002,4,19)
|
261
|
+
e2 = DateTime.new(2012,9,29)
|
262
|
+
should "compare with each other" do
|
263
|
+
assert(m1 > m2)
|
264
|
+
assert(m2 < m1)
|
265
|
+
end
|
266
|
+
should "compare with Earth dates" do
|
267
|
+
assert(m1 > e1)
|
268
|
+
assert(m2 < e2)
|
269
|
+
end
|
270
|
+
should "honor equality (within roundoff)" do
|
271
|
+
assert(m1 == m1)
|
272
|
+
assert(m1 != m2)
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
context "The 'now' and 'today' class methods" do
|
277
|
+
t1 = MarsDateTime.now
|
278
|
+
t0 = MarsDateTime.today
|
279
|
+
should "be less than a day apart" do
|
280
|
+
diff = t1 - t0
|
281
|
+
assert(diff < 1.0)
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
context "In M-year 1043, each month" do
|
286
|
+
md = (1..24).to_a.map {|mm| MarsDateTime.new(1043,mm,1) }
|
287
|
+
should "start on a Thursday" do
|
288
|
+
md.each {|m| assert(m.day_of_week == "Thursday") }
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
context "Converting 1961/5/31 to Martian" do
|
293
|
+
e = DateTime.new(1961,5,31)
|
294
|
+
m = MarsDateTime.new(e)
|
295
|
+
should "yield M-April 10, 1043 MCE" do
|
296
|
+
assert(m.year == 1043)
|
297
|
+
assert(m.month == 7)
|
298
|
+
assert(m.sol == 10)
|
299
|
+
end
|
300
|
+
should "give a Martian Saturday" do
|
301
|
+
assert(m.day_of_week == "Saturday")
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
context "The 1609 Martian equinox" do
|
306
|
+
e = DateTime.new(1609,3,12)
|
307
|
+
m = MarsDateTime.new(e)
|
308
|
+
m11 = MarsDateTime.new(856,1,1)
|
309
|
+
should "fall on or near 1/1 (MCE)" do
|
310
|
+
diff = (m11-m).abs
|
311
|
+
assert(diff < 1.5)
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
context "The 1902 Martian equinox" do
|
316
|
+
e = DateTime.new(1902,8,12,7,0,0)
|
317
|
+
m = MarsDateTime.new(e)
|
318
|
+
m11 = MarsDateTime.new(1012,1,1)
|
319
|
+
should "fall on or near 1/1 (MCE)" do
|
320
|
+
diff = (m11-m).abs
|
321
|
+
assert(diff < 1.5)
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
context "A Martian date" do
|
326
|
+
m = MarsDateTime.new(1068,1,1)
|
327
|
+
context "plus 7 days" do
|
328
|
+
m2 = m + 7
|
329
|
+
should "be the same day of the week" do
|
330
|
+
assert_equal(m.day_of_week, m2.day_of_week)
|
331
|
+
end
|
332
|
+
end
|
333
|
+
context "plus 14 days" do
|
334
|
+
m3 = m + 14
|
335
|
+
should "be the same day of the week" do
|
336
|
+
assert_equal(m.day_of_week, m3.day_of_week)
|
337
|
+
end
|
338
|
+
end
|
339
|
+
context "plus 21 days" do
|
340
|
+
m4 = m + 21
|
341
|
+
should "be the same day of the week" do
|
342
|
+
assert_equal(m.day_of_week, m4.day_of_week)
|
343
|
+
end
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
context "Martian April 1, 1043" do
|
348
|
+
m = MarsDateTime.new(1043,7,1)
|
349
|
+
should "be a Thursday" do
|
350
|
+
assert_equal(m.day_of_week,"Thursday")
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
context "A Martian date" do
|
355
|
+
md = MarsDateTime.new(1062,20,20)
|
356
|
+
m2 = MarsDateTime.new(1062,20,17)
|
357
|
+
should "allow subtraction of another date" do
|
358
|
+
m = md - m2
|
359
|
+
assert( (m - 3.0) < 0.01) # sols
|
360
|
+
end
|
361
|
+
should "allow subtraction of an Earth date" do
|
362
|
+
e = DateTime.new(1998, 3, 12, 16, 45, 0)
|
363
|
+
m = md - e
|
364
|
+
assert( (m - 3.0) < 0.01) # sols
|
365
|
+
end
|
366
|
+
should "allow subtraction of a Fixnum" do
|
367
|
+
m = md - 3 # sols
|
368
|
+
assert( (m - m2) < 0.01)
|
369
|
+
end
|
370
|
+
should "allow subtraction of a Float" do
|
371
|
+
m = md - 3.0 # sols
|
372
|
+
assert( (m - m2) < 0.01)
|
373
|
+
end
|
374
|
+
end
|
375
|
+
|
376
|
+
end
|
377
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: marsdate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hal Fulton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |2
|
14
14
|
This is a library for handling dates and times on Mars
|
@@ -19,14 +19,19 @@ executables: []
|
|
19
19
|
extensions: []
|
20
20
|
extra_rdoc_files: []
|
21
21
|
files:
|
22
|
+
- bin/marsdate
|
23
|
+
- bin/marsdate-version
|
22
24
|
- bin/mcal.rb
|
25
|
+
- bin/meh.html
|
23
26
|
- bin/mkcal.rb
|
24
27
|
- bin/mtcon.rb
|
25
28
|
- bin/mtoday.rb
|
26
29
|
- lib/marsdate.rb
|
30
|
+
- test/spec/marsdate_spec.rb
|
31
|
+
- test/test.rb
|
27
32
|
homepage: https://github.com/Hal9000/marsdate
|
28
33
|
licenses:
|
29
|
-
- Ruby
|
34
|
+
- Ruby
|
30
35
|
metadata: {}
|
31
36
|
post_install_message:
|
32
37
|
rdoc_options: []
|