rhodes-framework 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +3 -0
- data/Manifest.txt +8 -2
- data/README.txt +1 -0
- data/Rakefile +6 -30
- data/lib/builtinME.rb +67 -5
- data/lib/date.rb +121 -80
- data/lib/date/format.rb +44 -42
- data/lib/dateME.rb +2 -1
- data/lib/erb.rb +278 -238
- data/lib/rational.rb +2 -2
- data/lib/rho/rho.rb +59 -24
- data/lib/rho/rhoapplication.rb +13 -4
- data/lib/rho/rhocontroller.rb +7 -3
- data/lib/rho/rhoerror.rb +33 -0
- data/lib/rho/rhoutils.rb +5 -2
- data/lib/rhodes.rb +2 -2
- data/lib/rhom/rhom.rb +24 -11
- data/lib/rhom/rhom_db_adapter.rb +56 -23
- data/lib/rhom/rhom_object.rb +3 -32
- data/lib/rhom/rhom_object_factory.rb +154 -154
- data/lib/rhom/rhom_source.rb +9 -9
- data/lib/singleton.rb +3 -3
- data/lib/time.rb +20 -2
- data/lib/version.rb +2 -2
- data/spec/app/mspec/matchers/raise_error.rb +2 -1
- data/spec/app/spec/fixtures/object_values.txt +2 -2
- data/spec/app/spec/pagination/fixtures/object_values.txt +91 -0
- data/spec/app/spec/rho_controller_spec.rb +2 -2
- data/spec/app/spec/rho_spec.rb +8 -3
- data/spec/app/spec/rhom_db_adapter_spec.rb +27 -0
- data/spec/app/spec/{rhom_object_factory_spec.rb → rhom_object_spec.rb} +125 -10
- data/spec/app/spec/rhom_spec.rb +19 -8
- data/spec/app/spec/rhoruby_spec.rb +31 -0
- data/spec/app/spec/spec_helper.rb +2 -1
- data/spec/app/spec/syncengine_spec.rb +30 -0
- data/spec/app/spec_runner.rb +9 -5
- data/spec/build.yml +3 -2
- data/spec/rhoconfig.txt +2 -0
- metadata +19 -83
- data/lib/rhom/rhom_db_adapterME.rb +0 -92
data/History.txt
ADDED
data/Manifest.txt
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
.gitignore
|
2
|
+
History.txt
|
2
3
|
Manifest.txt
|
4
|
+
README.txt
|
3
5
|
Rakefile
|
4
6
|
lib/ServeME.rb
|
5
7
|
lib/bsearch.rb
|
@@ -17,6 +19,7 @@ lib/rho/rho.rb
|
|
17
19
|
lib/rho/rhoapplication.rb
|
18
20
|
lib/rho/rhocontact.rb
|
19
21
|
lib/rho/rhocontroller.rb
|
22
|
+
lib/rho/rhoerror.rb
|
20
23
|
lib/rho/rhofsconnector.rb
|
21
24
|
lib/rho/rhosupport.rb
|
22
25
|
lib/rho/rhoutils.rb
|
@@ -28,7 +31,6 @@ lib/rhofsconnector.rb
|
|
28
31
|
lib/rhom.rb
|
29
32
|
lib/rhom/rhom.rb
|
30
33
|
lib/rhom/rhom_db_adapter.rb
|
31
|
-
lib/rhom/rhom_db_adapterME.rb
|
32
34
|
lib/rhom/rhom_object.rb
|
33
35
|
lib/rhom/rhom_object_factory.rb
|
34
36
|
lib/rhom/rhom_source.rb
|
@@ -155,11 +157,15 @@ spec/app/mspec/utils/version.rb
|
|
155
157
|
spec/app/mspec/version.rb
|
156
158
|
spec/app/spec/fixtures/client_info.txt
|
157
159
|
spec/app/spec/fixtures/object_values.txt
|
160
|
+
spec/app/spec/pagination/fixtures/object_values.txt
|
158
161
|
spec/app/spec/rho_controller_spec.rb
|
159
162
|
spec/app/spec/rho_spec.rb
|
160
|
-
spec/app/spec/
|
163
|
+
spec/app/spec/rhom_db_adapter_spec.rb
|
164
|
+
spec/app/spec/rhom_object_spec.rb
|
161
165
|
spec/app/spec/rhom_spec.rb
|
166
|
+
spec/app/spec/rhoruby_spec.rb
|
162
167
|
spec/app/spec/spec_helper.rb
|
168
|
+
spec/app/spec/syncengine_spec.rb
|
163
169
|
spec/app/spec/webview_spec.rb
|
164
170
|
spec/app/spec_runner.rb
|
165
171
|
spec/build.yml
|
data/README.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
= Rhodes
|
data/Rakefile
CHANGED
@@ -1,33 +1,9 @@
|
|
1
|
-
%w[rubygems rake rake/clean fileutils newgem].each { |f| require f }
|
2
1
|
$:.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
3
|
-
require 'lib/
|
2
|
+
require 'lib/rhodes.rb'
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
9
|
-
$hoe = Hoe.new('rhodes-framework', RhodesFramework::VERSION) do |p|
|
10
|
-
p.developer('Rhomobile Dev', 'dev@rhomobile.com')
|
11
|
-
#p.changes = p.paragraphs_of("../History.txt", 0..1).join("\n\n") if File.exists? "../History.txt"
|
12
|
-
#p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
13
|
-
p.rubyforge_name = p.name # TODO this is default value
|
14
|
-
p.extra_deps = [
|
15
|
-
['sqlite3-ruby','= 1.2.3'],
|
16
|
-
['rcov'],
|
17
|
-
['rspec'],
|
18
|
-
['diff-lcs'],
|
19
|
-
['extlib'],
|
20
|
-
['newgem'],
|
21
|
-
['activesupport']
|
22
|
-
]
|
23
|
-
|
24
|
-
p.clean_globs |= %w[**/.DS_Store tmp *.log]
|
25
|
-
path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
|
26
|
-
p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
|
27
|
-
p.rsync_args = '-av --delete --ignore-errors'
|
28
|
-
p.test_globs = ''
|
29
|
-
p.summary = "rhodes-framework #{RhodesFramework::VERSION}"
|
30
|
-
|
6
|
+
Hoe.spec 'rhodes-framework' do |s|
|
7
|
+
s.developer 'Rhomobile Dev', 'dev@rhomobile.com'
|
8
|
+
s.version = Rhodes::VERSION
|
31
9
|
end
|
32
|
-
|
33
|
-
require 'newgem/tasks'
|
data/lib/builtinME.rb
CHANGED
@@ -16,10 +16,6 @@ module Kernel
|
|
16
16
|
false
|
17
17
|
end
|
18
18
|
|
19
|
-
def fork
|
20
|
-
raise NotImplementedError, "the fork() function is unimplemented on this machine"
|
21
|
-
end
|
22
|
-
|
23
19
|
def =~ x
|
24
20
|
false
|
25
21
|
end
|
@@ -56,6 +52,12 @@ module Kernel
|
|
56
52
|
private
|
57
53
|
def method_added symbol
|
58
54
|
end
|
55
|
+
|
56
|
+
public
|
57
|
+
def fork
|
58
|
+
raise NotImplementedError, "the fork() function is unimplemented on this machine"
|
59
|
+
end
|
60
|
+
|
59
61
|
end
|
60
62
|
|
61
63
|
class Object
|
@@ -90,6 +92,13 @@ module Enumerable
|
|
90
92
|
return array_of_tuples.collect {|x| x[0]}
|
91
93
|
end
|
92
94
|
|
95
|
+
def detect(ifnone = nil)
|
96
|
+
each { |obj| return obj if yield(obj) }
|
97
|
+
ifnone.call if ifnone
|
98
|
+
end
|
99
|
+
|
100
|
+
alias find :detect
|
101
|
+
|
93
102
|
def each_with_index
|
94
103
|
i = 0;
|
95
104
|
each {|x| yield x, i; i = i + 1}
|
@@ -137,6 +146,18 @@ module Enumerable
|
|
137
146
|
end
|
138
147
|
end
|
139
148
|
|
149
|
+
def all?(&proc)
|
150
|
+
proc = lambda { |obj| obj } unless block_given?
|
151
|
+
each { |obj| return false unless proc.call(obj) }
|
152
|
+
true
|
153
|
+
end
|
154
|
+
|
155
|
+
def any?(&proc)
|
156
|
+
proc = lambda { |obj| obj } unless block_given?
|
157
|
+
each { |obj| return true if proc.call(obj) }
|
158
|
+
false
|
159
|
+
end
|
160
|
+
|
140
161
|
def collect
|
141
162
|
arr = []
|
142
163
|
each{|obj| arr << yield(obj)}
|
@@ -217,7 +238,7 @@ class File
|
|
217
238
|
s = ""
|
218
239
|
first = true
|
219
240
|
aString.each {|x|
|
220
|
-
if !first
|
241
|
+
if !first and !s.end_with?(File::SEPARATOR)
|
221
242
|
s += File::SEPARATOR
|
222
243
|
end
|
223
244
|
s+= x
|
@@ -575,6 +596,47 @@ class FalseClass
|
|
575
596
|
end
|
576
597
|
end
|
577
598
|
|
599
|
+
class Range
|
600
|
+
include Enumerable
|
601
|
+
|
602
|
+
def ==(value)
|
603
|
+
if value.first == first and value.last == last and value.exclude_end? == exclude_end?
|
604
|
+
true
|
605
|
+
else
|
606
|
+
false
|
607
|
+
end
|
608
|
+
end
|
609
|
+
|
610
|
+
def ===(value)
|
611
|
+
each do |item|
|
612
|
+
return true if value == item
|
613
|
+
end
|
614
|
+
false
|
615
|
+
end
|
616
|
+
|
617
|
+
def to_s
|
618
|
+
return self.begin.to_s + "..." + self.end.to_s if exclude_end?
|
619
|
+
return self.begin.to_s + ".." + self.end.to_s
|
620
|
+
end
|
621
|
+
|
622
|
+
alias inspect :to_s
|
623
|
+
|
624
|
+
alias first :begin
|
625
|
+
alias last :end
|
626
|
+
|
627
|
+
def step(n=1)
|
628
|
+
if n == 1 then
|
629
|
+
each{|i|yield(i)}
|
630
|
+
else
|
631
|
+
counter = 0
|
632
|
+
each do |i|
|
633
|
+
yield(i) if counter%n == 0
|
634
|
+
counter = counter + 1
|
635
|
+
end
|
636
|
+
end
|
637
|
+
end
|
638
|
+
end
|
639
|
+
|
578
640
|
class String
|
579
641
|
include Comparable
|
580
642
|
|
data/lib/date.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
#
|
2
2
|
# date.rb - date and time library
|
3
3
|
#
|
4
|
-
# Author: Tadayoshi Funaba 1998-
|
4
|
+
# Author: Tadayoshi Funaba 1998-2008
|
5
5
|
#
|
6
6
|
# Documentation: William Webber <william@williamwebber.com>
|
7
7
|
#
|
8
8
|
#--
|
9
|
-
# $Id: date.rb,v 2.
|
9
|
+
# $Id: date.rb,v 2.37 2008-01-17 20:16:31+09 tadf Exp $
|
10
10
|
#++
|
11
11
|
#
|
12
12
|
# == Overview
|
@@ -193,11 +193,6 @@
|
|
193
193
|
#
|
194
194
|
# puts secs_to_new_year()
|
195
195
|
|
196
|
-
if defined? RHO_ME
|
197
|
-
require 'rationalME'
|
198
|
-
end
|
199
|
-
|
200
|
-
require 'rational'
|
201
196
|
require 'date/format'
|
202
197
|
|
203
198
|
# Class representing a date.
|
@@ -238,20 +233,20 @@ class Date
|
|
238
233
|
# Full month names, in English. Months count from 1 to 12; a
|
239
234
|
# month's numerical representation indexed into this array
|
240
235
|
# gives the name of that month (hence the first element is nil).
|
241
|
-
|
242
|
-
|
236
|
+
MONTHNAMES = [nil] + %w(January February March April May June July
|
237
|
+
August September October November December)
|
243
238
|
|
244
239
|
# Full names of days of the week, in English. Days of the week
|
245
240
|
# count from 0 to 6 (except in the commercial week); a day's numerical
|
246
241
|
# representation indexed into this array gives the name of that day.
|
247
|
-
|
242
|
+
DAYNAMES = %w(Sunday Monday Tuesday Wednesday Thursday Friday Saturday)
|
248
243
|
|
249
244
|
# Abbreviated month names, in English.
|
250
|
-
|
251
|
-
|
245
|
+
ABBR_MONTHNAMES = [nil] + %w(Jan Feb Mar Apr May Jun
|
246
|
+
Jul Aug Sep Oct Nov Dec)
|
252
247
|
|
253
248
|
# Abbreviated day names, in English.
|
254
|
-
|
249
|
+
ABBR_DAYNAMES = %w(Sun Mon Tue Wed Thu Fri Sat)
|
255
250
|
|
256
251
|
[MONTHNAMES, DAYNAMES, ABBR_MONTHNAMES, ABBR_DAYNAMES].each do |xs|
|
257
252
|
xs.each{|x| x.freeze unless x.nil?}.freeze
|
@@ -279,8 +274,8 @@ class Date
|
|
279
274
|
|
280
275
|
def <=> (other)
|
281
276
|
case other
|
282
|
-
when Infinity; d <=> other.d
|
283
|
-
when Numeric; d
|
277
|
+
when Infinity; return d <=> other.d
|
278
|
+
when Numeric; return d
|
284
279
|
else
|
285
280
|
begin
|
286
281
|
l, r = other.coerce(self)
|
@@ -317,7 +312,20 @@ class Date
|
|
317
312
|
# Gregorian calendar.
|
318
313
|
GREGORIAN = Infinity.new(-1)
|
319
314
|
|
320
|
-
|
315
|
+
HALF_DAYS_IN_DAY = Rational(1, 2) # :nodoc:
|
316
|
+
HOURS_IN_DAY = Rational(1, 24) # :nodoc:
|
317
|
+
MINUTES_IN_DAY = Rational(1, 1440) # :nodoc:
|
318
|
+
SECONDS_IN_DAY = Rational(1, 86400) # :nodoc:
|
319
|
+
MILLISECONDS_IN_DAY = Rational(1, 86400*10**3) # :nodoc:
|
320
|
+
NANOSECONDS_IN_DAY = Rational(1, 86400*10**9) # :nodoc:
|
321
|
+
MILLISECONDS_IN_SECOND = Rational(1, 10**3) # :nodoc:
|
322
|
+
NANOSECONDS_IN_SECOND = Rational(1, 10**9) # :nodoc:
|
323
|
+
|
324
|
+
MJD_EPOCH_IN_AJD = Rational(4800001, 2) # 1858-11-17 # :nodoc:
|
325
|
+
UNIX_EPOCH_IN_AJD = Rational(4881175, 2) # 1970-01-01 # :nodoc:
|
326
|
+
MJD_EPOCH_IN_CJD = 2400001 # :nodoc:
|
327
|
+
UNIX_EPOCH_IN_CJD = 2440588 # :nodoc:
|
328
|
+
LD_EPOCH_IN_CJD = 2299160 # :nodoc:
|
321
329
|
|
322
330
|
t = Module.new do
|
323
331
|
|
@@ -491,7 +499,7 @@ class Date
|
|
491
499
|
#
|
492
500
|
# Returns the (civil) Julian Day Number as [day_number,
|
493
501
|
# fraction] where +fraction+ is always 1/2.
|
494
|
-
def ajd_to_jd(ajd, of=0) (ajd + of +
|
502
|
+
def ajd_to_jd(ajd, of=0) (ajd + of + HALF_DAYS_IN_DAY).divmod(1) end # :nodoc:
|
495
503
|
|
496
504
|
# Convert a (civil) Julian Day Number to an Astronomical Julian
|
497
505
|
# Day Number.
|
@@ -502,46 +510,58 @@ class Date
|
|
502
510
|
#
|
503
511
|
# Returns the Astronomical Julian Day Number as a single
|
504
512
|
# numeric value.
|
505
|
-
def jd_to_ajd(jd, fr, of=0) jd + fr - of -
|
506
|
-
|
513
|
+
def jd_to_ajd(jd, fr, of=0) jd + fr - of - HALF_DAYS_IN_DAY end # :nodoc:
|
514
|
+
|
507
515
|
# Convert a fractional day +fr+ to [hours, minutes, seconds,
|
508
516
|
# fraction_of_a_second]
|
509
517
|
def day_fraction_to_time(fr) # :nodoc:
|
510
|
-
|
511
|
-
|
512
|
-
|
518
|
+
ss, fr = fr.divmod(SECONDS_IN_DAY) # 4p
|
519
|
+
h, ss = ss.divmod(3600)
|
520
|
+
min, s = ss.divmod(60)
|
513
521
|
return h, min, s, fr * 86400
|
514
522
|
end
|
515
523
|
|
516
524
|
# Convert an +h+ hour, +min+ minutes, +s+ seconds period
|
517
525
|
# to a fractional day.
|
518
|
-
|
519
|
-
|
526
|
+
begin
|
527
|
+
Rational(Rational(1, 2), 2) # a challenge
|
528
|
+
|
529
|
+
def time_to_day_fraction(h, min, s)
|
530
|
+
Rational(h * 3600 + min * 60 + s, 86400) # 4p
|
531
|
+
end
|
532
|
+
rescue
|
533
|
+
def time_to_day_fraction(h, min, s)
|
534
|
+
if Integer === h && Integer === min && Integer === s
|
535
|
+
Rational(h * 3600 + min * 60 + s, 86400) # 4p
|
536
|
+
else
|
537
|
+
(h * 3600 + min * 60 + s).to_r/86400 # 4p
|
538
|
+
end
|
539
|
+
end
|
520
540
|
end
|
521
541
|
|
522
542
|
# Convert an Astronomical Modified Julian Day Number to an
|
523
543
|
# Astronomical Julian Day Number.
|
524
|
-
def amjd_to_ajd(amjd) amjd +
|
544
|
+
def amjd_to_ajd(amjd) amjd + MJD_EPOCH_IN_AJD end # :nodoc:
|
525
545
|
|
526
546
|
# Convert an Astronomical Julian Day Number to an
|
527
547
|
# Astronomical Modified Julian Day Number.
|
528
|
-
def ajd_to_amjd(ajd) ajd -
|
548
|
+
def ajd_to_amjd(ajd) ajd - MJD_EPOCH_IN_AJD end # :nodoc:
|
529
549
|
|
530
550
|
# Convert a Modified Julian Day Number to a Julian
|
531
551
|
# Day Number.
|
532
|
-
def mjd_to_jd(mjd) mjd +
|
552
|
+
def mjd_to_jd(mjd) mjd + MJD_EPOCH_IN_CJD end # :nodoc:
|
533
553
|
|
534
554
|
# Convert a Julian Day Number to a Modified Julian Day
|
535
555
|
# Number.
|
536
|
-
def jd_to_mjd(jd) jd -
|
556
|
+
def jd_to_mjd(jd) jd - MJD_EPOCH_IN_CJD end # :nodoc:
|
537
557
|
|
538
558
|
# Convert a count of the number of days since the adoption
|
539
559
|
# of the Gregorian Calendar (in Italy) to a Julian Day Number.
|
540
|
-
def ld_to_jd(ld) ld +
|
560
|
+
def ld_to_jd(ld) ld + LD_EPOCH_IN_CJD end # :nodoc:
|
541
561
|
|
542
562
|
# Convert a Julian Day Number to the number of days since
|
543
563
|
# the adoption of the Gregorian Calendar (in Italy).
|
544
|
-
def jd_to_ld(jd) jd -
|
564
|
+
def jd_to_ld(jd) jd - LD_EPOCH_IN_CJD end # :nodoc:
|
545
565
|
|
546
566
|
# Convert a Julian Day Number to the day of the week.
|
547
567
|
#
|
@@ -680,9 +700,9 @@ class Date
|
|
680
700
|
h += 24 if h < 0
|
681
701
|
min += 60 if min < 0
|
682
702
|
s += 60 if s < 0
|
683
|
-
return unless ((0
|
684
|
-
(0
|
685
|
-
(0
|
703
|
+
return unless ((0...24) === h &&
|
704
|
+
(0...60) === min &&
|
705
|
+
(0...60) === s) ||
|
686
706
|
(24 == h &&
|
687
707
|
0 == min &&
|
688
708
|
0 == s)
|
@@ -839,7 +859,7 @@ class Date
|
|
839
859
|
h, fr = fr.divmod(3600)
|
840
860
|
min, fr = fr.divmod(60)
|
841
861
|
s, fr = fr.divmod(1)
|
842
|
-
elem[:jd] =
|
862
|
+
elem[:jd] = UNIX_EPOCH_IN_CJD + d
|
843
863
|
elem[:hour] = h
|
844
864
|
elem[:min] = min
|
845
865
|
elem[:sec] = s
|
@@ -1041,8 +1061,8 @@ class Date
|
|
1041
1061
|
# Day Number day 0.
|
1042
1062
|
#
|
1043
1063
|
# +sg+ specifies the Day of Calendar Reform.
|
1044
|
-
def self.parse(str='-4712-01-01',
|
1045
|
-
elem = _parse(str,
|
1064
|
+
def self.parse(str='-4712-01-01', comp=true, sg=ITALY)
|
1065
|
+
elem = _parse(str, comp)
|
1046
1066
|
new_by_frags(elem, sg)
|
1047
1067
|
end
|
1048
1068
|
|
@@ -1080,13 +1100,13 @@ class Date
|
|
1080
1100
|
|
1081
1101
|
class << self
|
1082
1102
|
|
1083
|
-
def once(*ids) # :nodoc:
|
1103
|
+
def once(*ids) # :nodoc: -- restricted
|
1084
1104
|
for id in ids
|
1085
1105
|
module_eval <<-"end;"
|
1086
|
-
alias_method :__#{id.
|
1087
|
-
private :__#{id.
|
1088
|
-
def #{id.to_s}(*args
|
1089
|
-
|
1106
|
+
alias_method :__#{id.object_id}__, :#{id.to_s}
|
1107
|
+
private :__#{id.object_id}__
|
1108
|
+
def #{id.to_s}(*args)
|
1109
|
+
@__ca__[#{id.object_id}] ||= __#{id.object_id}__(*args)
|
1090
1110
|
end
|
1091
1111
|
end;
|
1092
1112
|
end
|
@@ -1115,7 +1135,10 @@ class Date
|
|
1115
1135
|
#
|
1116
1136
|
# Using one of the factory methods such as Date::civil is
|
1117
1137
|
# generally easier and safer.
|
1118
|
-
def initialize(ajd=0, of=0, sg=ITALY)
|
1138
|
+
def initialize(ajd=0, of=0, sg=ITALY)
|
1139
|
+
@ajd, @of, @sg = ajd, of, sg
|
1140
|
+
@__ca__ = {}
|
1141
|
+
end
|
1119
1142
|
|
1120
1143
|
# Get the date as an Astronomical Julian Day Number.
|
1121
1144
|
def ajd() @ajd end
|
@@ -1198,7 +1221,12 @@ class Date
|
|
1198
1221
|
# Get the fraction-of-a-second of this date.
|
1199
1222
|
def sec_fraction() time[3] end
|
1200
1223
|
|
1201
|
-
|
1224
|
+
alias_method :minute, :min
|
1225
|
+
alias_method :second, :sec
|
1226
|
+
alias_method :second_fraction, :sec_fraction
|
1227
|
+
|
1228
|
+
private :hour, :min, :sec, :sec_fraction,
|
1229
|
+
:minute, :second, :second_fraction
|
1202
1230
|
|
1203
1231
|
def zone() strftime('%:z') end
|
1204
1232
|
|
@@ -1289,7 +1317,7 @@ class Date
|
|
1289
1317
|
|
1290
1318
|
def new_offset(of=0)
|
1291
1319
|
if String === of
|
1292
|
-
of = (zone_to_diff(of) || 0)
|
1320
|
+
of = Rational(zone_to_diff(of) || 0, 86400)
|
1293
1321
|
end
|
1294
1322
|
self.class.new!(@ajd, of, @sg)
|
1295
1323
|
end
|
@@ -1442,18 +1470,23 @@ class Date
|
|
1442
1470
|
def hash() @ajd.hash end
|
1443
1471
|
|
1444
1472
|
# Return internal object state as a programmer-readable string.
|
1445
|
-
def inspect
|
1473
|
+
def inspect
|
1474
|
+
format('#<%s: %s (%s,%s,%s)>', self.class, to_s, @ajd, @of, @sg)
|
1475
|
+
end
|
1446
1476
|
|
1447
1477
|
# Return the date as a human-readable string.
|
1448
1478
|
#
|
1449
1479
|
# The format used is YYYY-MM-DD.
|
1450
|
-
def to_s()
|
1480
|
+
def to_s() format('%.4d-%02d-%02d', year, mon, mday) end # 4p
|
1451
1481
|
|
1452
1482
|
# Dump to Marshal format.
|
1453
1483
|
def marshal_dump() [@ajd, @of, @sg] end
|
1454
1484
|
|
1455
|
-
# Load from
|
1456
|
-
def marshal_load(a)
|
1485
|
+
# Load from Marshal format.
|
1486
|
+
def marshal_load(a)
|
1487
|
+
@ajd, @of, @sg, = a
|
1488
|
+
@__ca__ = {}
|
1489
|
+
end
|
1457
1490
|
|
1458
1491
|
end
|
1459
1492
|
|
@@ -1521,13 +1554,12 @@ class DateTime < Date
|
|
1521
1554
|
#
|
1522
1555
|
# All day/time values default to 0.
|
1523
1556
|
def self.jd(jd=0, h=0, min=0, s=0, of=0, sg=ITALY)
|
1524
|
-
fr = _valid_time?(h, min, s)
|
1525
1557
|
unless (jd = _valid_jd?(jd, sg)) &&
|
1526
|
-
(fr)
|
1558
|
+
(fr = _valid_time?(h, min, s))
|
1527
1559
|
raise ArgumentError, 'invalid date'
|
1528
1560
|
end
|
1529
1561
|
if String === of
|
1530
|
-
of = (zone_to_diff(of) || 0)
|
1562
|
+
of = Rational(zone_to_diff(of) || 0, 86400)
|
1531
1563
|
end
|
1532
1564
|
new!(jd_to_ajd(jd, fr, of), of, sg)
|
1533
1565
|
end
|
@@ -1547,13 +1579,12 @@ class DateTime < Date
|
|
1547
1579
|
# +y+ defaults to -4712, and +d+ to 1; this is Julian Day Number
|
1548
1580
|
# day 0. The time values default to 0.
|
1549
1581
|
def self.ordinal(y=-4712, d=1, h=0, min=0, s=0, of=0, sg=ITALY)
|
1550
|
-
fr = _valid_time?(h, min, s)
|
1551
1582
|
unless (jd = _valid_ordinal?(y, d, sg)) &&
|
1552
|
-
(fr)
|
1583
|
+
(fr = _valid_time?(h, min, s))
|
1553
1584
|
raise ArgumentError, 'invalid date'
|
1554
1585
|
end
|
1555
1586
|
if String === of
|
1556
|
-
of = (zone_to_diff(of) || 0)
|
1587
|
+
of = Rational(zone_to_diff(of) || 0, 86400)
|
1557
1588
|
end
|
1558
1589
|
new!(jd_to_ajd(jd, fr, of), of, sg)
|
1559
1590
|
end
|
@@ -1573,13 +1604,12 @@ class DateTime < Date
|
|
1573
1604
|
# +y+ defaults to -4712, +m+ to 1, and +d+ to 1; this is Julian Day
|
1574
1605
|
# Number day 0. The time values default to 0.
|
1575
1606
|
def self.civil(y=-4712, m=1, d=1, h=0, min=0, s=0, of=0, sg=ITALY)
|
1576
|
-
fr = _valid_time?(h, min, s)
|
1577
1607
|
unless (jd = _valid_civil?(y, m, d, sg)) &&
|
1578
|
-
(fr)
|
1608
|
+
(fr = _valid_time?(h, min, s))
|
1579
1609
|
raise ArgumentError, 'invalid date'
|
1580
1610
|
end
|
1581
1611
|
if String === of
|
1582
|
-
of = (zone_to_diff(of) || 0)
|
1612
|
+
of = Rational(zone_to_diff(of) || 0, 86400)
|
1583
1613
|
end
|
1584
1614
|
new!(jd_to_ajd(jd, fr, of), of, sg)
|
1585
1615
|
end
|
@@ -1602,25 +1632,23 @@ class DateTime < Date
|
|
1602
1632
|
# Julian Day Number day 0.
|
1603
1633
|
# The time values default to 0.
|
1604
1634
|
def self.commercial(y=-4712, w=1, d=1, h=0, min=0, s=0, of=0, sg=ITALY)
|
1605
|
-
fr = _valid_time?(h, min, s)
|
1606
1635
|
unless (jd = _valid_commercial?(y, w, d, sg)) &&
|
1607
|
-
(fr)
|
1636
|
+
(fr = _valid_time?(h, min, s))
|
1608
1637
|
raise ArgumentError, 'invalid date'
|
1609
1638
|
end
|
1610
1639
|
if String === of
|
1611
|
-
of = (zone_to_diff(of) || 0)
|
1640
|
+
of = Rational(zone_to_diff(of) || 0, 86400)
|
1612
1641
|
end
|
1613
1642
|
new!(jd_to_ajd(jd, fr, of), of, sg)
|
1614
1643
|
end
|
1615
1644
|
|
1616
1645
|
def self.weeknum(y=-4712, w=0, d=1, f=0, h=0, min=0, s=0, of=0, sg=ITALY) # :nodoc:
|
1617
|
-
fr = _valid_time?(h, min, s)
|
1618
1646
|
unless (jd = _valid_weeknum?(y, w, d, f, sg)) &&
|
1619
|
-
(fr)
|
1647
|
+
(fr = _valid_time?(h, min, s))
|
1620
1648
|
raise ArgumentError, 'invalid date'
|
1621
1649
|
end
|
1622
1650
|
if String === of
|
1623
|
-
of = (zone_to_diff(of) || 0)
|
1651
|
+
of = Rational(zone_to_diff(of) || 0, 86400)
|
1624
1652
|
end
|
1625
1653
|
new!(jd_to_ajd(jd, fr, of), of, sg)
|
1626
1654
|
end
|
@@ -1628,13 +1656,12 @@ class DateTime < Date
|
|
1628
1656
|
private_class_method :weeknum
|
1629
1657
|
|
1630
1658
|
def self.nth_kday(y=-4712, m=1, n=1, k=1, h=0, min=0, s=0, of=0, sg=ITALY) # :nodoc:
|
1631
|
-
fr = _valid_time?(h, min, s)
|
1632
1659
|
unless (jd = _valid_nth_kday?(y, m, n, k, sg)) &&
|
1633
|
-
(fr)
|
1660
|
+
(fr = _valid_time?(h, min, s))
|
1634
1661
|
raise ArgumentError, 'invalid date'
|
1635
1662
|
end
|
1636
1663
|
if String === of
|
1637
|
-
of = (zone_to_diff(of) || 0)
|
1664
|
+
of = Rational(zone_to_diff(of) || 0, 86400)
|
1638
1665
|
end
|
1639
1666
|
new!(jd_to_ajd(jd, fr, of), of, sg)
|
1640
1667
|
end
|
@@ -1644,15 +1671,12 @@ class DateTime < Date
|
|
1644
1671
|
def self.new_by_frags(elem, sg) # :nodoc:
|
1645
1672
|
elem = rewrite_frags(elem)
|
1646
1673
|
elem = complete_frags(elem)
|
1647
|
-
fr = valid_time_frags?(elem)
|
1648
1674
|
unless (jd = valid_date_frags?(elem, sg)) &&
|
1649
|
-
(fr)
|
1675
|
+
(fr = valid_time_frags?(elem))
|
1650
1676
|
raise ArgumentError, 'invalid date'
|
1651
1677
|
end
|
1652
|
-
|
1653
|
-
|
1654
|
-
of = (elem[:offset] || 0)
|
1655
|
-
of = of.to_r/86400
|
1678
|
+
fr += (elem[:sec_fraction] || 0) / 86400
|
1679
|
+
of = Rational(elem[:offset] || 0, 86400)
|
1656
1680
|
new!(jd_to_ajd(jd, fr, of), of, sg)
|
1657
1681
|
end
|
1658
1682
|
|
@@ -1692,8 +1716,8 @@ class DateTime < Date
|
|
1692
1716
|
# Day Number day 0.
|
1693
1717
|
#
|
1694
1718
|
# +sg+ specifies the Day of Calendar Reform.
|
1695
|
-
def self.parse(str='-4712-01-01T00:00:00+00:00',
|
1696
|
-
elem = _parse(str,
|
1719
|
+
def self.parse(str='-4712-01-01T00:00:00+00:00', comp=true, sg=ITALY)
|
1720
|
+
elem = _parse(str, comp)
|
1697
1721
|
new_by_frags(elem, sg)
|
1698
1722
|
end
|
1699
1723
|
|
@@ -1729,7 +1753,13 @@ class DateTime < Date
|
|
1729
1753
|
new_by_frags(elem, sg)
|
1730
1754
|
end
|
1731
1755
|
|
1732
|
-
public :hour, :min, :sec, :sec_fraction, :zone, :offset, :new_offset
|
1756
|
+
public :hour, :min, :sec, :sec_fraction, :zone, :offset, :new_offset,
|
1757
|
+
:minute, :second, :second_fraction
|
1758
|
+
|
1759
|
+
def to_s # 4p
|
1760
|
+
format('%.4d-%02d-%02dT%02d:%02d:%02d%s',
|
1761
|
+
year, mon, mday, hour, min, sec, zone)
|
1762
|
+
end
|
1733
1763
|
|
1734
1764
|
end
|
1735
1765
|
|
@@ -1744,9 +1774,9 @@ class Time
|
|
1744
1774
|
|
1745
1775
|
def to_datetime
|
1746
1776
|
jd = DateTime.__send__(:civil_to_jd, year(), mon(), mday(), DateTime::ITALY)
|
1747
|
-
fr = DateTime.__send__(:time_to_day_fraction, hour(), min(), [sec, 59].min) +
|
1748
|
-
nsec
|
1749
|
-
of = utc_offset
|
1777
|
+
fr = DateTime.__send__(:time_to_day_fraction, hour(), min(), [sec(), 59].min) +
|
1778
|
+
Rational(nsec, 86400_000_000_000)
|
1779
|
+
of = Rational(utc_offset, 86400)
|
1750
1780
|
DateTime.new!(DateTime.__send__(:jd_to_ajd, jd, fr, of),
|
1751
1781
|
of, DateTime::ITALY)
|
1752
1782
|
end
|
@@ -1762,12 +1792,23 @@ class Date
|
|
1762
1792
|
# Create a new Date object representing today.
|
1763
1793
|
#
|
1764
1794
|
# +sg+ specifies the Day of Calendar Reform.
|
1765
|
-
def self.today(sg=ITALY)
|
1795
|
+
def self.today(sg=ITALY)
|
1796
|
+
t = Time.now
|
1797
|
+
jd = civil_to_jd(t.year(), t.mon(), t.mday(), sg)
|
1798
|
+
new!(jd_to_ajd(jd, 0, 0), 0, sg)
|
1799
|
+
end
|
1766
1800
|
|
1767
1801
|
# Create a new DateTime object representing the current time.
|
1768
1802
|
#
|
1769
1803
|
# +sg+ specifies the Day of Calendar Reform.
|
1770
|
-
def self.now
|
1804
|
+
def self.now(sg=ITALY)
|
1805
|
+
t = Time.now
|
1806
|
+
jd = civil_to_jd(t.year(), t.mon(), t.mday(), sg)
|
1807
|
+
fr = time_to_day_fraction(t.hour(), t.min(), [t.sec(), 59].min()) +
|
1808
|
+
Rational(t.nsec(), 86400_000_000_000)
|
1809
|
+
of = Rational(t.utc_offset(), 86400)
|
1810
|
+
new!(jd_to_ajd(jd, fr, of), of, sg)
|
1811
|
+
end
|
1771
1812
|
|
1772
1813
|
private_class_method :now
|
1773
1814
|
|