dater 0.2.0 → 0.2.1
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.
- data/Gemfile.lock +1 -1
- data/README.md +2 -1
- data/lib/dater.rb +7 -20
- data/lib/dater/version.rb +1 -1
- metadata +1 -1
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -37,7 +37,8 @@ Or install it yourself as:
|
|
37
37
|
|
38
38
|
#To get the converted date:
|
39
39
|
|
40
|
-
date.for("in
|
40
|
+
date.for("in 4 days") # => yyyy-mm-dd (date for 4 days from the date of today)
|
41
|
+
date.for("in 2 weeks") # => yyyy-mm-dd (date for 2 weeks from the date of today)
|
41
42
|
date.for("in 10 months") # => yyyy-mm-dd (date for 10 months from the date of today)
|
42
43
|
date.for("in 1 year") # => yyyy-mm-dd (date for 1 year from the date of today)
|
43
44
|
|
data/lib/dater.rb
CHANGED
@@ -46,19 +46,7 @@ module Dater
|
|
46
46
|
parts=period.split('-')
|
47
47
|
else
|
48
48
|
if (amount=period.scan(/\d+/)).size>0
|
49
|
-
|
50
|
-
if times[:year]
|
51
|
-
multiply_by = 3600*24*30*12
|
52
|
-
elsif times[:months]
|
53
|
-
multiply_by = 3600*24*30
|
54
|
-
elsif times[:weeks]
|
55
|
-
multiply_by = 3600*24*7
|
56
|
-
elsif times[:days]
|
57
|
-
multiply_by = 3600*24
|
58
|
-
else
|
59
|
-
multiply_by = 1
|
60
|
-
end
|
61
|
-
additional=amount[0].to_i*multiply_by
|
49
|
+
additional=amount[0].to_i*self.multiply_by(period,@lang)
|
62
50
|
@date=Time.now+additional
|
63
51
|
else
|
64
52
|
return period
|
@@ -73,13 +61,12 @@ module Dater
|
|
73
61
|
# Param [String] period = the period of time expressed in a literal way
|
74
62
|
# Param [String] lang = the languaje to eval
|
75
63
|
# Return [Hash] times
|
76
|
-
def
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
times
|
64
|
+
def multiply_by(period, lang)
|
65
|
+
return 3600*24 if period.scan(DICTIONARY[:day][lang]).size>0
|
66
|
+
return 3600*24*7 if period.scan(DICTIONARY[:week][lang]).size>0
|
67
|
+
return 3600*24*30 if period.scan(DICTIONARY[:month][lang]).size>0
|
68
|
+
return 3600*24*30*12 if period.scan(DICTIONARY[:year][lang]).size>0
|
69
|
+
return 1
|
83
70
|
end
|
84
71
|
|
85
72
|
# Return the Time object according to the splitted date in the given array
|
data/lib/dater/version.rb
CHANGED