fluid-time 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +49 -51
- data/VERSION +1 -1
- data/fluid-time.gemspec +2 -2
- data/lib/fluid-time.rb +29 -23
- metadata +5 -5
data/README.rdoc
CHANGED
@@ -1,64 +1,62 @@
|
|
1
|
-
|
1
|
+
== FluidTime
|
2
2
|
|
3
3
|
Stop formatting time like a C-anderthal. Craft human readable time formats like building a sentence.
|
4
4
|
|
5
|
-
|
6
|
-
FluidTime.new.
|
7
|
-
FluidTime.new(
|
8
|
-
```
|
5
|
+
FluidTime.new.month.hour.colon.minute.colon.second
|
6
|
+
FluidTime.new(Date.today).weekday.month.year
|
7
|
+
FluidTime.new('04/05/2012 09:45:23').weekday.month.year
|
9
8
|
|
10
9
|
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
10
|
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
|
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
18
|
|
19
19
|
REMEMBER to end your chains with .to_s or use in a string "Today is #{FluidTime.new.weekday.upper}"
|
20
20
|
|
21
|
+
FluidTime.demo
|
21
22
|
|
22
|
-
|
23
|
-
FluidTime.
|
24
|
-
# FluidTime.new.
|
25
|
-
# FluidTime.new.
|
26
|
-
# FluidTime.new.
|
27
|
-
# FluidTime.new.
|
28
|
-
# FluidTime.new.
|
29
|
-
# FluidTime.new.
|
30
|
-
# FluidTime.new.
|
31
|
-
# FluidTime.new.
|
32
|
-
# FluidTime.new. d.
|
33
|
-
# FluidTime.new.
|
34
|
-
# FluidTime.new.
|
35
|
-
# FluidTime.new.
|
36
|
-
# FluidTime.new.
|
37
|
-
# FluidTime.new.
|
38
|
-
# FluidTime.new.
|
39
|
-
# FluidTime.new.
|
40
|
-
# FluidTime.new.
|
41
|
-
# FluidTime.new.
|
42
|
-
# FluidTime.new.
|
43
|
-
# FluidTime.new.
|
44
|
-
# FluidTime.new.
|
45
|
-
# FluidTime.new.
|
46
|
-
# FluidTime.new.
|
47
|
-
# FluidTime.new.
|
48
|
-
# FluidTime.new.
|
49
|
-
# FluidTime.new.
|
50
|
-
# FluidTime.new.
|
51
|
-
# FluidTime.new.
|
52
|
-
# FluidTime.new.
|
53
|
-
# FluidTime.new.
|
54
|
-
# FluidTime.new.
|
55
|
-
# FluidTime.new.
|
56
|
-
# FluidTime.new.
|
57
|
-
# FluidTime.new. _('
|
58
|
-
# FluidTime.new.
|
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
|
-
```
|
23
|
+
# FluidTime.new. to_time.to_s Tue Apr 10 21:46:11 -0700 2012
|
24
|
+
# FluidTime.new. to_date.to_s 2012-04-10
|
25
|
+
# FluidTime.new. A.tday.weekday.to_s Tuesday Tuesday Tuesday
|
26
|
+
# FluidTime.new. weekday.up.to_s TUESDAY
|
27
|
+
# FluidTime.new. b.mmm.smonth.to_s Apr Apr Apr
|
28
|
+
# FluidTime.new. B.month.to_s April April
|
29
|
+
# FluidTime.new. c.to_s Tue Apr 10 21:46:11 2012
|
30
|
+
# FluidTime.new. full.to_s Tue Apr 10 21:46:11 2012
|
31
|
+
# FluidTime.new. d.day.num.dd.to_s 10 10 10 10
|
32
|
+
# FluidTime.new. e.mday.to_s 10 10
|
33
|
+
# FluidTime.new. mmm.d.th.year.to_s Apr 10 2012
|
34
|
+
# FluidTime.new. year.mmm.d.th.to_s 2012 Apr 10
|
35
|
+
# FluidTime.new. H.h24.hour24.to_s 21 21 21
|
36
|
+
# FluidTime.new. I.h12.hour.hour12.to_s 09 09 09 09
|
37
|
+
# FluidTime.new. l.to_s 9
|
38
|
+
# FluidTime.new. j.yday.day_of_year.to_s 101 101 101
|
39
|
+
# FluidTime.new. m.mm.mon.month_of_year.to_s 04 04 04 04
|
40
|
+
# FluidTime.new. M.min.minute.to_s 46 46 46
|
41
|
+
# FluidTime.new. p.am.pm.to_s PM PM PM
|
42
|
+
# FluidTime.new. time.xs.p.down.to_s 09:46:11pm
|
43
|
+
# FluidTime.new. S.sec.second.to_s 11 11 11
|
44
|
+
# FluidTime.new. U.th.txt('week').to_s 15 week
|
45
|
+
# FluidTime.new. W.th.tc.ts._('min').to_s 15, min
|
46
|
+
# FluidTime.new. w.to_s 2
|
47
|
+
# FluidTime.new. x.autodate.to_s 04/10/12 04/10/12
|
48
|
+
# FluidTime.new. X.autotime.to_s 21:46:11 21:46:11
|
49
|
+
# FluidTime.new. date.to_s 04/10/2012
|
50
|
+
# FluidTime.new. time.to_s 09:46:11
|
51
|
+
# FluidTime.new. y.yy.sy.to_s 12 12 12
|
52
|
+
# FluidTime.new. Y.year.to_s 2012 2012
|
53
|
+
# FluidTime.new. Z.zone.timezone.to_s PDT PDT PDT
|
54
|
+
# FluidTime.new. txt('01').xz.to_s 1
|
55
|
+
# FluidTime.new. txt('1:00').xz.xs.pm.lower.zone.to_s 1pm PDT
|
56
|
+
# FluidTime.new. _('braces').lb.lp.lc.rc.rp.rb.to_s braces[({})]
|
57
|
+
# FluidTime.new. _('symbols').lb.tp.ts.tc.ts.tn.ts.td.rb.to_s symbols[. , : -]
|
58
|
+
# FluidTime.new. _('symbols').lb.sp.ss.sc.ss.sn.ss.sd.rb.to_s symbols[. , : -]
|
59
|
+
# FluidTime.new. db.to_s 2012-04-10 21:09:11
|
62
60
|
|
63
61
|
== Contributing to fluid-time
|
64
62
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/fluid-time.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{fluid-time}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Steve Lawson"]
|
12
|
-
s.date = %q{2012-04-
|
12
|
+
s.date = %q{2012-04-11}
|
13
13
|
s.description = %q{Stop formatting time like a C-anderthal. Craft human readable time formats like building a sentence.
|
14
14
|
|
15
15
|
|
data/lib/fluid-time.rb
CHANGED
@@ -79,12 +79,17 @@ class FluidTime
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def cat(str, sep = ' ')
|
82
|
-
@last_was_space = ' ' == str
|
82
|
+
@last_was_space = ' ' == str.to_s
|
83
83
|
@build += str.to_s + sep
|
84
84
|
self
|
85
85
|
end
|
86
86
|
alias :txt :cat
|
87
87
|
alias :_ :cat
|
88
|
+
|
89
|
+
def set(str, sep = ' ')
|
90
|
+
@build = str.to_s + sep
|
91
|
+
self
|
92
|
+
end
|
88
93
|
|
89
94
|
|
90
95
|
##### Formats
|
@@ -206,41 +211,36 @@ class FluidTime
|
|
206
211
|
##### Modifiers
|
207
212
|
|
208
213
|
def th
|
209
|
-
@build
|
210
|
-
parts << parts.pop.tap { |last| last.replace(ordinalize(last)) }
|
211
|
-
end.join(' ')
|
212
|
-
self
|
214
|
+
set(@build.strip.split.tap do |parts|
|
215
|
+
parts << parts.pop.tap { |last| last.replace(numeric?(last) ? ordinalize(last) : last) }
|
216
|
+
end.join(' '))
|
213
217
|
end
|
214
218
|
|
215
219
|
def ytt
|
216
|
-
@build
|
220
|
+
set(@build.gsub('-', '/').split.tap do |parts|
|
217
221
|
parts.each_with_index do |part, index|
|
218
222
|
date = Date.parse(part) rescue nil
|
219
223
|
parts[index] = 'Today' if date.is_a?(Date) && date.to_s == Date.today.to_s
|
220
224
|
parts[index] = 'Tomorrow' if date.is_a?(Date) && date.to_s == Date.tomorrow.to_s
|
221
225
|
parts[index] = 'Yesterday' if date.is_a?(Date) && date.to_s == Date.yesterday.to_s
|
222
226
|
end
|
223
|
-
end.join(' ')
|
224
|
-
self
|
227
|
+
end.join(' '))
|
225
228
|
end
|
226
229
|
|
227
230
|
def down
|
228
|
-
@build
|
229
|
-
self
|
231
|
+
set(@build.split.tap {|parts| parts << parts.pop.downcase}.join(' '))
|
230
232
|
end
|
231
233
|
alias :lower :down
|
232
234
|
|
233
235
|
def up
|
234
|
-
@build
|
235
|
-
self
|
236
|
+
set(@build.split.tap {|parts| parts << parts.pop.upcase}.join(' '))
|
236
237
|
end
|
237
238
|
alias :upper :up
|
238
239
|
|
239
240
|
def strip_zero
|
240
|
-
@build
|
241
|
+
set(@build.strip.split.tap do |parts|
|
241
242
|
parts << parts.pop.tap { |last| last.replace(last.gsub(/^0/,'').gsub(':00','')) }
|
242
|
-
end.join(' ')
|
243
|
-
self
|
243
|
+
end.join(' '))
|
244
244
|
end
|
245
245
|
alias :xz :strip_zero
|
246
246
|
|
@@ -273,11 +273,11 @@ class FluidTime
|
|
273
273
|
##### Presets
|
274
274
|
|
275
275
|
def db
|
276
|
-
self.Y.
|
276
|
+
self.Y.dash.m.dash.d.H.colon.I.colon.S
|
277
277
|
end
|
278
278
|
|
279
279
|
def usdate
|
280
|
-
self.mm.
|
280
|
+
self.mm.slash.d.slash.Y
|
281
281
|
end
|
282
282
|
|
283
283
|
def Ymd
|
@@ -285,15 +285,15 @@ class FluidTime
|
|
285
285
|
end
|
286
286
|
|
287
287
|
def Y_m_d
|
288
|
-
self.Y.
|
288
|
+
self.Y.dash.mm.dash.d
|
289
289
|
end
|
290
290
|
|
291
291
|
def time
|
292
|
-
self.hour.
|
292
|
+
self.hour.colon.minute.colon.second
|
293
293
|
end
|
294
294
|
|
295
295
|
def date
|
296
|
-
self.mon.
|
296
|
+
self.mon.slash.day.slash.year
|
297
297
|
end
|
298
298
|
|
299
299
|
#####
|
@@ -305,9 +305,15 @@ class FluidTime
|
|
305
305
|
true if Float(string) rescue false
|
306
306
|
end
|
307
307
|
|
308
|
-
def ordinalize(
|
309
|
-
|
310
|
-
end
|
308
|
+
def ordinalize(number)
|
309
|
+
return "#{number}th" if (11..13).include?(number.to_i % 100)
|
311
310
|
|
311
|
+
case number.to_i % 10
|
312
|
+
when 1; "#{number}st"
|
313
|
+
when 2; "#{number}nd"
|
314
|
+
when 3; "#{number}rd"
|
315
|
+
else "#{number}th"
|
316
|
+
end
|
317
|
+
end
|
312
318
|
|
313
319
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluid-time
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Steve Lawson
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-04-
|
18
|
+
date: 2012-04-11 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|