stamp 0.1.6 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +1 -1
- data/Gemfile.lock +8 -10
- data/README.md +9 -2
- data/features/stamp.feature +30 -3
- data/features/step_definitions/stamp_steps.rb +1 -3
- data/lib/stamp/translator.rb +20 -1
- data/lib/stamp/version.rb +1 -1
- metadata +51 -63
- data/.rvmrc +0 -1
- data/features/step_definitions/turtle_steps.rb +0 -5
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,24 +1,22 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
stamp (0.
|
4
|
+
stamp (0.2.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: http://rubygems.org/
|
8
8
|
specs:
|
9
9
|
builder (3.0.0)
|
10
|
-
cucumber (1.
|
10
|
+
cucumber (1.2.1)
|
11
11
|
builder (>= 2.1.2)
|
12
|
-
diff-lcs (>= 1.1.
|
13
|
-
gherkin (~> 2.
|
12
|
+
diff-lcs (>= 1.1.3)
|
13
|
+
gherkin (~> 2.11.0)
|
14
14
|
json (>= 1.4.6)
|
15
|
-
|
16
|
-
|
17
|
-
gherkin (2.4.1)
|
15
|
+
diff-lcs (1.1.3)
|
16
|
+
gherkin (2.11.2)
|
18
17
|
json (>= 1.4.6)
|
19
|
-
json (1.5
|
20
|
-
rake (0.9.2)
|
21
|
-
term-ansicolor (1.0.5)
|
18
|
+
json (1.7.5)
|
19
|
+
rake (0.9.2.2)
|
22
20
|
|
23
21
|
PLATFORMS
|
24
22
|
ruby
|
data/README.md
CHANGED
@@ -29,6 +29,13 @@ date.stamp("12/31/99") #=> "06/09/11"
|
|
29
29
|
date.stamp("DOB: 12/31/2000") #=> "DOB: 06/09/2011"
|
30
30
|
```
|
31
31
|
|
32
|
+
It even formats ordinal days!
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
date.stamp("November 5th") #=> "June 9th"
|
36
|
+
date.stamp("1st of Jan") #=> "9th of Jun"
|
37
|
+
```
|
38
|
+
|
32
39
|
### Times
|
33
40
|
|
34
41
|
`Time#stamp` supports the same kinds of examples as `Date`, but also formats
|
@@ -85,7 +92,7 @@ Time::DATE_FORMATS[:military] = Stamp.strftime_format("23:59")
|
|
85
92
|
To use your formats:
|
86
93
|
|
87
94
|
```ruby
|
88
|
-
Date.today.
|
95
|
+
Date.today.to_s(:short) #=> "Sat Jul 16"
|
89
96
|
Time.now.to_s(:military) #=> "15:35"
|
90
97
|
```
|
91
98
|
|
@@ -102,7 +109,7 @@ just be passed along:
|
|
102
109
|
|
103
110
|
```ruby
|
104
111
|
Date.today.stamp("Week #%U, 1999") #=> "Week #23, 2011"
|
105
|
-
|
112
|
+
```
|
106
113
|
|
107
114
|
Check out [http://strfti.me](http://strfti.me) for more ideas.
|
108
115
|
|
data/features/stamp.feature
CHANGED
@@ -9,7 +9,6 @@ Feature: Stamping a date
|
|
9
9
|
Given the date September 8, 2011
|
10
10
|
When I stamp the example "<example>"
|
11
11
|
Then I produce "<output>"
|
12
|
-
And I like turtles
|
13
12
|
|
14
13
|
Examples:
|
15
14
|
| example | output |
|
@@ -34,12 +33,41 @@ Feature: Stamping a date
|
|
34
33
|
| 1999-12-31 | 2011-09-08 |
|
35
34
|
| DOB: 12-31-1999 | DOB: 09-08-2011 |
|
36
35
|
|
36
|
+
@date
|
37
|
+
Scenario Outline: Formatting dates with ordinal days
|
38
|
+
Given the date <date>
|
39
|
+
When I stamp the example "<example>"
|
40
|
+
Then I produce "<output>"
|
41
|
+
|
42
|
+
Examples:
|
43
|
+
| date | example | output |
|
44
|
+
| Jan 1, 1999 | July 4th | January 1st |
|
45
|
+
| Jan 2, 1999 | Dec 3rd | Jan 2nd |
|
46
|
+
| Jan 3, 1999 | Dec 2nd | Jan 3rd |
|
47
|
+
| Jan 4, 1999 | Jul 1st | Jan 4th |
|
48
|
+
| Jan 5, 1999 | Dec 1st | Jan 5th |
|
49
|
+
| Jan 6, 1999 | Dec 1st | Jan 6th |
|
50
|
+
| Jan 7, 1999 | Dec 1st | Jan 7th |
|
51
|
+
| Jan 8, 1999 | Dec 1st | Jan 8th |
|
52
|
+
| Jan 9, 1999 | Dec 1st | Jan 9th |
|
53
|
+
| Jan 10, 1999 | Dec 1st | Jan 10th |
|
54
|
+
| Jan 11, 1999 | Dec 1st | Jan 11th |
|
55
|
+
| Jan 12, 1999 | Dec 1st | Jan 12th |
|
56
|
+
| Jan 13, 1999 | Dec 1st | Jan 13th |
|
57
|
+
| Jan 14, 1999 | Dec 1st | Jan 14th |
|
58
|
+
| Jan 20, 1999 | Dec 1st | Jan 20th |
|
59
|
+
| Jan 21, 1999 | Dec 1st | Jan 21st |
|
60
|
+
| Jan 22, 1999 | Dec 1st | Jan 22nd |
|
61
|
+
| Jan 23, 1999 | Dec 1st | Jan 23rd |
|
62
|
+
| Jan 24, 1999 | Dec 1st | Jan 24th |
|
63
|
+
| Jan 1, 1999 | 4th of July | 1st of January |
|
64
|
+
| Jan 1, 1999 | 4th of July, 1999 | 1st of January, 1999 |
|
65
|
+
|
37
66
|
@time
|
38
67
|
Scenario Outline: Formatting times by example
|
39
68
|
Given the time September 8, 2011 at 13:31:27
|
40
69
|
When I stamp the example "<example>"
|
41
70
|
Then I produce "<output>"
|
42
|
-
And I like turtles
|
43
71
|
|
44
72
|
Examples:
|
45
73
|
| example | output |
|
@@ -59,7 +87,6 @@ Feature: Stamping a date
|
|
59
87
|
Given the time September 8, 2011 at 13:31:27
|
60
88
|
When I stamp the example "<example>"
|
61
89
|
Then I produce "<output>"
|
62
|
-
And I like turtles
|
63
90
|
|
64
91
|
Examples:
|
65
92
|
| example | output |
|
@@ -1,8 +1,6 @@
|
|
1
1
|
module StampStepHelpers
|
2
2
|
def month(month_name)
|
3
|
-
|
4
|
-
assert (1..12).include?(month), "Invalid month: #{month_name}"
|
5
|
-
return month
|
3
|
+
Date::MONTHNAMES.index(month_name) || Date::ABBR_MONTHNAMES.index(month_name)
|
6
4
|
end
|
7
5
|
end
|
8
6
|
World(StampStepHelpers)
|
data/lib/stamp/translator.rb
CHANGED
@@ -14,10 +14,12 @@ module Stamp
|
|
14
14
|
MERIDIAN_LOWER_REGEXP = /^(a|p)m$/
|
15
15
|
MERIDIAN_UPPER_REGEXP = /^(A|P)M$/
|
16
16
|
|
17
|
+
ORDINAL_DAY_REGEXP = /^(\d{1,2})(st|nd|rd|th)$/
|
18
|
+
|
17
19
|
# Disambiguate based on value
|
18
20
|
OBVIOUS_YEARS = 60..99
|
19
21
|
OBVIOUS_MONTHS = 12
|
20
|
-
OBVIOUS_DAYS =
|
22
|
+
OBVIOUS_DAYS = 24..31
|
21
23
|
OBVIOUS_24_HOUR = 13..23
|
22
24
|
|
23
25
|
TWO_DIGIT_DATE_SUCCESSION = {
|
@@ -39,6 +41,20 @@ module Stamp
|
|
39
41
|
@target = target_date_or_time
|
40
42
|
end
|
41
43
|
|
44
|
+
# Cribbed from ActiveSupport to format ordinal days (1st, 2nd, 23rd etc).
|
45
|
+
def ordinalize(number)
|
46
|
+
if (11..13).include?(number.to_i % 100)
|
47
|
+
"#{number}th"
|
48
|
+
else
|
49
|
+
case number.to_i % 10
|
50
|
+
when 1; "#{number}st"
|
51
|
+
when 2; "#{number}nd"
|
52
|
+
when 3; "#{number}rd"
|
53
|
+
else "#{number}th"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
42
58
|
def translate(example)
|
43
59
|
# extract any substrings that look like times, like "23:59" or "8:37 am"
|
44
60
|
before, time_example, after = example.partition(TIME_REGEXP)
|
@@ -115,6 +131,9 @@ module Stamp
|
|
115
131
|
when FOUR_DIGIT_REGEXP
|
116
132
|
'%Y'
|
117
133
|
|
134
|
+
when ORDINAL_DAY_REGEXP
|
135
|
+
ordinalize(@target.day)
|
136
|
+
|
118
137
|
when TWO_DIGIT_REGEXP
|
119
138
|
# try to discern obvious intent based on the example value
|
120
139
|
case token.to_i
|
data/lib/stamp/version.rb
CHANGED
metadata
CHANGED
@@ -1,60 +1,57 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: stamp
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 1
|
8
|
-
- 6
|
9
|
-
version: 0.1.6
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Jeremy Weiskotten
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-09-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: cucumber
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
- 0
|
30
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
31
22
|
type: :development
|
32
|
-
version_requirements: *id001
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: rake
|
35
23
|
prerelease: false
|
36
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
25
|
none: false
|
38
|
-
requirements:
|
39
|
-
- -
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
|
42
|
-
|
43
|
-
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
44
38
|
type: :development
|
45
|
-
|
46
|
-
|
47
|
-
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Format dates and times based on human-friendly examples, not arcane strftime
|
47
|
+
directives.
|
48
|
+
email:
|
48
49
|
- jeremy@weiskotten.com
|
49
50
|
executables: []
|
50
|
-
|
51
51
|
extensions: []
|
52
|
-
|
53
52
|
extra_rdoc_files: []
|
54
|
-
|
55
|
-
files:
|
53
|
+
files:
|
56
54
|
- .gitignore
|
57
|
-
- .rvmrc
|
58
55
|
- .travis.yml
|
59
56
|
- .yardopts
|
60
57
|
- Gemfile
|
@@ -65,46 +62,37 @@ files:
|
|
65
62
|
- cucumber.yml
|
66
63
|
- features/stamp.feature
|
67
64
|
- features/step_definitions/stamp_steps.rb
|
68
|
-
- features/step_definitions/turtle_steps.rb
|
69
65
|
- features/support/env.rb
|
70
66
|
- lib/stamp.rb
|
71
67
|
- lib/stamp/translator.rb
|
72
68
|
- lib/stamp/version.rb
|
73
69
|
- stamp.gemspec
|
74
|
-
has_rdoc: true
|
75
70
|
homepage: https://github.com/jeremyw/stamp
|
76
71
|
licenses: []
|
77
|
-
|
78
72
|
post_install_message:
|
79
73
|
rdoc_options: []
|
80
|
-
|
81
|
-
require_paths:
|
74
|
+
require_paths:
|
82
75
|
- lib
|
83
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
77
|
none: false
|
85
|
-
requirements:
|
86
|
-
- -
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
|
89
|
-
|
90
|
-
version: "0"
|
91
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
83
|
none: false
|
93
|
-
requirements:
|
94
|
-
- -
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
|
97
|
-
- 0
|
98
|
-
version: "0"
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
99
88
|
requirements: []
|
100
|
-
|
101
89
|
rubyforge_project:
|
102
|
-
rubygems_version: 1.
|
90
|
+
rubygems_version: 1.8.24
|
103
91
|
signing_key:
|
104
92
|
specification_version: 3
|
105
93
|
summary: Date and time formatting for humans.
|
106
|
-
test_files:
|
94
|
+
test_files:
|
107
95
|
- features/stamp.feature
|
108
96
|
- features/step_definitions/stamp_steps.rb
|
109
|
-
- features/step_definitions/turtle_steps.rb
|
110
97
|
- features/support/env.rb
|
98
|
+
has_rdoc:
|
data/.rvmrc
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
rvm use 1.9.2@stamp
|