drexed-datetime 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +56 -2
- data/app/helpers/datetime_helper.rb +111 -34
- data/lib/drexed/datetime.rb +22 -1
- data/lib/drexed/datetime/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3195a371e9617f1f20167177fca7ca21dc45c9c
|
4
|
+
data.tar.gz: 0c580bf728a2d7f879644bad6006c6bf48b5ca39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5b90092e40de110084dbd9ebf98c4f1127c48ff924fa1767819e92d68ed342de6def65f29dee9bcfd21f226f61b3bc29a9829a7e781fa0a0e3a77bafbce5851
|
7
|
+
data.tar.gz: a9ae676beb47202dcd0ec1eac13882d5fd017555be1b04431cd192ff66cb0b61eb7ce350d1f57f2c3d3187a72084326ec1fc042b51b3aeee39df1f4186e73b22
|
data/README.md
CHANGED
@@ -16,8 +16,62 @@ Or install it yourself as:
|
|
16
16
|
|
17
17
|
$ gem install drexed-datetime
|
18
18
|
|
19
|
-
##
|
19
|
+
## Datetime helpers
|
20
20
|
|
21
21
|
```ruby
|
22
22
|
<%= date_for(@variable.created_at) %>
|
23
|
-
```
|
23
|
+
```
|
24
|
+
|
25
|
+
| Helper | `strftime` equivalent |
|
26
|
+
| --- | --- |
|
27
|
+
| year_for | 2013 |
|
28
|
+
| month_name_for | December |
|
29
|
+
| abbr_month_name_for | Dec |
|
30
|
+
| day_number_for | 5 |
|
31
|
+
| day_name_for | Friday |
|
32
|
+
| abbr_day_name_for | Fri |
|
33
|
+
| twelve_hour_time_for | 07:13 PM |
|
34
|
+
| twelve_hour_time_with_timezone_for | 07:13 PM EST |
|
35
|
+
| twenty_four_hour_time_for | 19:12 |
|
36
|
+
| twenty_four_hour_time_with_timezone_for | 19:12 EST |
|
37
|
+
| month_day_and_time_for | December 4 at 07:11 PM |
|
38
|
+
| abbr_month_day_and_time_for | Dec 4 at 07:11 PM |
|
39
|
+
| month_day_and_time_with_timezone_for | December 4 at 07:11 PM EST |
|
40
|
+
| abbr_month_day_and_time_with_timezone_for | Dec 4 at 07:11 PM EST |
|
41
|
+
| datetime_for | December 4, 2013 at 07:11 PM |
|
42
|
+
| abbr_datetime_for | Dec 4, 2013 at 07:17 PM |
|
43
|
+
| datetime_with_timezone_for | December 4, 2013 at 07:11 PM EST |
|
44
|
+
| abbr_datetime_with_timezone_for | Dec 4, 2013 at 07:17 PM EST |
|
45
|
+
| date_for | December 4, 2013 |
|
46
|
+
| abbr_date_for | Dec 4, 2013 |
|
47
|
+
| month_and_day_for | December 4 |
|
48
|
+
| abbr_month_and_day_for | Dec 4 |
|
49
|
+
| timezone_name_for | EST |
|
50
|
+
|
51
|
+
## Datetime formatter
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
Time.now.datetime_to("yyyy-mm-dd") => "2012-03-04"
|
55
|
+
Time.now.datetime_to("M d, yy") => "Mar 4, 12"
|
56
|
+
Time.now.datetime_to("hh:mi p") => "02:06 pm"
|
57
|
+
```
|
58
|
+
|
59
|
+
| Format string | `strftime` equivalent | Output for `t` |
|
60
|
+
| --- | --- | --- |
|
61
|
+
| "yyyy" | "%Y"| 2013|
|
62
|
+
| "yy" | "%y"| 13|
|
63
|
+
| "mm" | "%m" | 03 |
|
64
|
+
| "m" | "%-m" | 3 |
|
65
|
+
| "MM" | "%B" | March |
|
66
|
+
| "M" | "%b" | Mar |
|
67
|
+
| "dd" | "%d" | 04 |
|
68
|
+
| "d" | "%-d" | 4 |
|
69
|
+
| "DD" | "%A" | Sunday |
|
70
|
+
| "D" | "%a" | Sun |
|
71
|
+
| "hh" | "%I" | 02 |
|
72
|
+
| "h" | "%l" | 2 |
|
73
|
+
| "HH" | "%H" | 14 |
|
74
|
+
| "H" | "%-H" | 14 |
|
75
|
+
| "mi" | "%M" | 06 |
|
76
|
+
| "p" | "%P" | pm |
|
77
|
+
| "P" | "%p" | PM |
|
@@ -1,83 +1,160 @@
|
|
1
1
|
module DatetimeHelper
|
2
|
-
|
3
|
-
|
2
|
+
|
3
|
+
## Ex. 2013
|
4
|
+
def year_for(tach)
|
4
5
|
unless tach.blank?
|
5
|
-
tach.strftime("%
|
6
|
+
tach.strftime("%Y")
|
6
7
|
end
|
7
8
|
end
|
8
|
-
|
9
|
-
|
9
|
+
|
10
|
+
## Ex. December
|
11
|
+
def month_name_for(tach)
|
10
12
|
unless tach.blank?
|
11
|
-
tach.strftime("%B
|
13
|
+
tach.strftime("%B")
|
12
14
|
end
|
13
15
|
end
|
14
|
-
|
15
|
-
|
16
|
+
|
17
|
+
## Ex. Dec
|
18
|
+
def abbr_month_name_for(tach)
|
16
19
|
unless tach.blank?
|
17
|
-
tach.strftime("%
|
20
|
+
tach.strftime("%b")
|
18
21
|
end
|
19
22
|
end
|
20
|
-
|
21
|
-
|
23
|
+
|
24
|
+
## Ex. 4
|
25
|
+
def day_number_for(tach)
|
22
26
|
unless tach.blank?
|
23
|
-
tach.strftime("%
|
27
|
+
tach.strftime("%e")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
## Ex. Wednesday
|
32
|
+
def day_name_for(tach)
|
33
|
+
unless tach.blank?
|
34
|
+
tach.strftime("%A")
|
24
35
|
end
|
25
36
|
end
|
26
37
|
|
38
|
+
## Ex. Wed
|
39
|
+
def abbr_day_name_for(tach)
|
40
|
+
unless tach.blank?
|
41
|
+
tach.strftime("%a")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
## Ex. 07:13 PM
|
27
46
|
def twelve_hour_time_for(tach)
|
28
47
|
unless tach.blank?
|
29
48
|
tach.strftime("%I:%M %p")
|
30
49
|
end
|
31
50
|
end
|
32
|
-
|
33
|
-
|
51
|
+
|
52
|
+
## Ex. 07:13 PM EST
|
53
|
+
def twelve_hour_time_with_timezone_for(tach)
|
34
54
|
unless tach.blank?
|
35
|
-
tach.strftime("%
|
55
|
+
tach.strftime("%I:%M %p")
|
36
56
|
end
|
37
57
|
end
|
38
|
-
|
39
|
-
|
58
|
+
|
59
|
+
## Ex. 19:12
|
60
|
+
def twenty_four_hour_time_for(tach)
|
40
61
|
unless tach.blank?
|
41
|
-
tach.strftime("%
|
62
|
+
tach.strftime("%H:%M")
|
42
63
|
end
|
43
64
|
end
|
44
|
-
|
45
|
-
|
65
|
+
|
66
|
+
## Ex. 19:12 EST
|
67
|
+
def twenty_four_hour_time_with_timezone_for(tach)
|
46
68
|
unless tach.blank?
|
47
|
-
tach.strftime("%
|
69
|
+
tach.strftime("%H:%M %Z")
|
48
70
|
end
|
49
71
|
end
|
50
|
-
|
51
|
-
|
72
|
+
|
73
|
+
## Ex. December 4 at 07:11 PM
|
74
|
+
def month_day_and_time_for(tach)
|
52
75
|
unless tach.blank?
|
53
|
-
tach.strftime("%e")
|
76
|
+
tach.strftime("%B %e at %I:%M %p")
|
54
77
|
end
|
55
78
|
end
|
56
|
-
|
57
|
-
|
79
|
+
|
80
|
+
## Ex. Dec 4 at 07:11 PM
|
81
|
+
def abbr_month_day_and_time_for(tach)
|
58
82
|
unless tach.blank?
|
59
|
-
tach.strftime("%
|
83
|
+
tach.strftime("%b %e at %I:%M %p")
|
60
84
|
end
|
61
85
|
end
|
62
|
-
|
63
|
-
|
86
|
+
|
87
|
+
## Ex. December 4 at 07:11 PM EST
|
88
|
+
def month_day_and_time_with_timezone_for(tach)
|
64
89
|
unless tach.blank?
|
65
|
-
tach.strftime("%
|
90
|
+
tach.strftime("%B %e at %I:%M %p %Z")
|
66
91
|
end
|
67
92
|
end
|
68
|
-
|
93
|
+
|
94
|
+
## Ex. Dec 4 at 07:11 PM EST
|
95
|
+
def abbr_month_day_and_time_with_timezone_for(tach)
|
96
|
+
unless tach.blank?
|
97
|
+
tach.strftime("%b %e at %I:%M %p %Z")
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
## Ex. December 4, 2013 at 07:11 PM
|
102
|
+
def datetime_for(tach)
|
103
|
+
unless tach.blank?
|
104
|
+
tach.strftime("%B %e, %Y at %I:%M %p")
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
## Ex. Dec 4, 2013 at 07:11 PM
|
109
|
+
def abbr_datetime_for(tach)
|
110
|
+
unless tach.blank?
|
111
|
+
tach.strftime("%b %e, %Y at %I:%M %p")
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
## Ex. December 4, 2013 at 07:11 PM EST
|
116
|
+
def datetime_with_timezone_for(tach)
|
117
|
+
unless tach.blank?
|
118
|
+
tach.strftime("%B %e, %Y at %I:%M %p %Z")
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
## Ex. Dec 4, 2013 at 07:11 PM EST
|
123
|
+
def abbr_datetime_with_timezone_for(tach)
|
124
|
+
unless tach.blank?
|
125
|
+
tach.strftime("%b %e, %Y at %I:%M %p %Z")
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
## Ex. December 4, 2013
|
130
|
+
def date_for(tach)
|
131
|
+
unless tach.blank?
|
132
|
+
tach.strftime("%B %e, %Y")
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
## Ex. Dec 4, 2013
|
69
137
|
def abbr_date_for(tach)
|
70
138
|
unless tach.blank?
|
71
|
-
tach.strftime("%b %
|
139
|
+
tach.strftime("%b %e, %Y")
|
72
140
|
end
|
73
141
|
end
|
74
142
|
|
75
|
-
|
143
|
+
## Ex. December 4
|
144
|
+
def month_and_day_for(tach)
|
145
|
+
unless tach.blank?
|
146
|
+
tach.strftime("%B %e")
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
## Ex. Dec 4
|
151
|
+
def abbr_month_and_day_for(tach)
|
76
152
|
unless tach.blank?
|
77
|
-
tach.strftime("%b %
|
153
|
+
tach.strftime("%b %e")
|
78
154
|
end
|
79
155
|
end
|
80
156
|
|
157
|
+
## Ex. EST
|
81
158
|
def timezone_name_for(tach)
|
82
159
|
unless tach.blank?
|
83
160
|
tach.strftime("%Z")
|
data/lib/drexed/datetime.rb
CHANGED
@@ -2,7 +2,28 @@ require "drexed/datetime/version"
|
|
2
2
|
|
3
3
|
module Drexed
|
4
4
|
module Datetime
|
5
|
-
|
5
|
+
## Time.datetime_to("yyyy-mm-dd") => "2012-03-04"
|
6
|
+
def datetime_to(tach)
|
7
|
+
delineators = tach.scan /\W+/
|
8
|
+
formatters = tach.scan /[a-z]+/i
|
9
|
+
units = { "yy" => "y",
|
10
|
+
"yyyy" => "Y",
|
11
|
+
"m" => "-m",
|
12
|
+
"mm" => "m",
|
13
|
+
"M" => "b",
|
14
|
+
"MM" => "B",
|
15
|
+
"d" => "-d",
|
16
|
+
"dd" => "d",
|
17
|
+
"D" => "a",
|
18
|
+
"DD" => "A",
|
19
|
+
"h" => "-I",
|
20
|
+
"hh" => "I",
|
21
|
+
"H" => "-H",
|
22
|
+
"HH" => "H",
|
23
|
+
"mi" => "M",
|
24
|
+
"p" => "P",
|
25
|
+
"P" => "p" }
|
26
|
+
strftime(formatters.map{ |f| "%#{units[f]}#{delineators.shift || ""}" }.join)
|
6
27
|
end
|
7
28
|
end
|
8
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: drexed-datetime
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Gomez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|