semantic_date_time_tags 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd779a26b39abb5e57b3ee76930c189d9d9e4e4c
4
- data.tar.gz: 4319fc74b0cd79f290f4693a67c91f99543a8019
3
+ metadata.gz: fb0316eee2d0502118793403d13455ac95df6d4f
4
+ data.tar.gz: c57428b1211df6fc793f41e128af35e41c317c45
5
5
  SHA512:
6
- metadata.gz: d466220153da01be35c987bd981fa5610656b662188f92c0cc3c0d3941f8fcf23bae5e50f546432e848ba639db30ffaa1a572cee8ff194f0256eddcc4a394a88
7
- data.tar.gz: 7887bb40ffb2e659257b255c8eeaec1396f5345c58ac86a4e46d8e3973f83bb518cbe69259ba5cf36db9e0bfcc8deb7072a21b9011887ebf23635655b8f0ca8b
6
+ metadata.gz: d8e01cc7bd515255cd49e7aba68401eb07faa69200c64269cf88834a271e60a5d6edea6a7c9d3aec4d7178a2a9c785d61c4082f92277a673647a88bed1387eae
7
+ data.tar.gz: b59754e7a9f8174a7903fa37d76e9248d6d8d14ba77a0413e526dc23a04dd43fb5b3c715ca263a2d332f6c5b7e63db237051a4e2badc6d142eae22e02ebd6162
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- semantic_date_time_tags (0.1.4)
4
+ semantic_date_time_tags (0.1.5)
5
5
  rails (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -76,7 +76,7 @@ GEM
76
76
  domain_name (~> 0.5)
77
77
  i18n (0.7.0)
78
78
  json (1.8.3)
79
- listen (3.0.3)
79
+ listen (3.0.4)
80
80
  rb-fsevent (>= 0.9.3)
81
81
  rb-inotify (>= 0.9)
82
82
  loofah (2.0.3)
@@ -41,7 +41,7 @@ module SemanticDateTimeTags
41
41
  when /%-?[aAdej]/ then ['day', comp[/\w/]]
42
42
  when /%-?[HKIl]/ then ['hours', comp[/\w/]]
43
43
  when /%-?[M]/ then ['minutes', comp[/\w/]]
44
- when /%-?[p]/ then ['ampm', comp[/\w/]]
44
+ when /%-?[pP]/ then ['ampm', comp[/\w/]]
45
45
  when /\W+/ then ['sep']
46
46
  end
47
47
  end
@@ -40,6 +40,12 @@ module SemanticDateTimeTags
40
40
  date_from.year == ::Date.today.year
41
41
  end
42
42
 
43
+ def same_meridian?
44
+ return false unless same_day?
45
+ (date_from.to_time.hour < 12 && date_to.to_time.hour < 12) ||
46
+ (date_from.to_time.hour >= 12 && date_to.to_time.hour >= 12)
47
+ end
48
+
43
49
  # ---------------------------------------------------------------------
44
50
 
45
51
  def dom_classes
@@ -51,6 +57,7 @@ module SemanticDateTimeTags
51
57
  res << 'more_than_a_week' unless within_a_week?
52
58
  res << 'same_day' if same_day?
53
59
  res << 'same_time' if same_time?
60
+ res << 'same_meridian' if same_meridian?
54
61
  res
55
62
  end
56
63
 
@@ -29,6 +29,7 @@ module SemanticDateTimeTags
29
29
  def dom_classes
30
30
  [
31
31
  'semantic',
32
+ am_pm_class,
32
33
  type_class,
33
34
  current_date_class,
34
35
  current_year_class,
@@ -74,6 +75,14 @@ module SemanticDateTimeTags
74
75
  'midnight' if obj == obj.midnight
75
76
  end
76
77
 
78
+ def am_pm_class
79
+ return unless [::Time,::DateTime].any?{ |c| obj.instance_of? c }
80
+ case
81
+ when (0..11).include?(obj.hour) then 'am'
82
+ else 'pm'
83
+ end
84
+ end
85
+
77
86
  # ---------------------------------------------------------------------
78
87
 
79
88
  def dom_data
@@ -1,3 +1,3 @@
1
1
  module SemanticDateTimeTags
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -52,5 +52,14 @@ describe SemanticDateTimeTags::FormatParser do
52
52
  to_html.must_equal '<span class="day A">Saturday</span><span class="sep"> </span><span class="day d">12</span><span class="sep"> / </span><span class="month m">12</span><span class="sep"> / </span><span class="year Y">2014</span>'
53
53
  end
54
54
  end
55
+
56
+ describe '%-l:%M %P' do
57
+ let(:format) { '%-l:%M %P' }
58
+ let(:string) { '12:30 am' }
59
+
60
+ it 'marks up the am/pm' do
61
+ to_html.must_include '<span class="ampm P">'
62
+ end
63
+ end
55
64
  end
56
65
  end
@@ -17,6 +17,8 @@ describe SemanticDateTimeTags::ViewHelpers do
17
17
  let(:time_object_noon) { Time.new(2015, 11, 3, 12, 00) }
18
18
  let(:time_object_whole_hour) { Time.new(2014, 8, 21, 15) }
19
19
  let(:time_object_whole_minute) { Time.new(2014, 8, 21, 15, 30) }
20
+ let(:time_object_before_noon) { Time.new(2014, 8, 21, 11, 00) }
21
+ let(:time_object_after_noon) { Time.new(2014, 8, 21, 12, 01) }
20
22
 
21
23
 
22
24
  it 'does not work with a date object' do
@@ -59,6 +61,14 @@ describe SemanticDateTimeTags::ViewHelpers do
59
61
  semantic_time_tag(time_object_midnight).must_match /\A<time.+?midnight.+?<\/time>\z/
60
62
  end
61
63
 
64
+ it 'adds am class if time is before noon' do
65
+ semantic_time_tag(time_object_before_noon).must_match /\A<time.+?am.+?<\/time>\z/
66
+ end
67
+
68
+ it 'adds pm class if time is after noon' do
69
+ semantic_time_tag(time_object_after_noon).must_match /\A<time.+?pm.+?<\/time>\z/
70
+ end
71
+
62
72
 
63
73
  it 'adds noon as data-in-words if time is noon' do
64
74
  semantic_time_tag(time_object_noon).must_match /\A<time.+?data-in-words=\"noon\".+?<\/time>\z/
@@ -153,6 +163,8 @@ describe SemanticDateTimeTags::ViewHelpers do
153
163
  let(:date_time_object_from) { DateTime.parse('31/10/2015') }
154
164
  let(:date_time_object_to) { DateTime.parse('11/11/2015') }
155
165
 
166
+ let(:date_time_object_from_morning) { DateTime.parse('7/11/2015 8:00') }
167
+
156
168
  it 'returns the from date wrapped correctly' do
157
169
  semantic_date_range_tag(date_object, date_tomorrow_object).must_match /<time.+?semantic.+?date.+?from.+?>.+?<time.+?semantic.+?date.+?to.+?>/
158
170
  end
@@ -169,6 +181,10 @@ describe SemanticDateTimeTags::ViewHelpers do
169
181
  semantic_date_range_tag(date_time_object_from, date_time_object_from).must_match /\A<span.+?date_range.+?same_day.+?same_time.+?>/
170
182
  end
171
183
 
184
+ it 'adds am to wrapping span if both times in morning' do
185
+ semantic_date_range_tag(date_time_object_from_morning, date_time_object_from_morning+1.hour).must_match /\A<span.+?date_range.+?same_meridian.+?>/
186
+ end
187
+
172
188
  it 'accepts datetime objects' do
173
189
  semantic_date_range_tag(date_time_object_from, date_time_object_to).must_match /<time.+?from.+?<\/time>/
174
190
  semantic_date_range_tag(date_time_object_from, date_time_object_to).must_match /<time.+?to.+?<\/time>/
@@ -178,6 +194,7 @@ describe SemanticDateTimeTags::ViewHelpers do
178
194
  semantic_date_time_range_tag(date_object, date_tomorrow_object).must_match /<time.+?semantic.+?date.+?from.+?>/
179
195
  end
180
196
 
197
+
181
198
  it 'allows to pass :format' do
182
199
  semantic_date_time_range_tag(date_object, date_tomorrow_object, format: :test).must_include '~'
183
200
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: semantic_date_time_tags
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Celizna