rubysl-parsedate 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE +25 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/parsedate.rb +1 -0
- data/lib/rubysl/parsedate.rb +2 -0
- data/lib/rubysl/parsedate/parsedate.rb +53 -0
- data/lib/rubysl/parsedate/version.rb +5 -0
- data/rubysl-parsedate.gemspec +24 -0
- data/spec/parsedate_spec.rb +105 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e7684bc47785bbf015a0a457e2fb721a7159108c
|
4
|
+
data.tar.gz: 20268a4862b8aa8895604a766562b91c5bceff3b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fc07fc433479c2a8355f6fda1ba67d8bf70ff54e66d2727f08fd850273b06755e48457a45fcd0797b9c0b8ce64d11e9425d462baf15a858473e753dd40c45ec1
|
7
|
+
data.tar.gz: 6378660c69695981e523886f3fbe6d4417dc3163eb013fb55af56257f986820adc961edac679e0b65326f0b64e1e8725fd3b52878ba55c64fd584d4bbc3fe0b9
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Copyright (c) 2013, Brian Shirai
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
8
|
+
list of conditions and the following disclaimer.
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
11
|
+
and/or other materials provided with the distribution.
|
12
|
+
3. Neither the name of the library nor the names of its contributors may be
|
13
|
+
used to endorse or promote products derived from this software without
|
14
|
+
specific prior written permission.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
18
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
19
|
+
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY DIRECT,
|
20
|
+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
21
|
+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
22
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
23
|
+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
24
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
25
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Rubysl::Parsedate
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'rubysl-parsedate'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install rubysl-parsedate
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/parsedate.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "rubysl/parsedate"
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#
|
2
|
+
# = parsedate.rb: Parses dates
|
3
|
+
#
|
4
|
+
# Author:: Tadayoshi Funaba
|
5
|
+
# Documentation:: Konrad Meyer
|
6
|
+
#
|
7
|
+
# ParseDate munches on a date and turns it into an array of values.
|
8
|
+
#
|
9
|
+
|
10
|
+
#
|
11
|
+
# ParseDate converts a date into an array of values.
|
12
|
+
# For example:
|
13
|
+
#
|
14
|
+
# require 'parsedate'
|
15
|
+
#
|
16
|
+
# ParseDate.parsedate "Tuesday, July 6th, 2007, 18:35:20 UTC"
|
17
|
+
# # => [2007, 7, 6, 18, 35, 20, "UTC", 2]
|
18
|
+
#
|
19
|
+
# The order is of the form [year, month, day of month, hour, minute, second,
|
20
|
+
# timezone, day of the week].
|
21
|
+
|
22
|
+
require 'date/format'
|
23
|
+
|
24
|
+
module ParseDate
|
25
|
+
#
|
26
|
+
# Parse a string representation of a date into values.
|
27
|
+
# For example:
|
28
|
+
#
|
29
|
+
# require 'parsedate'
|
30
|
+
#
|
31
|
+
# ParseDate.parsedate "Tuesday, July 5th, 2007, 18:35:20 UTC"
|
32
|
+
# # => [2007, 7, 5, 18, 35, 20, "UTC", 2]
|
33
|
+
#
|
34
|
+
# The order is of the form [year, month, day of month, hour, minute,
|
35
|
+
# second, timezone, day of week].
|
36
|
+
#
|
37
|
+
# ParseDate.parsedate can also take a second argument, +comp+, which
|
38
|
+
# is a boolean telling the method to compensate for dates with years
|
39
|
+
# expressed as two digits. Example:
|
40
|
+
#
|
41
|
+
# require 'parsedate'
|
42
|
+
#
|
43
|
+
# ParseDate.parsedate "Mon Dec 25 00 06:53:24 UTC", true
|
44
|
+
# # => [2000, 12, 25, 6, 53, 24, "UTC", 1]
|
45
|
+
#
|
46
|
+
def parsedate(str, comp=false)
|
47
|
+
Date._parse(str, comp).
|
48
|
+
values_at(:year, :mon, :mday, :hour, :min, :sec, :zone, :wday)
|
49
|
+
end
|
50
|
+
|
51
|
+
module_function :parsedate
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require './lib/rubysl/parsedate/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "rubysl-parsedate"
|
6
|
+
spec.version = RubySL::ParseDate::VERSION
|
7
|
+
spec.authors = ["Brian Shirai"]
|
8
|
+
spec.email = ["brixen@gmail.com"]
|
9
|
+
spec.description = %q{Ruby standard library parsedate.}
|
10
|
+
spec.summary = %q{Ruby standard library parsedate.}
|
11
|
+
spec.homepage = "https://github.com/rubysl/rubysl-parsedate"
|
12
|
+
spec.license = "BSD"
|
13
|
+
|
14
|
+
spec.files = `git ls-files`.split($/)
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_runtime_dependency "rubysl-date", "~> 1.0"
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "mspec", "~> 1.5"
|
24
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
ruby_version_is ""..."1.9" do
|
2
|
+
require "parsedate"
|
3
|
+
|
4
|
+
describe "ParseDate.parsedate" do
|
5
|
+
it "returns Array of 8 nils given an empty String" do
|
6
|
+
ParseDate.parsedate("").should == [nil] * 8
|
7
|
+
end
|
8
|
+
|
9
|
+
it "raises TypeError given nil" do
|
10
|
+
lambda { ParseDate.parsedate(nil) }.should raise_error(TypeError)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "raises NoMethodError given Time" do
|
14
|
+
lambda { ParseDate.parsedate(Time.now) }.should raise_error(NoMethodError)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns Array with weekday number, given a full day name" do
|
18
|
+
ParseDate.parsedate("Sunday").should == [nil] * 7 + [0]
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns Array with weekday number, given a 3 letter day name" do
|
22
|
+
ParseDate.parsedate("mon").should == [nil] * 7 + [1]
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns Array with weekday number, given a String containing a word starting with day" do
|
26
|
+
ParseDate.parsedate("ignore friday monday ignore").should == [nil] * 7 + [5]
|
27
|
+
ParseDate.parsedate("ignorefriday").should == [nil] * 8
|
28
|
+
ParseDate.parsedate("fridayignore").should == [nil] * 7 + [5]
|
29
|
+
# friday, not monday!
|
30
|
+
ParseDate.parsedate("friends on monday").should == [nil] * 7 + [5]
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns Array of 8 nils, given a single digit String" do
|
34
|
+
ParseDate.parsedate("8").should == [nil] * 8
|
35
|
+
end
|
36
|
+
|
37
|
+
it "returns Array with day set, given a String of 2 digits" do
|
38
|
+
ParseDate.parsedate("08").should == [nil, nil] + [8] + [nil] * 5
|
39
|
+
ParseDate.parsedate("99").should == [nil, nil] + [99] + [nil] * 5
|
40
|
+
end
|
41
|
+
|
42
|
+
it "returns Array of 8 nils, given a String of 3 digits" do
|
43
|
+
ParseDate.parsedate("100").should == [nil] * 8
|
44
|
+
end
|
45
|
+
|
46
|
+
it "returns Array with month and day set, given a String of 4 digits" do
|
47
|
+
ParseDate.parsedate("1050").should == [nil] + [10,50] + [nil] * 5
|
48
|
+
end
|
49
|
+
|
50
|
+
it "returns Array with year set, given a String of 5 digits" do
|
51
|
+
ParseDate.parsedate("10500").should == [10] + [nil] * 7
|
52
|
+
end
|
53
|
+
|
54
|
+
it "returns Array with date fields set, given a String of 6 digits" do
|
55
|
+
ParseDate.parsedate("105070").should == [10, 50, 70] + [nil] * 5
|
56
|
+
end
|
57
|
+
|
58
|
+
it "returns Array with 4-digit year set, given a String of 7 digits" do
|
59
|
+
ParseDate.parsedate("1050701").should == [1050] + [nil] * 7
|
60
|
+
end
|
61
|
+
|
62
|
+
it "returns Array with date fields set, given a String of 8 digits" do
|
63
|
+
ParseDate.parsedate("10507011").should == [1050, 70, 11] + [nil] * 5
|
64
|
+
end
|
65
|
+
|
66
|
+
it "returns Array of 8 nils, given a odd-sized String of 9 or more digits" do
|
67
|
+
ParseDate.parsedate("123456789").should == [nil] * 8
|
68
|
+
ParseDate.parsedate("12345678901").should == [nil] * 8
|
69
|
+
end
|
70
|
+
|
71
|
+
it "returns Array with date & hour fields set, given a String of 10 digits" do
|
72
|
+
ParseDate.parsedate("1234567890").should == [1234, 56, 78, 90] + [nil] * 4
|
73
|
+
end
|
74
|
+
|
75
|
+
it "returns Array with date, hour & minute fields set, given a String of 12 digits" do
|
76
|
+
ParseDate.parsedate("123456789012").should == [1234, 56, 78, 90, 12] + [nil] * 3
|
77
|
+
end
|
78
|
+
|
79
|
+
it "returns Array with date & time fields set, given a String of 14 digits" do
|
80
|
+
ParseDate.parsedate("12345678901234").should == [1234, 56, 78, 90, 12, 34, nil, nil]
|
81
|
+
end
|
82
|
+
|
83
|
+
ruby_version_is ""..."1.8.7" do
|
84
|
+
it "returns Array with year and month set, given a String like nn-nn" do
|
85
|
+
ParseDate.parsedate("08-09").should == [8,9] + [nil] * 6
|
86
|
+
ParseDate.parsedate("08-09",true).should == [2008,9] + [nil] * 6
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
ruby_version_is "1.8.7" do
|
91
|
+
it "returns Array with year and month set, given a String like nn-nn" do
|
92
|
+
ParseDate.parsedate("08-09").should == [nil, nil, 8, nil, nil, nil, "-09", nil]
|
93
|
+
ParseDate.parsedate("08-09",true).should == [nil, nil, 8, nil, nil, nil, "-09", nil]
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
it "returns Array with day and hour set, given a String like n-nn" do
|
98
|
+
ParseDate.parsedate("8-09").should == [nil,nil] + [9,8] + [nil] * 4
|
99
|
+
end
|
100
|
+
|
101
|
+
it "returns Array with day and timezone set, given a String like nn-n" do
|
102
|
+
ParseDate.parsedate("08-9").should == [nil,nil,8,nil,nil,nil,"-9",nil]
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubysl-parsedate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brian Shirai
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rubysl-date
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.5'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.5'
|
69
|
+
description: Ruby standard library parsedate.
|
70
|
+
email:
|
71
|
+
- brixen@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .travis.yml
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- lib/parsedate.rb
|
83
|
+
- lib/rubysl/parsedate.rb
|
84
|
+
- lib/rubysl/parsedate/parsedate.rb
|
85
|
+
- lib/rubysl/parsedate/version.rb
|
86
|
+
- rubysl-parsedate.gemspec
|
87
|
+
- spec/parsedate_spec.rb
|
88
|
+
homepage: https://github.com/rubysl/rubysl-parsedate
|
89
|
+
licenses:
|
90
|
+
- BSD
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.0.7
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: Ruby standard library parsedate.
|
112
|
+
test_files:
|
113
|
+
- spec/parsedate_spec.rb
|