Module: DateTools
- Defined in:
- lib/date_tools.rb,
lib/date_tools/date_locale.rb
Overview
date_tools-Gem
Define some helper for the classes Date, DateTime and Time:
-
compare to time (sort date and time-objects)
-
define locales (non-english monthnames.
-
new creators
Check the examples-folders to get an impression of the gem.
date_tools/date_time_compare.rb:
Usage:
require 'date_tools/date_time_compare'
Allows to compare Date and Time objects (allows to sort by mixed Date/Time-keys).
Time gets also some methods like Date:
-
Time#cwday
-
Time#cweek
-
Time#cwyear
-> please check the examples in examples/example_date_time_compare.rb
date_tools/date_creator.rb:
Usage:
require 'date_tools/date_creator'
New date creations: Date.new_by_mday: Allows “Third sunday in june 2010”…
-> please check the examples in examples/example_date_creator.rb
date_tools/date_locale.rb:
Usage:
require 'date_tools/date_locale.rb'
Localization of Date, DateTime and Time.
strftime (Date#strftime, Time#strftime and DateTime#strftime) gets an optional parameter to determine the language.
Default is en, or if locale is used the current locale.
-> please check the examples in examples/example_date_locale.rb
Usage with I18N
With I18N y ou don’t need a redefinition of Time#strftime, with I18N you use the I18n.localize function.
But you can use this gem to define the translations of day and month names.
Example:
require 'date_tools'
require 'i18n'
I18n.load_path = DateTools::I18N_FILES
I18n.load_path += YOUR_I18N_FILES
I18n.backend.load_translations #this is done automatic by rails
%w{en de de_at}.each{|locale|
I18n.locale = locale
puts I18n.localize Time.now #"07. r 2013 00:13"
#~ puts I18n.l Time.now #"07. r 2013 00:13"
}
Remark: If you get a
translation missing: en.time.formats.default (I18n::MissingTranslationData)
then you didn’t localize time/date in your project (YOUR_I18N_FILES).
This gem doesn’t define, how your Time/Date is printed, it only defines the correct day- and month name if you use %B/%A.
-> please check the examples in examples/example_date_i18n.rb
Defined Under Namespace
Modules: Mixin
Constant Summary collapse
- VERSION =
'0.1.1'
- I18N_FILES =
Path to I18N-compatible language definition for day- and month names.
Dir[File.join(File.(__FILE__),'..','..','data', 'locales','*.yml')]