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 CHANGED
@@ -0,0 +1,6 @@
1
+ = 0.1.1 - 2010-10-14
2
+ * Alias for validates_timeliness compatibility
3
+ * Tiny cleanup
4
+
5
+ = 0.1.0 - 2010-10-14
6
+ * Initial release
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 the validates_timeliness gem, it has been rewritten cleaner and much faster. It's most suitable for when
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 values for that type.
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 {parser source code}[http://github.com/adzap/timeliness/tree/master/lib/timeliness/parser.rb].
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
@@ -163,7 +163,7 @@ module Timeliness
163
163
  compile_formats
164
164
  end
165
165
 
166
- # Removes US date formats so that ambigious dates are parsed as European format
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 ]
@@ -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
- if type == :date
15
+ case type
16
+ when :date
16
17
  time_array[3..7] = nil
17
- elsif type == :time
18
+ when :time
18
19
  time_array[0..2] = current_date(options)
19
- elsif type.nil?
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]
@@ -1,3 +1,3 @@
1
1
  module Timeliness
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
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 (:local or :utc)
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{timeliness}
5
- s.version = "0.1.0"
5
+ s.version = "0.1.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Adam Meehan"]
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: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Adam Meehan