matiox 0.0.0.9 → 0.0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/matiox.rb +2 -1
- data/lib/matiox/errors.rb +6 -2
- data/lib/matiox/initializers/default.rb +32 -30
- data/lib/matiox/initializers/from_gregorian.rb +11 -2
- data/lib/matiox/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a29677df3a23cf4c00f30b66abcdf7653726b70027fe7dca1690c7e578def3b
|
4
|
+
data.tar.gz: 3a6c5987a7ed704b4886853465ef2a3498d637ec9dc2aa15549a1ce20cda965e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b28bc22e99625f50ae37fc67a7d53a5cf2c225bb0242897d11b1f56b79fec351658c0178509315ff956993b97845c8ba271547f7f4eda8d4d42125b02229780f
|
7
|
+
data.tar.gz: 6720446cea830bf0620043cfa62e794fa8eb5a5622ba3b07d9950d1e6bc47cc7cce8c27d6bd1e2e397b62d88bf5b1b8c3b37a7b293a2cbf85c1cbe742c82d5fc
|
data/lib/matiox.rb
CHANGED
data/lib/matiox/errors.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
class Matiox
|
2
2
|
module Error
|
3
|
+
class NotYetImplemented < StandardError; end
|
3
4
|
module GregorianDate
|
4
|
-
class
|
5
|
-
|
5
|
+
class IncorrectlyFormatted < StandardError
|
6
|
+
class YMD < StandardError; end
|
7
|
+
class YMDHMS < StandardError; end
|
8
|
+
class ISO8601 < StandardError; end
|
9
|
+
end
|
6
10
|
end
|
7
11
|
end
|
8
12
|
end
|
@@ -1,52 +1,54 @@
|
|
1
1
|
class Matiox
|
2
|
-
module
|
2
|
+
module Initializer
|
3
|
+
module Default
|
3
4
|
|
4
|
-
|
5
|
+
def initialize(date=nil)
|
5
6
|
|
6
|
-
|
7
|
+
case date
|
7
8
|
|
8
|
-
|
9
|
+
when DateTime
|
9
10
|
|
10
|
-
|
11
|
+
@gregorian = date
|
11
12
|
|
12
|
-
|
13
|
+
when Time
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
15
|
+
seconds = date.sec + Rational(date.usec, 10**6)
|
16
|
+
offset = Rational(date.utc_offset, 60 * 60 * 24)
|
17
|
+
@gregorian = DateTime.new(
|
18
|
+
date.year,
|
19
|
+
date.month,
|
20
|
+
date.day,
|
21
|
+
date.hour,
|
22
|
+
date.min,
|
23
|
+
seconds,
|
24
|
+
offset
|
25
|
+
)
|
26
|
+
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
#de TODO: Move these into their own self.from_ methods and invoke in general initializer here:
|
29
|
+
#de TODO: Use Regular expressions?
|
30
|
+
when String
|
30
31
|
|
31
|
-
begin
|
32
|
-
@gregorian = DateTime.strptime(date, '%Y-%m-%dT%H:%M:%S%z')
|
33
|
-
rescue
|
34
32
|
begin
|
35
|
-
@gregorian = DateTime.strptime(date, '%Y-%m-%
|
33
|
+
@gregorian = DateTime.strptime(date, '%Y-%m-%dT%H:%M:%S%z')
|
36
34
|
rescue
|
37
35
|
begin
|
38
|
-
@gregorian = DateTime.strptime(date, '%Y-%m-%d')
|
36
|
+
@gregorian = DateTime.strptime(date, '%Y-%m-%d %H:%M:%S')
|
39
37
|
rescue
|
40
|
-
|
38
|
+
begin
|
39
|
+
@gregorian = DateTime.strptime(date, '%Y-%m-%d')
|
40
|
+
rescue
|
41
|
+
raise Matiox::Error::GregorianDate::IncorrectlyFormatted.new("Bad date string: #{date}")
|
42
|
+
end
|
41
43
|
end
|
42
44
|
end
|
45
|
+
|
46
|
+
else
|
47
|
+
@gregorian = DateTime.now
|
43
48
|
end
|
44
49
|
|
45
|
-
else
|
46
|
-
@gregorian = DateTime.now
|
47
50
|
end
|
48
51
|
|
49
52
|
end
|
50
|
-
|
51
53
|
end
|
52
54
|
end
|
@@ -1,17 +1,26 @@
|
|
1
1
|
class Matiox
|
2
|
-
module
|
3
|
-
|
2
|
+
module Initializer
|
3
|
+
module Gregorian
|
4
4
|
|
5
5
|
def from_ymdhms(date)
|
6
6
|
raise Error::NotYetImplemented
|
7
|
+
#de TODO: Convert to DateTime beforehand... after regular expression validation.
|
8
|
+
converted = DateTime.strptime(date, "FORMAT")
|
9
|
+
new(converted)
|
7
10
|
end
|
8
11
|
|
9
12
|
def from_ymd(date)
|
10
13
|
raise Error::NotYetImplemented
|
14
|
+
#de TODO: Convert to DateTime beforehand... after regular expression validation.
|
15
|
+
converted = DateTime.strptime(date, "FORMAT")
|
16
|
+
new(converted)
|
11
17
|
end
|
12
18
|
|
13
19
|
def from_iso8601(date)
|
14
20
|
raise Error::NotYetImplemented
|
21
|
+
#de TODO: Convert to DateTime beforehand... after regular expression validation.
|
22
|
+
converted = DateTime.strptime(date, "FORMAT")
|
23
|
+
new(converted)
|
15
24
|
end
|
16
25
|
|
17
26
|
end
|
data/lib/matiox/version.rb
CHANGED