fluid-time 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +14 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +77 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/fluid-time.gemspec +63 -0
- data/lib/fluid-time.rb +313 -0
- data/spec/fluid-time_spec.rb +17 -0
- data/spec/spec_helper.rb +12 -0
- metadata +155 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# April 12, 2012 @ 09:22 AM PDT
|
2
|
+
```ruby
|
3
|
+
FluidTime.new('2012/04/12 9:22').month.day.th.sc.ss.year.txt('@').time.xz.pm.zone.to_s
|
4
|
+
```
|
5
|
+
|
6
|
+
Making it ready for the first release:
|
7
|
+
|
8
|
+
- Added xs - strips space (renamed from ns)
|
9
|
+
- Added xz - strips leading 0 or :00
|
10
|
+
- Removed aliases for times without leading zeros, use xz
|
11
|
+
- Now works outside of rails (.th doesn't work without it though)
|
12
|
+
- Added sp, sc, sl, sn, ss aliases for making symbols
|
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rspec", "~> 2.8.0"
|
10
|
+
gem "rdoc", "~> 3.12"
|
11
|
+
gem "bundler", "~> 1.0.0"
|
12
|
+
gem "jeweler", "~> 1.8.3"
|
13
|
+
gem "rcov", ">= 0"
|
14
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Steve Lawson
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
= fluid-time
|
2
|
+
|
3
|
+
Stop formatting time like a C-anderthal. Craft human readable time formats like building a sentence.
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
FluidTime.new.month.hour.tc.minute.tc.second
|
7
|
+
FluidTime.new(Date.today).weekday.month.year
|
8
|
+
```
|
9
|
+
|
10
|
+
Do things like strip zeros, ordinalize and change case with ease (ordinalize only works if you've included rails for now)
|
11
|
+
```ruby
|
12
|
+
FluidTime.new.time.pm.zone.to_s
|
13
|
+
# 09:51:29 PM PDT
|
14
|
+
|
15
|
+
FluidTime.new.time.xz.xs.pm.down.zone.to_s
|
16
|
+
# 9:51:51pm PDT
|
17
|
+
```
|
18
|
+
|
19
|
+
REMEMBER to end your chains with .to_s or use in a string "Today is #{FluidTime.new.weekday.upper}"
|
20
|
+
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
FluidTime.demo
|
24
|
+
# FluidTime.new. to_time.to_s Tue Apr 10 21:46:11 -0700 2012
|
25
|
+
# FluidTime.new. to_date.to_s 2012-04-10
|
26
|
+
# FluidTime.new. A.tday.weekday.to_s Tuesday Tuesday Tuesday
|
27
|
+
# FluidTime.new. weekday.up.to_s TUESDAY
|
28
|
+
# FluidTime.new. b.mmm.smonth.to_s Apr Apr Apr
|
29
|
+
# FluidTime.new. B.month.to_s April April
|
30
|
+
# FluidTime.new. c.to_s Tue Apr 10 21:46:11 2012
|
31
|
+
# FluidTime.new. full.to_s Tue Apr 10 21:46:11 2012
|
32
|
+
# FluidTime.new. d.day.num.dd.to_s 10 10 10 10
|
33
|
+
# FluidTime.new. e.mday.to_s 10 10
|
34
|
+
# FluidTime.new. mmm.d.th.year.to_s Apr 10 2012
|
35
|
+
# FluidTime.new. year.mmm.d.th.to_s 2012 Apr 10
|
36
|
+
# FluidTime.new. H.h24.hour24.to_s 21 21 21
|
37
|
+
# FluidTime.new. I.h12.hour.hour12.to_s 09 09 09 09
|
38
|
+
# FluidTime.new. l.to_s 9
|
39
|
+
# FluidTime.new. j.yday.day_of_year.to_s 101 101 101
|
40
|
+
# FluidTime.new. m.mm.mon.month_of_year.to_s 04 04 04 04
|
41
|
+
# FluidTime.new. M.min.minute.to_s 46 46 46
|
42
|
+
# FluidTime.new. p.am.pm.to_s PM PM PM
|
43
|
+
# FluidTime.new. time.xs.p.down.to_s 09:46:11pm
|
44
|
+
# FluidTime.new. S.sec.second.to_s 11 11 11
|
45
|
+
# FluidTime.new. U.th.txt('week').to_s 15 week
|
46
|
+
# FluidTime.new. W.th.tc.ts._('min').to_s 15, min
|
47
|
+
# FluidTime.new. w.to_s 2
|
48
|
+
# FluidTime.new. x.autodate.to_s 04/10/12 04/10/12
|
49
|
+
# FluidTime.new. X.autotime.to_s 21:46:11 21:46:11
|
50
|
+
# FluidTime.new. date.to_s 04/10/2012
|
51
|
+
# FluidTime.new. time.to_s 09:46:11
|
52
|
+
# FluidTime.new. y.yy.sy.to_s 12 12 12
|
53
|
+
# FluidTime.new. Y.year.to_s 2012 2012
|
54
|
+
# FluidTime.new. Z.zone.timezone.to_s PDT PDT PDT
|
55
|
+
# FluidTime.new. txt('01').xz.to_s 1
|
56
|
+
# FluidTime.new. txt('1:00').xz.xs.pm.lower.zone.to_s 1pm PDT
|
57
|
+
# FluidTime.new. _('braces').lb.lp.lc.rc.rp.rb.to_s braces[({})]
|
58
|
+
# FluidTime.new. _('symbols').lb.tp.ts.tc.ts.tn.ts.td.rb.to_s symbols[. , : -]
|
59
|
+
# FluidTime.new. _('symbols').lb.sp.ss.sc.ss.sn.ss.sd.rb.to_s symbols[. , : -]
|
60
|
+
# FluidTime.new. db.to_s 2012-04-10 21:09:11
|
61
|
+
```
|
62
|
+
|
63
|
+
== Contributing to fluid-time
|
64
|
+
|
65
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
66
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
67
|
+
* Fork the project.
|
68
|
+
* Start a feature/bugfix branch.
|
69
|
+
* Commit and push until you are happy with your contribution.
|
70
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
71
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
72
|
+
|
73
|
+
== Copyright
|
74
|
+
|
75
|
+
Copyright (c) 2012 Steve Lawson. See LICENSE.txt for
|
76
|
+
further details.
|
77
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "fluid-time"
|
18
|
+
gem.homepage = "http://github.com/smlsml/fluid-time"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{A fluent interface for formatting ruby time}
|
21
|
+
gem.description = %Q{Stop formatting time like a C-anderthal. Craft human readable time formats like building a sentence. FluidTime.new.month.hour.tc.minute.tc.second}
|
22
|
+
gem.email = "smlsml@gmail.com"
|
23
|
+
gem.authors = ["Steve Lawson"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rdoc/task'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "fluid-time #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.2
|
data/fluid-time.gemspec
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{fluid-time}
|
8
|
+
s.version = "0.1.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Steve Lawson"]
|
12
|
+
s.date = %q{2012-04-10}
|
13
|
+
s.description = %q{Stop formatting time like a C-anderthal. Craft human readable time formats like building a sentence. FluidTime.new.month.hour.tc.minute.tc.second}
|
14
|
+
s.email = %q{smlsml@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"CHANGELOG.md",
|
23
|
+
"Gemfile",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"fluid-time.gemspec",
|
29
|
+
"lib/fluid-time.rb",
|
30
|
+
"spec/fluid-time_spec.rb",
|
31
|
+
"spec/spec_helper.rb"
|
32
|
+
]
|
33
|
+
s.homepage = %q{http://github.com/smlsml/fluid-time}
|
34
|
+
s.licenses = ["MIT"]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubygems_version = %q{1.4.2}
|
37
|
+
s.summary = %q{A fluent interface for formatting ruby time}
|
38
|
+
|
39
|
+
if s.respond_to? :specification_version then
|
40
|
+
s.specification_version = 3
|
41
|
+
|
42
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
43
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
44
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
45
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
46
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
|
47
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
48
|
+
else
|
49
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
50
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
51
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
52
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
53
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
54
|
+
end
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
57
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
58
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
59
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
60
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
data/lib/fluid-time.rb
ADDED
@@ -0,0 +1,313 @@
|
|
1
|
+
require "date"
|
2
|
+
require "time"
|
3
|
+
|
4
|
+
class FluidTime
|
5
|
+
|
6
|
+
def initialize(input = Time.now)
|
7
|
+
@build = ""
|
8
|
+
@last_was_space = false
|
9
|
+
|
10
|
+
@time = nil
|
11
|
+
@time = input if input.is_a?(Time)
|
12
|
+
@time = input.to_time if input.is_a?(Date) && input.methods.include?(:to_time)
|
13
|
+
@time = Time.parse(input.to_s) if @time.nil?
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.demo
|
17
|
+
%w{
|
18
|
+
to_time
|
19
|
+
to_date
|
20
|
+
A.tday.weekday
|
21
|
+
weekday.up
|
22
|
+
b.mmm.smonth
|
23
|
+
B.month
|
24
|
+
c
|
25
|
+
full
|
26
|
+
d.day.num.dd
|
27
|
+
e.mday
|
28
|
+
mmm.d.th.year
|
29
|
+
year.mmm.d.th
|
30
|
+
H.h24.hour24
|
31
|
+
I.h12.hour.hour12
|
32
|
+
l
|
33
|
+
j.yday.day_of_year
|
34
|
+
m.mm.mon.month_of_year
|
35
|
+
M.min.minute
|
36
|
+
p.am.pm
|
37
|
+
time.xs.p.down
|
38
|
+
S.sec.second
|
39
|
+
U.th.txt('week')
|
40
|
+
W.th.tc.ts._('min')
|
41
|
+
w
|
42
|
+
x.autodate
|
43
|
+
X.autotime
|
44
|
+
date
|
45
|
+
time
|
46
|
+
y.yy.sy
|
47
|
+
Y.year
|
48
|
+
Z.zone.timezone
|
49
|
+
txt('01').xz
|
50
|
+
txt('1:00').xz.xs.pm.lower.zone
|
51
|
+
_('braces').lb.lp.lc.rc.rp.rb
|
52
|
+
_('symbols').lb.tp.ts.tc.ts.tn.ts.td.rb
|
53
|
+
_('symbols').lb.sp.ss.sc.ss.sn.ss.sd.rb
|
54
|
+
db
|
55
|
+
}.each {|ex| "FluidTime.new. #{ex}.to_s".tap {|str| p str + (" %#{80 - str.length}s" % eval(str))} }
|
56
|
+
nil
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
##### Helpers
|
61
|
+
|
62
|
+
|
63
|
+
def to_s
|
64
|
+
hold = @build.strip
|
65
|
+
@build = ""
|
66
|
+
'' == hold ? @time.to_s : hold
|
67
|
+
end
|
68
|
+
|
69
|
+
def to_time
|
70
|
+
@time
|
71
|
+
end
|
72
|
+
|
73
|
+
def to_date
|
74
|
+
Date.new(@time.year, @time.month, @time.day)
|
75
|
+
end
|
76
|
+
|
77
|
+
def <=>(o)
|
78
|
+
self.to_s <=> o.to_s
|
79
|
+
end
|
80
|
+
|
81
|
+
def cat(str, sep = ' ')
|
82
|
+
@last_was_space = ' ' == str
|
83
|
+
@build += str.to_s + sep
|
84
|
+
self
|
85
|
+
end
|
86
|
+
alias :txt :cat
|
87
|
+
alias :_ :cat
|
88
|
+
|
89
|
+
|
90
|
+
##### Formats
|
91
|
+
|
92
|
+
def a; cat @time.strftime('%a') end # %a - The abbreviated weekday name (``Sun'')
|
93
|
+
alias :ddd :a
|
94
|
+
alias :wday :a
|
95
|
+
|
96
|
+
|
97
|
+
def A; cat @time.strftime('%A') end # %A - The full weekday name (``Sunday'')
|
98
|
+
alias :weekday :A
|
99
|
+
alias :tday :A
|
100
|
+
|
101
|
+
|
102
|
+
def b; cat @time.strftime('%b') end # %b - The abbreviated month name (``Jan'')
|
103
|
+
alias :mmm :b
|
104
|
+
alias :smonth :b
|
105
|
+
|
106
|
+
|
107
|
+
def B; cat @time.strftime('%B') end # %B - The full month name (``January'')
|
108
|
+
alias :month :B
|
109
|
+
|
110
|
+
|
111
|
+
def c; cat @time.strftime('%c') end # %c - The preferred local date and time representation
|
112
|
+
alias :full :c
|
113
|
+
|
114
|
+
|
115
|
+
def d; cat @time.strftime('%d') end # %d - Day of the month (01..31)
|
116
|
+
alias :dd :d
|
117
|
+
alias :day :d
|
118
|
+
alias :num :d
|
119
|
+
|
120
|
+
|
121
|
+
def e; cat @time.strftime('%e') end # %e - Day of the month (1..31)
|
122
|
+
alias :mday :e # included for completeness, should use day.xz (strip zero)
|
123
|
+
|
124
|
+
|
125
|
+
def H; cat @time.strftime('%H') end # %H - Hour of the day, 24-hour clock (00..23)
|
126
|
+
alias :h24 :H # use h24.xz to remove leading zero
|
127
|
+
alias :hour :H
|
128
|
+
alias :hour24 :H
|
129
|
+
|
130
|
+
|
131
|
+
def I; cat @time.strftime('%I') end # %I - Hour of the day, 12-hour clock (01..12)
|
132
|
+
alias :h12 :I # use h12.xz to remove leading zero
|
133
|
+
alias :hour :I
|
134
|
+
alias :hour12 :I
|
135
|
+
|
136
|
+
|
137
|
+
def l; cat @time.strftime('%l') end # %l - hour, 12-hour clock, blank-padded ( 0..12)
|
138
|
+
# included for completeness, should just use hour.xz (strip zero)
|
139
|
+
|
140
|
+
|
141
|
+
def j; cat @time.strftime('%j') end # %j - Day of the year (001..366)
|
142
|
+
alias :yday :j
|
143
|
+
alias :day_of_year :j
|
144
|
+
|
145
|
+
|
146
|
+
def m; cat @time.strftime('%m') end # %m - Month of the year (01..12)
|
147
|
+
alias :mm :m
|
148
|
+
alias :mon :m
|
149
|
+
alias :month_of_year :m
|
150
|
+
|
151
|
+
|
152
|
+
def M; cat @time.strftime('%M') end # %M - Minute of the hour (00..59)
|
153
|
+
alias :min :M
|
154
|
+
alias :minute :M
|
155
|
+
|
156
|
+
|
157
|
+
def p; cat @time.strftime('%p') end # %p - Meridian indicator (``AM'' or ``PM'')
|
158
|
+
alias :om :p
|
159
|
+
alias :am :p
|
160
|
+
alias :pm :p
|
161
|
+
|
162
|
+
|
163
|
+
def S; cat @time.strftime('%S') end # %S - Second of the minute (00..60)
|
164
|
+
alias :sec :S
|
165
|
+
alias :second :S
|
166
|
+
|
167
|
+
|
168
|
+
def U; cat @time.strftime('%U') end # %U - Week number of the current year,
|
169
|
+
# starting with the first Sunday
|
170
|
+
# as the first day
|
171
|
+
# of the first week (00..53)
|
172
|
+
|
173
|
+
|
174
|
+
def W; cat @time.strftime('%W') end # %W - Week number of the current year,
|
175
|
+
# starting with the first Monday
|
176
|
+
# as the first day
|
177
|
+
# of the first week (00..53)
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
def w; cat @time.strftime('%w') end # %w - Day of the week (Sunday is 0, 0..6)
|
182
|
+
|
183
|
+
|
184
|
+
def x; cat @time.strftime('%x') end # %x - Preferred representation for the date alone, no time
|
185
|
+
alias :autodate :x
|
186
|
+
|
187
|
+
|
188
|
+
def X; cat @time.strftime('%X') end # %X - Preferred representation for the time alone, no date
|
189
|
+
alias :autotime :X
|
190
|
+
|
191
|
+
|
192
|
+
def y; cat @time.strftime('%y') end # %y - Year without a century (00..99)
|
193
|
+
alias :yy :y
|
194
|
+
alias :sy :y
|
195
|
+
|
196
|
+
|
197
|
+
def Y; cat @time.strftime('%Y') end # %Y - Year with century
|
198
|
+
alias :year :Y
|
199
|
+
|
200
|
+
|
201
|
+
def Z; cat @time.strftime('%Z') end # %Z - Time zone name
|
202
|
+
alias :zone :Z
|
203
|
+
alias :timezone :Z
|
204
|
+
|
205
|
+
|
206
|
+
##### Modifiers
|
207
|
+
|
208
|
+
def th
|
209
|
+
@build = @build.strip.split.tap do |parts|
|
210
|
+
parts << parts.pop.tap { |last| last.replace(ordinalize(last)) }
|
211
|
+
end.join(' ') + ' '
|
212
|
+
self
|
213
|
+
end
|
214
|
+
|
215
|
+
def ytt
|
216
|
+
@build = @build.gsub('-', '/').split.tap do |parts|
|
217
|
+
parts.each_with_index do |part, index|
|
218
|
+
date = Date.parse(part) rescue nil
|
219
|
+
parts[index] = 'Today' if date.is_a?(Date) && date.to_s == Date.today.to_s
|
220
|
+
parts[index] = 'Tomorrow' if date.is_a?(Date) && date.to_s == Date.tomorrow.to_s
|
221
|
+
parts[index] = 'Yesterday' if date.is_a?(Date) && date.to_s == Date.yesterday.to_s
|
222
|
+
end
|
223
|
+
end.join(' ') + ' '
|
224
|
+
self
|
225
|
+
end
|
226
|
+
|
227
|
+
def down
|
228
|
+
@build = @build.split.tap { |parts| parts << parts.pop.downcase }.join(' ') + ' '
|
229
|
+
self
|
230
|
+
end
|
231
|
+
alias :lower :down
|
232
|
+
|
233
|
+
def up
|
234
|
+
@build = @build.split.tap { |parts| parts << parts.pop.upcase }.join(' ') + ' '
|
235
|
+
self
|
236
|
+
end
|
237
|
+
alias :upper :up
|
238
|
+
|
239
|
+
def strip_zero
|
240
|
+
@build = @build.strip.split.tap do |parts|
|
241
|
+
parts << parts.pop.tap { |last| last.replace(last.gsub(/^0/,'').gsub(':00','')) }
|
242
|
+
end.join(' ') + ' '
|
243
|
+
self
|
244
|
+
end
|
245
|
+
alias :xz :strip_zero
|
246
|
+
|
247
|
+
def strip
|
248
|
+
@build.strip! unless @last_was_space
|
249
|
+
self
|
250
|
+
end
|
251
|
+
alias :xs :strip
|
252
|
+
|
253
|
+
|
254
|
+
##### Symbols (couldn't decide between: t for text and s for symbol)
|
255
|
+
|
256
|
+
def space; txt ' ','' end; alias :ts :space; alias :ss :space
|
257
|
+
def period; xs.txt '.', '' end; alias :tp :period; alias :sp :period
|
258
|
+
def comma; xs.txt ',', '' end; alias :tc :comma; alias :sc :comma
|
259
|
+
def colon; xs.txt ':', '' end; alias :tn :colon; alias :sn :colon
|
260
|
+
def dash; xs.txt '-', '' end; alias :td :dash; alias :sd :dash
|
261
|
+
def slash; xs.txt '/', '' end; alias :tl :slash; alias :sl :slash
|
262
|
+
|
263
|
+
def lbrace; xs.txt '[', '' end; alias :lb :lbrace
|
264
|
+
def rbrace; xs.txt ']', '' end; alias :rb :rbrace
|
265
|
+
|
266
|
+
def lcurve; xs.txt '{', '' end; alias :lc :lcurve
|
267
|
+
def rcurve; xs.txt '}', '' end; alias :rc :rcurve
|
268
|
+
|
269
|
+
def lparen; xs.txt '(', '' end; alias :lp :lparen
|
270
|
+
def rparen; xs.txt ')', '' end; alias :rp :rparen
|
271
|
+
|
272
|
+
|
273
|
+
##### Presets
|
274
|
+
|
275
|
+
def db
|
276
|
+
self.Y.td.m.td.d.H.tn.I.tn.S
|
277
|
+
end
|
278
|
+
|
279
|
+
def usdate
|
280
|
+
self.mm.tl.d.tl.Y
|
281
|
+
end
|
282
|
+
|
283
|
+
def Ymd
|
284
|
+
self.Y.xs.mm.xs.d
|
285
|
+
end
|
286
|
+
|
287
|
+
def Y_m_d
|
288
|
+
self.Y.td.mm.td.d
|
289
|
+
end
|
290
|
+
|
291
|
+
def time
|
292
|
+
self.hour.tn.minute.tn.second
|
293
|
+
end
|
294
|
+
|
295
|
+
def date
|
296
|
+
self.mon.sl.day.sl.year
|
297
|
+
end
|
298
|
+
|
299
|
+
#####
|
300
|
+
|
301
|
+
|
302
|
+
private
|
303
|
+
|
304
|
+
def numeric?(string)
|
305
|
+
true if Float(string) rescue false
|
306
|
+
end
|
307
|
+
|
308
|
+
def ordinalize(input)
|
309
|
+
numeric?(input) && input.to_i.methods.include?(:ordinalize) ? input.to_i.ordinalize : input
|
310
|
+
end
|
311
|
+
|
312
|
+
|
313
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "FluidTime" do
|
4
|
+
it "runs the demo" do
|
5
|
+
FluidTime.demo.should be_nil
|
6
|
+
end
|
7
|
+
|
8
|
+
it "can be initialized with a Date" do
|
9
|
+
today = Date.today
|
10
|
+
FluidTime.new(today).to_date.should eql(today)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "strips zeros" do
|
14
|
+
FluidTime.new.txt('01').xz.to_s.should eql('1')
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'fluid-time'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluid-time
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 31
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Steve Lawson
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-04-10 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
type: :development
|
23
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 47
|
29
|
+
segments:
|
30
|
+
- 2
|
31
|
+
- 8
|
32
|
+
- 0
|
33
|
+
version: 2.8.0
|
34
|
+
requirement: *id001
|
35
|
+
prerelease: false
|
36
|
+
name: rspec
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
type: :development
|
39
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 31
|
45
|
+
segments:
|
46
|
+
- 3
|
47
|
+
- 12
|
48
|
+
version: "3.12"
|
49
|
+
requirement: *id002
|
50
|
+
prerelease: false
|
51
|
+
name: rdoc
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
type: :development
|
54
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ~>
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 23
|
60
|
+
segments:
|
61
|
+
- 1
|
62
|
+
- 0
|
63
|
+
- 0
|
64
|
+
version: 1.0.0
|
65
|
+
requirement: *id003
|
66
|
+
prerelease: false
|
67
|
+
name: bundler
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
type: :development
|
70
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 49
|
76
|
+
segments:
|
77
|
+
- 1
|
78
|
+
- 8
|
79
|
+
- 3
|
80
|
+
version: 1.8.3
|
81
|
+
requirement: *id004
|
82
|
+
prerelease: false
|
83
|
+
name: jeweler
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
type: :development
|
86
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
hash: 3
|
92
|
+
segments:
|
93
|
+
- 0
|
94
|
+
version: "0"
|
95
|
+
requirement: *id005
|
96
|
+
prerelease: false
|
97
|
+
name: rcov
|
98
|
+
description: Stop formatting time like a C-anderthal. Craft human readable time formats like building a sentence. FluidTime.new.month.hour.tc.minute.tc.second
|
99
|
+
email: smlsml@gmail.com
|
100
|
+
executables: []
|
101
|
+
|
102
|
+
extensions: []
|
103
|
+
|
104
|
+
extra_rdoc_files:
|
105
|
+
- LICENSE.txt
|
106
|
+
- README.rdoc
|
107
|
+
files:
|
108
|
+
- .document
|
109
|
+
- .rspec
|
110
|
+
- CHANGELOG.md
|
111
|
+
- Gemfile
|
112
|
+
- LICENSE.txt
|
113
|
+
- README.rdoc
|
114
|
+
- Rakefile
|
115
|
+
- VERSION
|
116
|
+
- fluid-time.gemspec
|
117
|
+
- lib/fluid-time.rb
|
118
|
+
- spec/fluid-time_spec.rb
|
119
|
+
- spec/spec_helper.rb
|
120
|
+
has_rdoc: true
|
121
|
+
homepage: http://github.com/smlsml/fluid-time
|
122
|
+
licenses:
|
123
|
+
- MIT
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
hash: 3
|
135
|
+
segments:
|
136
|
+
- 0
|
137
|
+
version: "0"
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
none: false
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
hash: 3
|
144
|
+
segments:
|
145
|
+
- 0
|
146
|
+
version: "0"
|
147
|
+
requirements: []
|
148
|
+
|
149
|
+
rubyforge_project:
|
150
|
+
rubygems_version: 1.4.2
|
151
|
+
signing_key:
|
152
|
+
specification_version: 3
|
153
|
+
summary: A fluent interface for formatting ruby time
|
154
|
+
test_files: []
|
155
|
+
|