time-helper 2.0.0 → 2.0.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/README +8 -3
- data/lib/time-helper.rb +10 -1
- metadata +27 -33
data/README
CHANGED
@@ -4,6 +4,9 @@ There's a method Time.strtotime which takes a date(time) string and turns it int
|
|
4
4
|
Also method add and substract to the instance. (Important, these methods do not account for leap years and months, etc, one month is 30 days and 1 year is 365 days.)
|
5
5
|
=~ to see if two Time objects are "close enough"
|
6
6
|
|
7
|
+
Time:: DateTimeRegex a regex for verifying if a string might represent a date
|
8
|
+
|
9
|
+
|
7
10
|
Usage examples:
|
8
11
|
|
9
12
|
Time.strtotime date_string
|
@@ -42,10 +45,13 @@ time_obj.=~ other_time, 360 # true or false if the difference is less than 6 min
|
|
42
45
|
*How is this diferent than just "Time.parse"?*
|
43
46
|
**********************************************
|
44
47
|
|
45
|
-
Time.parse does not work well with non-American formats, if like me, you're working with strings that have dates in a
|
46
|
-
mat like: DD/MM/YYYY Time.parse will not do. In fact, if you rewrite strtotime so it just calls parse a few of the tests
|
48
|
+
Time.parse does not work well with non-American formats, if like me, you're working with strings that have dates in a format like: DD/MM/YYYY Time.parse will not do. In fact, if you rewrite strtotime so it just calls parse a few of the tests
|
47
49
|
included will fail.
|
48
50
|
|
51
|
+
New in 2.0.1
|
52
|
+
Fixed an issue/bug where a few non date number sequences would be evaluated as date by ::valid_datetime? due to the a liniency in the validating regex.
|
53
|
+
The verification regex is now available for public as a constant: Time::DateTimeRegex
|
54
|
+
|
49
55
|
New in 2.0.0
|
50
56
|
Completelly changed =~ method, the second argument is now an acceptable difference in seconds - more reliable.
|
51
57
|
Removed the require 'time' std lib (which should reduce memory of this gem ) and as such it no longers has the parse method included in the strtotime method, if you want to use parse, use it!
|
@@ -64,4 +70,3 @@ Tomorrow and Yesterday methods
|
|
64
70
|
|
65
71
|
New in 1.1
|
66
72
|
I skiped this version.... because I suck at versioning
|
67
|
-
|
data/lib/time-helper.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
#@version 2.0.0
|
3
3
|
#@author Arthur
|
4
4
|
class Time
|
5
|
+
#datetime regex
|
6
|
+
DateTimeRegex = /^\d{2}|\d{4}[^\d]?\d{2}[^\d]?\d{2}|\d{4}(?:[^\d]?\d{2}:?\d{2}:?\d{2})?$/
|
5
7
|
#class methods
|
6
8
|
class << self
|
7
9
|
#@param string [String] a datetime string with many possible formats
|
@@ -44,7 +46,14 @@ class Time
|
|
44
46
|
#@param string [String] datetime string
|
45
47
|
#@return [Boolean]
|
46
48
|
def valid_datetime? string
|
47
|
-
|
49
|
+
valid_number_only_date_sizes = [8,14]
|
50
|
+
valid_date_sizes = [10, 19]
|
51
|
+
if string.match /^\d+$/
|
52
|
+
return false unless valid_number_only_date_sizes.include? string.length
|
53
|
+
else
|
54
|
+
return false unless valid_date_sizes.include? string.length
|
55
|
+
end
|
56
|
+
return false unless string.match DateTimeRegex
|
48
57
|
return true
|
49
58
|
end
|
50
59
|
#@return [Time] Time object set 24 hours ago
|
metadata
CHANGED
@@ -1,56 +1,50 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: time-helper
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.1
|
4
5
|
prerelease:
|
5
|
-
version: 2.0.0
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
8
|
-
|
7
|
+
authors:
|
8
|
+
- Arthur Silva
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
date: 2012-11-04 00:00:00 Z
|
12
|
+
date: 2012-11-04 00:00:00.000000000 Z
|
14
13
|
dependencies: []
|
15
|
-
|
16
|
-
|
14
|
+
description: ! " Adds a few methods to the Time class, more significant:\n\n strtotime
|
15
|
+
which returns a Time object based on a string.\n\n also methods add and substract
|
16
|
+
that allow you to do some easy date math (doesn't take leap months/years into account)\n
|
17
|
+
also tomorrow and yesterday methods witch are like Time.now +- 1 day\n\n =~ to
|
18
|
+
see if two Time objects are \"close enough\"\n"
|
17
19
|
email: awls99@gmail.com
|
18
20
|
executables: []
|
19
|
-
|
20
21
|
extensions: []
|
21
|
-
|
22
22
|
extra_rdoc_files: []
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
- README
|
23
|
+
files:
|
24
|
+
- lib/time-helper.rb
|
25
|
+
- README
|
27
26
|
homepage: https://github.com/awls99/time-helper
|
28
27
|
licenses: []
|
29
|
-
|
30
28
|
post_install_message:
|
31
29
|
rdoc_options: []
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
33
|
none: false
|
37
|
-
requirements:
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
39
|
none: false
|
43
|
-
requirements:
|
44
|
-
|
45
|
-
|
46
|
-
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
47
44
|
requirements: []
|
48
|
-
|
49
45
|
rubyforge_project:
|
50
|
-
rubygems_version: 1.8.
|
46
|
+
rubygems_version: 1.8.24
|
51
47
|
signing_key:
|
52
48
|
specification_version: 3
|
53
49
|
summary: A few helper functions for the Time class.
|
54
50
|
test_files: []
|
55
|
-
|
56
|
-
has_rdoc:
|