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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 85fd02613548daff6b145b6b134901e0f1d2d35934e5ca37242e862f2b7496b0
4
- data.tar.gz: acb351ea8f9e19cc83a857239f6180ccba856f5d82aec1836c5f72cf88d600fb
3
+ metadata.gz: 233e2bd36ca6201e4626ce77408e011d810b345ae0258145aa280060fe65d539
4
+ data.tar.gz: 380afab2e63824722d60846b08f933d62c39ab3ce25d78140a4db435e9c6cc19
5
5
  SHA512:
6
- metadata.gz: aa60c42b61b55fce361839c5b075ed2943cb1a63b5f8a912743d3b82eecccd906a58c22c0d5cdb8f26cdda528f5ac139d327c84e83e033be71cb51c650a68270
7
- data.tar.gz: 361435c50ea23472c4e8a638695fda533ad70b271830844cec5e51372ac85272ecba89bb3bf84eb6732528c23dd87328cfddef55296fb97d8d9cf1e7d68e93ce
6
+ metadata.gz: 6dc61018e16ba75a21461da7c57ee4eb2c83839b1b392efdf63591958a76bf7b3fa09e8b367e7d48c717a02b5131a69dc0f187bb857f0ece2657f325a00ef523
7
+ data.tar.gz: 50c216362f841623437f7f5f07620bab4f4d0cf5980115e9f9cc07e6dbfd300f7c0f8d40aab2eaca612e6d360640de681e3c306c197c1fb4c530abc5563f374b
@@ -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
- when "s"
190
- # TODO Handle s and ms
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
- when "s"
214
- # TODO Handle s and ms
213
+ else
214
+ date_time
215
215
  end
216
216
  end
217
217
 
@@ -1,3 +1,3 @@
1
1
  module Datemath
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datemath
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - victor-aguilars