fuzzytime 0.0.1.alpha
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/.gitignore +4 -0
- data/Gemfile +4 -0
- data/LICENSE +19 -0
- data/README.md +26 -0
- data/Rakefile +6 -0
- data/fuzzytime.gemspec +31 -0
- data/lib/fuzzytime/version.rb +3 -0
- data/lib/fuzzytime.rb +36 -0
- data/spec/fuzzytime_spec.rb +109 -0
- data/spec/spec_helper.rb +1 -0
- metadata +68 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2012 Paul Maki
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
7
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
8
|
+
so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
This simple gem outputs time in a "fuzzy" manner.
|
2
|
+
|
3
|
+
Note: this is my first gem so please do tell if you find anything wrong with it!
|
4
|
+
|
5
|
+
It takes the Time class as input or defaults to the current local time if no time is provided.
|
6
|
+
|
7
|
+
Example usage:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
require 'fuzzytime'
|
11
|
+
|
12
|
+
t = Time.local(2012,1,1,0,0)
|
13
|
+
Fuzzytime.fuzzy_time(t) => "midnight"
|
14
|
+
|
15
|
+
t = Time.local(2012,3,17,4,20)
|
16
|
+
Fuzzytime.fuzzy_time(t) => "20 past 4"
|
17
|
+
|
18
|
+
t = Time.local(2012,3,17,9,45)
|
19
|
+
Fuzzytime.fuzzy_time(t) => "quarter til 10"
|
20
|
+
|
21
|
+
t = Time.local(2012,1,1,12,0)
|
22
|
+
Fuzzytime.fuzzy_time(t) => "noon"
|
23
|
+
|
24
|
+
t = Time.local(2012,3,17,17,15)
|
25
|
+
Fuzzytime.fuzzy_time(t) => "quarter past 5"
|
26
|
+
```
|
data/Rakefile
ADDED
data/fuzzytime.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "fuzzytime/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "fuzzytime"
|
7
|
+
s.version = Fuzzytime::VERSION
|
8
|
+
s.authors = ["Paul Maki"]
|
9
|
+
s.email = ["paul.maki@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/paulmaki/fuzzytime"
|
11
|
+
s.summary = %q{Converts times into "fuzzy" output}
|
12
|
+
s.description = %q{
|
13
|
+
Sample output:
|
14
|
+
2:30AM => half past 2
|
15
|
+
7:50AM => 10 til 8
|
16
|
+
12:00PM => noon
|
17
|
+
5:15PM => quarter past 5
|
18
|
+
9:00PM => 9 o'clock
|
19
|
+
10:17PM => 17 past 10
|
20
|
+
12:00AM => midnight
|
21
|
+
}
|
22
|
+
|
23
|
+
s.rubyforge_project = "fuzzytime"
|
24
|
+
|
25
|
+
s.files = `git ls-files`.split("\n")
|
26
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
27
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
28
|
+
s.require_paths = ["lib"]
|
29
|
+
|
30
|
+
s.add_development_dependency "rspec"
|
31
|
+
end
|
data/lib/fuzzytime.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
#require "fuzzytime/version"
|
2
|
+
|
3
|
+
module Fuzzytime
|
4
|
+
|
5
|
+
def self.fuzzy_time(t = Time.now)
|
6
|
+
|
7
|
+
min = t.min
|
8
|
+
hour = t.hour
|
9
|
+
|
10
|
+
case min
|
11
|
+
when 0
|
12
|
+
when 1..30
|
13
|
+
rel = "past"
|
14
|
+
min = min
|
15
|
+
when 31..59
|
16
|
+
rel = "til"
|
17
|
+
min = 60 - min
|
18
|
+
hour = (hour + 1) % 24
|
19
|
+
end
|
20
|
+
|
21
|
+
min = "quarter" if min == 15
|
22
|
+
min = "half" if min == 30
|
23
|
+
|
24
|
+
case hour
|
25
|
+
when 0
|
26
|
+
hour = "midnight"
|
27
|
+
when 12
|
28
|
+
hour = "noon"
|
29
|
+
else
|
30
|
+
hour = hour % 12
|
31
|
+
suffix = t.min.zero? && hour.is_a?(Integer) ? "o'clock" : ""
|
32
|
+
end
|
33
|
+
|
34
|
+
"#{min} #{rel} #{hour} #{suffix}".strip
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Fuzzytime do
|
5
|
+
|
6
|
+
it "should display midnight correctly" do
|
7
|
+
t = Time.local(2012,1,1,0,0)
|
8
|
+
Fuzzytime.fuzzy_time(t).should include "midnight"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should display noon correctly" do
|
12
|
+
t = Time.local(2012,1,1,12,0)
|
13
|
+
Fuzzytime.fuzzy_time(t).should include "noon"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should display 5 past correctly" do
|
17
|
+
t = Time.local(2012,1,1,2,5)
|
18
|
+
Fuzzytime.fuzzy_time(t).should include "5 past"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should display 10 past correctly" do
|
22
|
+
t = Time.local(2012,1,1,12,10)
|
23
|
+
Fuzzytime.fuzzy_time(t).should include "10 past"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should display 15 past correctly" do
|
27
|
+
t = Time.local(2012,1,1,12,15)
|
28
|
+
Fuzzytime.fuzzy_time(t).should include "quarter"
|
29
|
+
Fuzzytime.fuzzy_time(t).should include "past"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should display 20 past correctly" do
|
33
|
+
t = Time.local(2012,1,1,2,20)
|
34
|
+
Fuzzytime.fuzzy_time(t).should include "20 past"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should display 25 past correctly" do
|
38
|
+
t = Time.local(2012,1,1,2,25)
|
39
|
+
Fuzzytime.fuzzy_time(t).should include "25 past"
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should display 30 past correctly" do
|
43
|
+
t = Time.local(2012,1,1,2,30)
|
44
|
+
Fuzzytime.fuzzy_time(t).should include("half past")
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should display 35 past correctly" do
|
48
|
+
t = Time.local(2012,1,1,2,35)
|
49
|
+
Fuzzytime.fuzzy_time(t).should include("25")
|
50
|
+
Fuzzytime.fuzzy_time(t).should include("til")
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should display 40 past correctly" do
|
54
|
+
t = Time.local(2012,1,1,1,40)
|
55
|
+
Fuzzytime.fuzzy_time(t).should include("20")
|
56
|
+
Fuzzytime.fuzzy_time(t).should include("til")
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should display 45 past correctly" do
|
60
|
+
t = Time.local(2012,1,1,1,45)
|
61
|
+
Fuzzytime.fuzzy_time(t).should include("quarter")
|
62
|
+
Fuzzytime.fuzzy_time(t).should include("til")
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should display 50 past correctly" do
|
66
|
+
t = Time.local(2012,1,1,1,50)
|
67
|
+
Fuzzytime.fuzzy_time(t).should include("10")
|
68
|
+
Fuzzytime.fuzzy_time(t).should include("til")
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should display 55 past correctly" do
|
72
|
+
t = Time.local(2012,1,1,1,55)
|
73
|
+
Fuzzytime.fuzzy_time(t).should include("5")
|
74
|
+
Fuzzytime.fuzzy_time(t).should include("til")
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should display 11:45am correctly" do
|
78
|
+
t = Time.local(2012,1,1,11,45)
|
79
|
+
Fuzzytime.fuzzy_time(t).should == "quarter til noon"
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should display 11:45pm correctly" do
|
83
|
+
t = Time.local(2012,1,1,23,45)
|
84
|
+
Fuzzytime.fuzzy_time(t).should == "quarter til midnight"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should display 12:15am correctly" do
|
88
|
+
t1 = Time.local(2012,1,1,0,15)
|
89
|
+
Fuzzytime.fuzzy_time(t1).should == "quarter past midnight"
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should display 12:15pm correctly" do
|
93
|
+
t1 = Time.local(2012,1,1,12,15)
|
94
|
+
Fuzzytime.fuzzy_time(t1).should == "quarter past noon"
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should display 5:15am and 5:15pm correctly" do
|
98
|
+
t1 = Time.local(2012,1,1,5,15)
|
99
|
+
t2 = Time.local(2012,1,1,17,15)
|
100
|
+
Fuzzytime.fuzzy_time(t1).should == "quarter past 5"
|
101
|
+
Fuzzytime.fuzzy_time(t2).should == "quarter past 5"
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should display 4:17pm correctly" do
|
105
|
+
t1 = Time.local(2012,1,1,16,17)
|
106
|
+
Fuzzytime.fuzzy_time(t1).should == "17 past 4"
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'fuzzytime'
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fuzzytime
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.alpha
|
5
|
+
prerelease: 6
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Paul Maki
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-14 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &17781440 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *17781440
|
25
|
+
description: ! "\n Sample output:\n 2:30AM => half past 2\n 7:50AM => 10
|
26
|
+
til 8\n 12:00PM => noon\n 5:15PM => quarter past 5\n 9:00PM => 9 o'clock\n
|
27
|
+
\ 10:17PM => 17 past 10\n 12:00AM => midnight\n "
|
28
|
+
email:
|
29
|
+
- paul.maki@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- .gitignore
|
35
|
+
- Gemfile
|
36
|
+
- LICENSE
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- fuzzytime.gemspec
|
40
|
+
- lib/fuzzytime.rb
|
41
|
+
- lib/fuzzytime/version.rb
|
42
|
+
- spec/fuzzytime_spec.rb
|
43
|
+
- spec/spec_helper.rb
|
44
|
+
homepage: https://github.com/paulmaki/fuzzytime
|
45
|
+
licenses: []
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>'
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.3.1
|
62
|
+
requirements: []
|
63
|
+
rubyforge_project: fuzzytime
|
64
|
+
rubygems_version: 1.8.10
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: Converts times into "fuzzy" output
|
68
|
+
test_files: []
|