datemath 0.1.0 → 0.2.0
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/lib/datemath/parser.rb +8 -8
- data/lib/datemath/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: 233e2bd36ca6201e4626ce77408e011d810b345ae0258145aa280060fe65d539
|
4
|
+
data.tar.gz: 380afab2e63824722d60846b08f933d62c39ab3ce25d78140a4db435e9c6cc19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6dc61018e16ba75a21461da7c57ee4eb2c83839b1b392efdf63591958a76bf7b3fa09e8b367e7d48c717a02b5131a69dc0f187bb857f0ece2657f325a00ef523
|
7
|
+
data.tar.gz: 50c216362f841623437f7f5f07620bab4f4d0cf5980115e9f9cc07e6dbfd300f7c0f8d40aab2eaca612e6d360640de681e3c306c197c1fb4c530abc5563f374b
|
data/lib/datemath/parser.rb
CHANGED
@@ -5,8 +5,6 @@ module Datemath
|
|
5
5
|
#
|
6
6
|
def initialize
|
7
7
|
@units = ['y', 'M', 'w', 'd', 'h', 'm', 's', 'ms']
|
8
|
-
@unitsDesc = @units
|
9
|
-
@unitsAsc = @unitsDesc.reverse
|
10
8
|
end
|
11
9
|
|
12
10
|
# Parses a datemath string to DateTime
|
@@ -34,10 +32,10 @@ module Datemath
|
|
34
32
|
parse_string = text[0, index]
|
35
33
|
math_string = text[(index + 2)..text.length]
|
36
34
|
end
|
37
|
-
time = DateTime.parse(parse_string)
|
35
|
+
time = DateTime.parse(parse_string) rescue nil
|
38
36
|
end
|
39
37
|
|
40
|
-
return time if math_string == nil || math_string == ''
|
38
|
+
return time if math_string == nil || math_string == '' || time.nil?
|
41
39
|
parse_date_math(math_string, time, round_up)
|
42
40
|
end
|
43
41
|
|
@@ -164,6 +162,8 @@ module Datemath
|
|
164
162
|
date_time.public_send(operation, num.public_send("minutes"))
|
165
163
|
when "s"
|
166
164
|
date_time.public_send(operation, num.public_send("seconds"))
|
165
|
+
when "ms"
|
166
|
+
date_time.public_send(operation, (num/1000.0).public_send("seconds"))
|
167
167
|
end
|
168
168
|
end
|
169
169
|
|
@@ -186,8 +186,8 @@ module Datemath
|
|
186
186
|
date_time.end_of_hour
|
187
187
|
when "m"
|
188
188
|
date_time.end_of_minute
|
189
|
-
|
190
|
-
|
189
|
+
else
|
190
|
+
date_time
|
191
191
|
end
|
192
192
|
end
|
193
193
|
|
@@ -210,8 +210,8 @@ module Datemath
|
|
210
210
|
date_time.beginning_of_hour
|
211
211
|
when "m"
|
212
212
|
date_time.beginning_of_minute
|
213
|
-
|
214
|
-
|
213
|
+
else
|
214
|
+
date_time
|
215
215
|
end
|
216
216
|
end
|
217
217
|
|
data/lib/datemath/version.rb
CHANGED