Class: PDateTime

Inherits:
RailsPdate::BaseDateTime show all
Includes:
RailsPdate::Formats::DateTime
Defined in:
lib/rails_pdate/p_date_time.rb

Overview

:title:PDateTime (Persian DateTime) #

Constant Summary

Constants included from RailsPdate::Formats::DateTime

RailsPdate::Formats::DateTime::FORMATS

Constants included from RailsPdate::Constants

RailsPdate::Constants::GDaysInMonth, RailsPdate::Constants::PDaysInMonth, RailsPdate::Constants::PERSIAN_ABBR_MERIDIAN_INDICATOR, RailsPdate::Constants::PERSIAN_ABBR_WEEKDAY_NAMES, RailsPdate::Constants::PERSIAN_MERIDIAN_INDICATOR, RailsPdate::Constants::PERSIAN_MONTH_NAMES, RailsPdate::Constants::PERSIAN_MONTH_NAMES_PINGLISH, RailsPdate::Constants::PERSIAN_WEEKDAY_NAMES

Instance Attribute Summary collapse

Attributes inherited from RailsPdate::BaseDateTime

#day, #month, #year

Instance Method Summary collapse

Methods included from RailsPdate::Formats::DateTime

#to_formatted_s

Methods inherited from RailsPdate::BaseDateTime

#<, #<=, #==, #>, #>=, #cwday, #cweek, #initialize, #pdayname, #to_date, #to_i, #yday

Methods included from RailsPdate::TimeShifting

#beginning_of_day, #beginning_of_hour, #beginning_of_minute, #beginning_of_month, #beginning_of_week, #beginning_of_year, #end_of_day, #end_of_hour, #end_of_minute, #end_of_month, #end_of_week, #end_of_year, included

Constructor Details

This class inherits a constructor from RailsPdate::BaseDateTime

Instance Attribute Details

#hourObject

Returns the value of attribute hour.



6
7
8
# File 'lib/rails_pdate/p_date_time.rb', line 6

def hour
  @hour
end

#minuteObject

Returns the value of attribute minute.



6
7
8
# File 'lib/rails_pdate/p_date_time.rb', line 6

def minute
  @minute
end

#secondObject

Returns the value of attribute second.



6
7
8
# File 'lib/rails_pdate/p_date_time.rb', line 6

def second
  @second
end

Instance Method Details

#+(other) ⇒ Object



42
43
44
# File 'lib/rails_pdate/p_date_time.rb', line 42

def +(other)
  ( to_datetime + other ).to_pdatetime
end

#-(other) ⇒ Object



46
47
48
# File 'lib/rails_pdate/p_date_time.rb', line 46

def -(other)
  ( to_datetime - other ).to_pdatetime
end

#cloneObject



33
34
35
# File 'lib/rails_pdate/p_date_time.rb', line 33

def clone
  PDateTime.new(@year, @month, @day, @hour, @minute, @second)
end

#strftime(format) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rails_pdate/p_date_time.rb', line 14

def strftime(format)
  format
      .gsub('%Y', '%d' % @year)
      .gsub('%m', '%02d' % @month)
      .gsub('%d', '%02d' % @day)
      .gsub('%C', '%d' % (@year / 100) )
      .gsub('%y', '%d' % (@year % 100) )
      .gsub('%B', '%s' %  PERSIAN_MONTH_NAMES_PINGLISH[@month])
      .gsub('%b', '%s' %  PERSIAN_MONTH_NAMES[@month])
      .gsub('%e', '%d' % @day)
      .gsub('%A', '%s' % PERSIAN_WEEKDAY_NAMES[self.cwday-1])
      .gsub('%H', '%d' % @hour)
      .gsub('%h', '%02d' % @hour)
      .gsub('%i', '%02d' % @minute)
      .gsub('%I', '%d' % @minute)
      .gsub('%s', '%02d' % @second)
      .gsub('%S', '%d' % @second)
end

#to_aObject



10
11
12
# File 'lib/rails_pdate/p_date_time.rb', line 10

def to_a
  [@year, @month, @day, @hour, @minute, @second]
end

#to_datetimeObject



37
38
39
40
# File 'lib/rails_pdate/p_date_time.rb', line 37

def to_datetime
  year, month, day = Pconvertor.new.persian_to_gregorian(@year, @month, @day)
  DateTime.new(year, month, day, @hour, @minute, @second)
end