Use DateTime object for date in Sms class
parent
dcbafff75b
commit
404f7d8290
|
@ -1,6 +1,9 @@
|
||||||
|
require 'date'
|
||||||
|
|
||||||
module Biju
|
module Biju
|
||||||
class Sms
|
class Sms
|
||||||
attr_accessor :id, :phone_number, :datetime, :message
|
attr_accessor :id, :phone_number, :message
|
||||||
|
attr_reader :datetime
|
||||||
|
|
||||||
def initialize(params={})
|
def initialize(params={})
|
||||||
params.each do |attr, value|
|
params.each do |attr, value|
|
||||||
|
@ -8,8 +11,15 @@ module Biju
|
||||||
end if params
|
end if params
|
||||||
end
|
end
|
||||||
|
|
||||||
def datetime
|
def datetime=(arg)
|
||||||
@datetime.sub(/(\d+)\D+(\d+)\D+(\d+),(\d*\D)(\d*\D)(\d+)(.*)/, '20\1-\2-\3 \4\5\6')
|
@datetime = case arg
|
||||||
|
when String
|
||||||
|
DateTime.strptime(arg, "%y/%m/%d,%T")
|
||||||
|
when DateTime
|
||||||
|
arg
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
|
|
Loading…
Reference in New Issue