timeliness 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +6 -0
- data/README.rdoc +5 -5
- data/lib/timeliness/formats.rb +7 -7
- data/lib/timeliness/parser.rb +4 -3
- data/lib/timeliness/version.rb +1 -1
- data/lib/timeliness.rb +11 -1
- data/timeliness.gemspec +1 -1
- metadata +3 -3
data/CHANGELOG.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -11,11 +11,11 @@ Date/time parser for Ruby with the following features:
|
|
11
11
|
* It's pretty fast. Up to 60% faster than Time/Date parse method.
|
12
12
|
* Control the parser strictness.
|
13
13
|
* Control behaviour of ambiguous date formats (US vs European e.g. mm/dd/yy, dd/mm/yy).
|
14
|
-
* I18n support (for months).
|
14
|
+
* I18n support (for months), if I18n gem loaded.
|
15
15
|
* Fewer WTFs than Time/Date parse method.
|
16
16
|
* Has no dependencies.
|
17
17
|
|
18
|
-
Extracted from
|
18
|
+
Extracted from my {validates_timeliness gem}[http://github.com/adzap/validates_timeliness], it has been rewritten cleaner and much faster. It's most suitable for when
|
19
19
|
you need to control the parsing behaviour. It's faster than the Time/Date class parse methods, so it has general appeal.
|
20
20
|
|
21
21
|
|
@@ -36,7 +36,7 @@ or specified with :now option:
|
|
36
36
|
|
37
37
|
Timeliness.parse('12:13:14', :now => Time.mktime(2010,9,8)) #=> Wed Sep 08 12:13:14 1000 2010
|
38
38
|
|
39
|
-
You can also provide a type which will tell the parser that you are only interested in the
|
39
|
+
You can also provide a type which will tell the parser that you are only interested in the part of the value for that type.
|
40
40
|
|
41
41
|
Timeliness.parse('2010-09-08 12:13:14', :date) #=> Wed Sep 08 00:00:00 1000 2010
|
42
42
|
Timeliness.parse('2010-09-08 12:13:14', :time) #=> Sat Jan 01 12:13:14 1100 2000
|
@@ -48,7 +48,7 @@ Now let's get strict. Pass the :strict option with true and things get finicky
|
|
48
48
|
Timeliness.parse('2010-09-08 12:13:14', :time, :strict => true) #=> nil
|
49
49
|
Timeliness.parse('2010-09-08 12:13:14', :datetime, :strict => true) #=> Wed Sep 08 12:13:14 1000 2010 i.e. the whole string is used
|
50
50
|
|
51
|
-
The strict option without a type is ignored.
|
51
|
+
The date and time strings are not accepted for a datetime type. The strict option without a type is ignored.
|
52
52
|
|
53
53
|
To control what zone the time object is returned in, you have two options. Firstly you can set the default zone. Below
|
54
54
|
is the list of options with their effective time creation method call
|
@@ -166,7 +166,7 @@ Here is what each format token means:
|
|
166
166
|
|
167
167
|
All other characters are considered literal. For the technically minded, these formats are compiled into a single regular expression
|
168
168
|
|
169
|
-
To see all defined formats look at the {
|
169
|
+
To see all defined formats look at the {source code}[http://github.com/adzap/timeliness/tree/master/lib/timeliness/formats.rb].
|
170
170
|
|
171
171
|
|
172
172
|
== Settings
|
data/lib/timeliness/formats.rb
CHANGED
@@ -163,7 +163,7 @@ module Timeliness
|
|
163
163
|
compile_formats
|
164
164
|
end
|
165
165
|
|
166
|
-
# Removes US date formats so that
|
166
|
+
# Removes US date formats so that ambiguous dates are parsed as European format
|
167
167
|
#
|
168
168
|
def use_euro_formats
|
169
169
|
@date_format_set = FormatSet.compile(date_formats.select { |format| US_FORMAT_REGEXP !~ format })
|
@@ -194,18 +194,18 @@ module Timeliness
|
|
194
194
|
case type
|
195
195
|
when :date
|
196
196
|
[ @date_format_set, @datetime_format_set ]
|
197
|
-
when :time
|
198
|
-
if string.length < 11
|
199
|
-
[ @time_format_set ]
|
200
|
-
else
|
201
|
-
[ @datetime_format_set, @time_format_set ]
|
202
|
-
end
|
203
197
|
when :datetime
|
204
198
|
if string.length < 11
|
205
199
|
[ @date_format_set, @datetime_format_set ]
|
206
200
|
else
|
207
201
|
[ @datetime_format_set, @date_format_set ]
|
208
202
|
end
|
203
|
+
when :time
|
204
|
+
if string.length < 11
|
205
|
+
[ @time_format_set ]
|
206
|
+
else
|
207
|
+
[ @datetime_format_set, @time_format_set ]
|
208
|
+
end
|
209
209
|
else
|
210
210
|
if string.length < 11
|
211
211
|
[ @date_format_set, @time_format_set, @datetime_format_set ]
|
data/lib/timeliness/parser.rb
CHANGED
@@ -12,11 +12,12 @@ module Timeliness
|
|
12
12
|
time_array = _parse(value, type, options)
|
13
13
|
return nil if time_array.nil?
|
14
14
|
|
15
|
-
|
15
|
+
case type
|
16
|
+
when :date
|
16
17
|
time_array[3..7] = nil
|
17
|
-
|
18
|
+
when :time
|
18
19
|
time_array[0..2] = current_date(options)
|
19
|
-
|
20
|
+
when nil
|
20
21
|
dummy_date = current_date(options)
|
21
22
|
time_array[0] ||= dummy_date[0]
|
22
23
|
time_array[1] ||= dummy_date[1]
|
data/lib/timeliness/version.rb
CHANGED
data/lib/timeliness.rb
CHANGED
@@ -12,10 +12,20 @@ module Timeliness
|
|
12
12
|
extend Forwardable
|
13
13
|
def_delegators Parser, :parse, :_parse
|
14
14
|
def_delegators Formats, :add_formats, :remove_formats, :use_us_formats, :use_euro_formats
|
15
|
+
|
15
16
|
attr_accessor :default_timezone, :date_for_time_type, :ambiguous_year_threshold
|
17
|
+
|
18
|
+
alias :dummy_date_for_time_type :date_for_time_type
|
16
19
|
end
|
17
20
|
|
18
|
-
# Default timezone
|
21
|
+
# Default timezone. Options:
|
22
|
+
# - :local (default)
|
23
|
+
# - :utc
|
24
|
+
#
|
25
|
+
# If ActiveSupport loaded, also
|
26
|
+
# - :current
|
27
|
+
# - 'Zone name'
|
28
|
+
#
|
19
29
|
@default_timezone = :local
|
20
30
|
|
21
31
|
# Set the default date part for a time type values.
|
data/timeliness.gemspec
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timeliness
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Adam Meehan
|