date_tools 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/examples/example_date_i18n.rb +52 -52
- data/lib/date_tools.rb +2 -1
- data/lib/date_tools/date_locale.rb +16 -8
- data/unittest/test_date_locale.rb +9 -0
- data/unittest/test_date_tools.rb +1 -1
- metadata +2 -2
@@ -1,52 +1,52 @@
|
|
1
|
-
#encoding: utf-8
|
2
|
-
=begin rdoc
|
3
|
-
Example file for usage with I18N.
|
4
|
-
=end
|
5
|
-
module Example
|
6
|
-
end
|
7
|
-
|
8
|
-
$:.unshift('../lib')
|
9
|
-
|
10
|
-
require 'date_tools'
|
11
|
-
require 'i18n'
|
12
|
-
|
13
|
-
=begin
|
14
|
-
Define the format for time.
|
15
|
-
=end
|
16
|
-
I18n.backend.store_translations(:en , {
|
17
|
-
time: {
|
18
|
-
formats: {
|
19
|
-
default: "%A %d. %B (%b) %Y %H:%M",
|
20
|
-
},
|
21
|
-
}
|
22
|
-
}
|
23
|
-
)
|
24
|
-
|
25
|
-
I18n.backend.store_translations(:de , {
|
26
|
-
time: {
|
27
|
-
formats: {
|
28
|
-
default: "%A %d. %B (%b) %Y %H:%M",
|
29
|
-
},
|
30
|
-
},
|
31
|
-
}
|
32
|
-
)
|
33
|
-
I18n.backend.store_translations(:de_at , {
|
34
|
-
time: {
|
35
|
-
formats: {
|
36
|
-
default: "%A %d. %B (%b) %Y %H:%M",
|
37
|
-
},
|
38
|
-
},
|
39
|
-
}
|
40
|
-
)
|
41
|
-
|
42
|
-
=begin
|
43
|
-
Load the translations for day and month names
|
44
|
-
=end
|
45
|
-
I18n.load_path = DateTools::I18N_FILES
|
46
|
-
I18n.backend.load_translations
|
47
|
-
|
48
|
-
%w{en de de_at}.each{|locale|
|
49
|
-
I18n.locale = locale
|
50
|
-
puts I18n.localize Time.now #"07. r 2013 00:13"
|
51
|
-
#~ puts I18n.l Time.now #"07. r 2013 00:13"
|
52
|
-
}
|
1
|
+
#encoding: utf-8
|
2
|
+
=begin rdoc
|
3
|
+
Example file for usage with I18N.
|
4
|
+
=end
|
5
|
+
module Example
|
6
|
+
end
|
7
|
+
|
8
|
+
$:.unshift('../lib')
|
9
|
+
|
10
|
+
require 'date_tools'
|
11
|
+
require 'i18n'
|
12
|
+
|
13
|
+
=begin
|
14
|
+
Define the format for time.
|
15
|
+
=end
|
16
|
+
I18n.backend.store_translations(:en , {
|
17
|
+
time: {
|
18
|
+
formats: {
|
19
|
+
default: "%A %d. %B (%b) %Y %H:%M",
|
20
|
+
},
|
21
|
+
}
|
22
|
+
}
|
23
|
+
)
|
24
|
+
|
25
|
+
I18n.backend.store_translations(:de , {
|
26
|
+
time: {
|
27
|
+
formats: {
|
28
|
+
default: "%A %d. %B (%b) %Y %H:%M",
|
29
|
+
},
|
30
|
+
},
|
31
|
+
}
|
32
|
+
)
|
33
|
+
I18n.backend.store_translations(:de_at , {
|
34
|
+
time: {
|
35
|
+
formats: {
|
36
|
+
default: "%A %d. %B (%b) %Y %H:%M",
|
37
|
+
},
|
38
|
+
},
|
39
|
+
}
|
40
|
+
)
|
41
|
+
|
42
|
+
=begin
|
43
|
+
Load the translations for day and month names
|
44
|
+
=end
|
45
|
+
I18n.load_path = DateTools::I18N_FILES
|
46
|
+
I18n.backend.load_translations
|
47
|
+
|
48
|
+
%w{en de de_at}.each{|locale|
|
49
|
+
I18n.locale = locale
|
50
|
+
puts I18n.localize Time.now #"07. r 2013 00:13"
|
51
|
+
#~ puts I18n.l Time.now #"07. r 2013 00:13"
|
52
|
+
}
|
data/lib/date_tools.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
#encoding: utf-8
|
1
2
|
=begin
|
2
3
|
=date_tools-Gem
|
3
4
|
Define some helper for the classes Date, DateTime and Time:
|
@@ -83,7 +84,7 @@ examples/example_date_i18n.rb[link:files/examples/example_date_i18n_rb.html]
|
|
83
84
|
=end
|
84
85
|
|
85
86
|
module DateTools
|
86
|
-
VERSION = '0.1.
|
87
|
+
VERSION = '0.1.1'
|
87
88
|
|
88
89
|
#Path to I18N-compatible language definition for day- and month names.
|
89
90
|
I18N_FILES = Dir[File.join(File.expand_path(__FILE__),'..','..','data', 'locales','*.yml')]
|
@@ -108,12 +108,13 @@ or i18n-gem[https://rubygems.org/gems/i18n].
|
|
108
108
|
#Make the original replacements, after....
|
109
109
|
result = self.strftime_orig(
|
110
110
|
#...you replaced the language dependent parts.
|
111
|
-
format.gsub(/%([aAbB])/){|m|
|
112
|
-
|
113
|
-
|
114
|
-
when '
|
115
|
-
when '
|
116
|
-
when '
|
111
|
+
format.gsub(/%(-*\d*)([aAbB])/){|m|
|
112
|
+
mformat = '%%%ss' % $1
|
113
|
+
case $2
|
114
|
+
when 'a'; mformat % abbr_daynames[self.wday]
|
115
|
+
when 'A'; mformat % daynames[self.wday]
|
116
|
+
when 'b'; mformat % abbr_monthnames[self.mon]
|
117
|
+
when 'B'; mformat % monthnames[self.mon]
|
117
118
|
else
|
118
119
|
raise "Date#strftime: InputError"
|
119
120
|
end
|
@@ -173,10 +174,17 @@ end
|
|
173
174
|
if __FILE__ == $0
|
174
175
|
#~ require 'date_locale'
|
175
176
|
|
176
|
-
p DateTools::Mixin.get_language_key('de-at')
|
177
|
+
#~ p DateTools::Mixin.get_language_key('de-at')
|
177
178
|
|
178
|
-
|
179
|
+
d = Date.new(2009,10,21)
|
180
|
+
puts d.strftime("de: %A ", :en )
|
181
|
+
puts d.strftime("de: %15A ", :en )
|
182
|
+
puts d.strftime("de: %A ", :de )
|
183
|
+
puts d.strftime("de: %15A ", :de )
|
184
|
+
|
179
185
|
#~ puts d.strftime("de: %A {%a} {%A} {%W} %w ", :de ) #=> de: Mittwoch {Mi} {Mittwoch} {42} 3 (loc: en)
|
186
|
+
#~ puts d.strftime("de: %10A {%a} {%A} {%W} %w ", :de ) #=> de: Mittwoch {Mi} {Mittwoch} {42} 3 (loc: en)
|
187
|
+
#~ puts d.strftime("de: %-10A {%a} {%A} {%W} %w ", :de ) #=> de: Mittwoch {Mi} {Mittwoch} {42} 3 (loc: en)
|
180
188
|
#~ puts d.strftime("en: %A {%a} {%A} {%W} %w ", :en ) #=> en: Wednesday {Wed} {Wednesday} {42} 3 (loc: en)
|
181
189
|
|
182
190
|
#~ puts "=======Load locale"
|
@@ -80,6 +80,9 @@ class Test_en_US < Test::Unit::TestCase
|
|
80
80
|
def test_march()
|
81
81
|
assert_equal('March - Thursday', Date.new(2012,3,1).strftime('%B - %A', @locale))
|
82
82
|
end
|
83
|
+
def test_march_length()
|
84
|
+
assert_equal(' March - Thursday', Date.new(2012,3,1).strftime('%10B - %10A', @locale))
|
85
|
+
end
|
83
86
|
end
|
84
87
|
|
85
88
|
class Test_de < Test::Unit::TestCase
|
@@ -87,11 +90,17 @@ class Test_de < Test::Unit::TestCase
|
|
87
90
|
@locale = 'de'
|
88
91
|
end
|
89
92
|
def test_jan()
|
93
|
+
assert_equal('Jan - So', Date.new(2012,1,1).strftime('%b - %a', @locale))
|
90
94
|
assert_equal('Januar - Sonntag', Date.new(2012,1,1).strftime('%B - %A', @locale))
|
91
95
|
end
|
92
96
|
def test_march()
|
97
|
+
assert_equal('Mrz - Do', Date.new(2012,3,1).strftime('%b - %a', @locale))
|
93
98
|
assert_equal('März - Donnerstag', Date.new(2012,3,1).strftime('%B - %A', @locale))
|
94
99
|
end
|
100
|
+
def test_march_length()
|
101
|
+
assert_equal(' März - Donnerstag', Date.new(2012,3,1).strftime('%10B - %12A', @locale))
|
102
|
+
assert_equal('März - Donnerstag ', Date.new(2012,3,1).strftime('%-10B - %-12A', @locale))
|
103
|
+
end
|
95
104
|
end
|
96
105
|
|
97
106
|
class Test_de_de < Test::Unit::TestCase
|
data/unittest/test_date_tools.rb
CHANGED
@@ -7,7 +7,7 @@ require 'date_tools'
|
|
7
7
|
class Test_Date_tools < Test::Unit::TestCase
|
8
8
|
def test_version
|
9
9
|
assert_kind_of( String, DateTools::VERSION )
|
10
|
-
assert_equal( '0.1.
|
10
|
+
assert_equal( '0.1.1', DateTools::VERSION, "DateTools::VERSION changed? New version?" )
|
11
11
|
end
|
12
12
|
|
13
13
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: date_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-04-28 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! 'Little helper for the classes Date, DateTime and Time.
|
15
15
|
|