Class: LocaSMS::Helpers::DateTimeHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/locasms/helpers/date_time_helper.rb

Overview

Helper class to handle with time parsing

Class Method Summary collapse

Class Method Details

.parse(date) ⇒ Object

Parse a value into a time

Examples:


DateTimeHelper.parse '1977-03-14 14:12:00'
# => 1977-03-14 14:12:00 -0300

DateTimeHelper.split 227207520
# => 1977-03-14 14:12:00 -0300

Parameters:

  • date (Fixnum, String, DateTime, Time, #to_time)


19
20
21
22
23
24
# File 'lib/locasms/helpers/date_time_helper.rb', line 19

def self.parse(date)
  date = Time.at(date)    if date.is_a? Integer
  date = Time.parse(date) if date.is_a? String
  date = date.to_time     if date.respond_to? :to_time
  date
end

.split(date) ⇒ Object

Breaks a given date in date and time

Examples:


DateTimeHelper.split Time.now
# => ['14/03/1977', '14:12']

DateTimeHelper.split 227207520
# => ['14/03/1977', '14:12']

Parameters:

  • date (Fixnum, String, DateTime, Time, #to_time)


38
39
40
# File 'lib/locasms/helpers/date_time_helper.rb', line 38

def self.split(date)
  parse(date).strftime('%d/%m/%Y %H:%M').split
end