Class: Time

Inherits:
Object
  • Object
show all
Defined in:
lib/utiles_datetime.rb

Overview

Extentions for Time class.

Instance Method Summary collapse

Instance Method Details

#to_str(*splat) ⇒ Object

Formats Time object to string.

Examples:

Usage

obj.to_str == obj.strftime("%Y-%m-%d / %H:%M:%S")
obj.to_str(:minutes) == obj.strftime("%Y-%m-%d / %H:%M")
obj.to_str(:date) == obj.strftime("%Y-%m-%d")

Parameters:

  • format (Symbol)

    the format type, ‘:minutes` or `:date` or no parameters



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/utiles_datetime.rb', line 11

def to_str(*splat)
  if splat.empty?
    localtime.strftime("%Y-%m-%d / %H:%M:%S")
  else
    case splat[0]
      when :minutes
        localtime.strftime("%Y-%m-%d / %H:%M")
      when :date
        localtime.strftime("%Y-%m-%d")
      else
        localtime.strftime("%Y-%m-%d / %H:%M:%S")
    end
  end
end