time-helper 1.0.01 → 1.2

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.
Files changed (2) hide show
  1. data/lib/time-helper.rb +29 -4
  2. metadata +2 -7
@@ -1,8 +1,11 @@
1
- #@version 1.0
1
+ #@version 1.0.0
2
2
  #@author Arthur
3
3
  class Time
4
4
  #class methods
5
5
  class << self
6
+ #@param string [String] a datetime string with many possible formats
7
+ #@see Time#valid_datetime? or the feature file for valid format
8
+ #@return [Time] set in the date of the string passed
6
9
  def strtotime string
7
10
  abort 'invalid date' unless valid_datetime? string
8
11
  h,m,s = 0,0,0
@@ -35,12 +38,20 @@ class Time
35
38
  end
36
39
 
37
40
  end
38
-
41
+ #@param string [String] datetime string
42
+ #@return [Boolean]
39
43
  def valid_datetime? string
40
44
  return false unless string.match /\d{2,4}.?\d{2}.?\d{2,4}(?:.?\d{2}:?\d{2}:?\d{2})?/
41
45
  return true
42
46
  end
43
-
47
+ #@return [Time] Time object set 24 hours ago
48
+ def tomorrow
49
+ return Time.now.add(:day => 1 )
50
+ end
51
+ #@return [Time] return time object 24 hours from now
52
+ def yesterday
53
+ return Time.now.substract(:day => 1 )
54
+ end
44
55
  private
45
56
  def get_time_array time
46
57
  h,m,s = 0,0,0
@@ -129,11 +140,25 @@ class Time
129
140
  end
130
141
  end
131
142
 
132
- #instance methods
143
+ #@param params [Hash] hash of time to be added {:time => amount } (can take several at once)
144
+ #@return [Time] new time object with date set to the result
145
+ # @example add time
146
+ # t = Time.now()
147
+ # t.add(:year => 1 ) #=> a time object set for 365 days from now
148
+ # t.add(:year => 2, :day => 1 ) #=> a time object set 731 days from now
149
+ # accepts :year :month :day :minute :hour :second :week
133
150
  def add params
134
151
  seconds = get_seconds params
135
152
  return self + seconds
136
153
  end
154
+
155
+ #@param params [Hash] hash of time to be added {:time => amount } (can take several at once)
156
+ #@return [Time] new time object with date set to the result
157
+ # @example substract time
158
+ # t = Time.now()
159
+ # t.substract(:year => 1 ) returns a time object set for 365 days ago
160
+ # t.substract(:year => 2, :day => 1 ) returns a time object set 731 ago
161
+ # accepts :year :month :day :minute :hour :second :week
137
162
  def substract params
138
163
  seconds = get_seconds params
139
164
  return self - seconds
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: time-helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.01
4
+ version: "1.2"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arthur Silva
@@ -13,12 +13,7 @@ date: 2012-05-02 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description: |-
17
- Adds a few methods to the Time class, more significant:
18
-
19
- strtotime which returns a Time object based on a string.
20
-
21
- also methods add and substract that allow you to do some easy date math (doesn't take leap months/years into account)
16
+ description: "Adds a few methods to the Time class, more significant:\n\n strtotime which returns a Time object based on a string.\n\n also methods add and substract that allow you to do some easy date math (doesn't take leap months/years into account)\n also tomorrow and yesterday methods witch are like Time.now +- 1 day "
22
17
  email: awls99@gmail.com
23
18
  executables: []
24
19