time_compact 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -8
- data/Rakefile +7 -1
- data/lib/time_compact/version.rb +1 -1
- data/lib/time_compact.rb +17 -42
- data/locale/en.yml +5 -5
- data/locale/ja.yml +5 -5
- data/test/test_time_compact.rb +15 -13
- data/time_compact.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a07ad5487258701576985039433534a971cd7886
|
4
|
+
data.tar.gz: d9dfa3fbf7af561adf42b7827c2e808a40f4c0fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bec71f0877f0fd18352da5daa7c164ea9bef8e75c66f154cda30e6225ca51b4e400b66bdab699527aa34cc4617ced136fc619ca1837a18372df5ae2646140dcf
|
7
|
+
data.tar.gz: b42c4de394bc46f6855622d4901b1d0b7e1f454355bf749946a9ceb99bf15f3475537e6299f7813a55d31a74d86759d5e0b10f3d769b07dcd8aa243de6d72845
|
data/README.md
CHANGED
@@ -5,9 +5,9 @@ Displays time compactly.
|
|
5
5
|
for example:
|
6
6
|
|
7
7
|
# default locale
|
8
|
-
2014/1/2 #
|
9
|
-
1/2 #
|
10
|
-
8:16 #
|
8
|
+
2014/1/2 # on other year.
|
9
|
+
1/2 # on same year.
|
10
|
+
8:16 # on same day.
|
11
11
|
|
12
12
|
# 日本語ロケール
|
13
13
|
2014年1月2日 # 違う年の時
|
@@ -44,11 +44,20 @@ You can customize the format.
|
|
44
44
|
# config/locales/en.yml:
|
45
45
|
en:
|
46
46
|
time_compact:
|
47
|
-
same_year: '%
|
48
|
-
same_month: '%
|
49
|
-
same_day: '%
|
50
|
-
same_hour: '%
|
51
|
-
other: '%
|
47
|
+
same_year: '%1m/%1d'
|
48
|
+
same_month: '%1m/%1d'
|
49
|
+
same_day: '%1H:%M'
|
50
|
+
same_hour: '%1M min'
|
51
|
+
other: '%Y/%1m/%1d'
|
52
|
+
|
53
|
+
# config/locales/ja.yml:
|
54
|
+
ja:
|
55
|
+
time_compact:
|
56
|
+
same_year: '%1m月%1d日'
|
57
|
+
same_month: '%1d日'
|
58
|
+
same_day: '%1H時%1M分'
|
59
|
+
same_hour: '%1M分'
|
60
|
+
other: '%Y年%1m月%1d日'
|
52
61
|
|
53
62
|
## Contributing
|
54
63
|
|
data/Rakefile
CHANGED
data/lib/time_compact/version.rb
CHANGED
data/lib/time_compact.rb
CHANGED
@@ -1,63 +1,38 @@
|
|
1
1
|
require_relative 'time_compact/version'
|
2
2
|
require_relative 'time_compact/railtie' if defined? Rails
|
3
3
|
require 'i18n'
|
4
|
+
require 'yaml'
|
4
5
|
|
5
6
|
module TimeCompact
|
7
|
+
LOCALE_DIR = File.expand_path('../../locale', __FILE__)
|
8
|
+
|
6
9
|
def time_compact(time, now = Time.now)
|
7
|
-
|
8
|
-
|
10
|
+
I18n.enforce_available_locales = true
|
11
|
+
I18n.load_path += Dir[LOCALE_DIR + '/*.yml']
|
9
12
|
|
10
13
|
if time.year == now.year
|
11
14
|
if time.month == now.month
|
12
15
|
if time.day == now.day
|
13
16
|
if time.hour == now.hour
|
14
|
-
|
15
|
-
'time_compact.same_hour',
|
16
|
-
year: time.year,
|
17
|
-
month: time.month,
|
18
|
-
day: time.day,
|
19
|
-
hour: time.hour,
|
20
|
-
min: time.min
|
21
|
-
)
|
17
|
+
time.strftime(fetch_locale('same_hour'))
|
22
18
|
else
|
23
|
-
|
24
|
-
'time_compact.same_day',
|
25
|
-
year: time.year,
|
26
|
-
month: time.month,
|
27
|
-
day: time.day,
|
28
|
-
hour: time.hour,
|
29
|
-
min: '%02d' % time.min
|
30
|
-
)
|
19
|
+
time.strftime(fetch_locale('same_day'))
|
31
20
|
end
|
32
21
|
else
|
33
|
-
|
34
|
-
'time_compact.same_month',
|
35
|
-
year: time.year,
|
36
|
-
month: time.month,
|
37
|
-
day: time.day,
|
38
|
-
hour: time.hour,
|
39
|
-
min: '%02d' % time.min
|
40
|
-
)
|
22
|
+
time.strftime(fetch_locale('same_month'))
|
41
23
|
end
|
42
24
|
else
|
43
|
-
|
44
|
-
'time_compact.same_year',
|
45
|
-
year: time.year,
|
46
|
-
month: time.month,
|
47
|
-
day: time.day,
|
48
|
-
hour: time.hour,
|
49
|
-
min: '%02d' % time.min
|
50
|
-
)
|
25
|
+
time.strftime(fetch_locale('same_year'))
|
51
26
|
end
|
52
27
|
else
|
53
|
-
|
54
|
-
'time_compact.other',
|
55
|
-
year: time.year,
|
56
|
-
month: time.month,
|
57
|
-
day: time.day,
|
58
|
-
hour: time.hour,
|
59
|
-
min: '%02d' % time.min
|
60
|
-
)
|
28
|
+
time.strftime(fetch_locale('other'))
|
61
29
|
end
|
62
30
|
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def fetch_locale(name)
|
35
|
+
yml = YAML.load_file("#{LOCALE_DIR}/#{I18n.locale}.yml")
|
36
|
+
yml[I18n.locale.to_s]['time_compact'][name]
|
37
|
+
end
|
63
38
|
end
|
data/locale/en.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
en:
|
2
2
|
time_compact:
|
3
|
-
same_year: '%
|
4
|
-
same_month: '%
|
5
|
-
same_day: '%
|
6
|
-
same_hour: '%
|
7
|
-
other: '%
|
3
|
+
same_year: '%1m/%1d'
|
4
|
+
same_month: '%1m/%1d'
|
5
|
+
same_day: '%1H:%M'
|
6
|
+
same_hour: '%1M min'
|
7
|
+
other: '%Y/%1m/%1d'
|
data/locale/ja.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
ja:
|
2
2
|
time_compact:
|
3
|
-
same_year: '%
|
4
|
-
same_month: '%
|
5
|
-
same_day: '%
|
6
|
-
same_hour: '%
|
7
|
-
other: '%
|
3
|
+
same_year: '%1m月%1d日'
|
4
|
+
same_month: '%1d日'
|
5
|
+
same_day: '%1H時%1M分'
|
6
|
+
same_hour: '%1M分'
|
7
|
+
other: '%Y年%1m月%1d日'
|
data/test/test_time_compact.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
require 'minitest/unit'
|
2
1
|
require 'minitest/autorun'
|
2
|
+
require 'minitest/unit'
|
3
3
|
require_relative '../lib/time_compact'
|
4
4
|
|
5
|
-
class TestTimeCompact < MiniTest::
|
5
|
+
class TestTimeCompact < MiniTest::Test
|
6
6
|
def setup
|
7
|
+
I18n.enforce_available_locales = true
|
8
|
+
I18n.available_locales = [:en, :ja]
|
7
9
|
@object = Object.new
|
8
10
|
@object.extend TimeCompact
|
9
11
|
end
|
@@ -13,23 +15,23 @@ class TestTimeCompact < MiniTest::Unit::TestCase
|
|
13
15
|
assert_equal '2014/1/1', @object.time_compact(
|
14
16
|
Time.new(2014, 1, 1, 0, 0, 0),
|
15
17
|
Time.new(2015, 1, 1, 0, 0, 0)
|
16
|
-
)
|
18
|
+
), 'defferent year'
|
17
19
|
assert_equal '1/1', @object.time_compact(
|
18
20
|
Time.new(2014, 1, 1, 0, 0, 0),
|
19
21
|
Time.new(2014, 2, 1, 0, 0, 0)
|
20
|
-
)
|
22
|
+
), 'same year'
|
21
23
|
assert_equal '1/1', @object.time_compact(
|
22
24
|
Time.new(2014, 1, 1, 0, 0, 0),
|
23
25
|
Time.new(2014, 1, 2, 0, 0, 0)
|
24
|
-
)
|
26
|
+
), 'same month'
|
25
27
|
assert_equal '0:00', @object.time_compact(
|
26
28
|
Time.new(2014, 1, 1, 0, 0, 0),
|
27
29
|
Time.new(2014, 1, 1, 1, 0, 0)
|
28
|
-
)
|
30
|
+
), 'same day'
|
29
31
|
assert_equal '0 min', @object.time_compact(
|
30
32
|
Time.new(2014, 1, 1, 0, 0, 0),
|
31
33
|
Time.new(2014, 1, 1, 0, 1, 0)
|
32
|
-
)
|
34
|
+
), 'same hour'
|
33
35
|
end
|
34
36
|
|
35
37
|
def test_time_compact_ja
|
@@ -37,22 +39,22 @@ class TestTimeCompact < MiniTest::Unit::TestCase
|
|
37
39
|
assert_equal '2014年1月1日', @object.time_compact(
|
38
40
|
Time.new(2014, 1, 1, 0, 0, 0),
|
39
41
|
Time.new(2015, 1, 1, 0, 0, 0)
|
40
|
-
)
|
42
|
+
), 'defferent year'
|
41
43
|
assert_equal '1月1日', @object.time_compact(
|
42
44
|
Time.new(2014, 1, 1, 0, 0, 0),
|
43
45
|
Time.new(2014, 2, 1, 0, 0, 0)
|
44
|
-
)
|
46
|
+
), 'same year'
|
45
47
|
assert_equal '1日', @object.time_compact(
|
46
48
|
Time.new(2014, 1, 1, 0, 0, 0),
|
47
49
|
Time.new(2014, 1, 2, 0, 0, 0)
|
48
|
-
)
|
49
|
-
assert_equal '0時
|
50
|
+
), 'same month'
|
51
|
+
assert_equal '0時0分', @object.time_compact(
|
50
52
|
Time.new(2014, 1, 1, 0, 0, 0),
|
51
53
|
Time.new(2014, 1, 1, 1, 0, 0)
|
52
|
-
)
|
54
|
+
), 'same day'
|
53
55
|
assert_equal '0分', @object.time_compact(
|
54
56
|
Time.new(2014, 1, 1, 0, 0, 0),
|
55
57
|
Time.new(2014, 1, 1, 0, 1, 0)
|
56
|
-
)
|
58
|
+
), 'same hour'
|
57
59
|
end
|
58
60
|
end
|
data/time_compact.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: time_compact
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masaki Komagata
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description: Displays time compactly.
|
56
70
|
email:
|
57
71
|
- komagata@gmail.com
|