Class: Time
- Inherits:
-
Object
- Object
- Time
- Defined in:
- lib/easysft.rb
Class Method Summary collapse
-
.easysft(format) ⇒ Object
Provides an easier and human-readable interface to Time.strftime.
Instance Method Summary collapse
-
#easysft(format) ⇒ Object
Provides an easier and human-readable interface to Time.strftime Use the following format:.
Class Method Details
.easysft(format) ⇒ Object
Provides an easier and human-readable interface to Time.strftime
52 53 54 55 |
# File 'lib/easysft.rb', line 52 def self.easysft(format) t = Time.now return t.easysft(format) end |
Instance Method Details
#easysft(format) ⇒ Object
Provides an easier and human-readable interface to Time.strftime Use the following format:
Month = December
month = Dec
Day = 01-31
Year = 2008
year = 08
Weekday = Wednesday
weekday = Wed
Hour = 4 (AMPM version)
hour = 16 (24 hour time)
Minute = 0-59
Second = 0-59
AMPM = Meridian indicator (AM or PM)
TZ = Name of timezone (CST)
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/easysft.rb', line 21 def easysft(format) # Define substituion table sub_table = { "Month" => "%B", "month" => "%b", "Day" => "%d", "Year" => "%Y", "year" => "%y", "Weekday" => "%A", "weekday" => "%a", "Hour" => "%I", "hour" => "%i", "Minute" => "%M", "Second" => "%S", "AMPM" => "%p", "TZ" => "%Z", "Day of Year" => "%j" } # Perform substutions sub_table.each { |k,v| format.gsub!(k, v) } # Pass results to Time.strftime return strftime(format) end |