Class: Chronos::Calendar::Gregorian

Inherits:
Chronos::Calendar show all
Defined in:
lib/chronos/calendar/gregorian.rb

Constant Summary collapse

Inspect =
"#<%s %s>".freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(datetime) ⇒ Gregorian

Returns a new instance of Gregorian.



27
28
29
30
# File 'lib/chronos/calendar/gregorian.rb', line 27

def initialize(datetime)
  @datetime = datetime
  @language = datetime.language
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object



76
77
78
79
80
81
82
83
84
# File 'lib/chronos/calendar/gregorian.rb', line 76

def method_missing(*args, &block)
  r = @datetime.send(*args, &block)
  if r.class == ::Chronos::Datetime::Gregorian then
    @datetime = r
    self
  else
    r
  end
end

Class Method Details

.method_missing(*args, &block) ⇒ Object



22
23
24
# File 'lib/chronos/calendar/gregorian.rb', line 22

def method_missing(*args, &block)
  new(Chronos::Datetime::Gregorian.send(*args, &block))
end

Instance Method Details

#day=(value) ⇒ Object



44
45
46
# File 'lib/chronos/calendar/gregorian.rb', line 44

def day=(value)
  @datetime += Chronos::Duration::Gregorian.new((value-@datetime.day())*Chronos::PS_IN_DAY, 0, @language)
end

#hour=(value) ⇒ Object



48
49
50
# File 'lib/chronos/calendar/gregorian.rb', line 48

def hour=(value)
  @datetime += Chronos::Duration::Gregorian.new((value-@datetime.hour())*Chronos::PS_IN_HOUR, 0, @language)
end

#inspectObject



86
87
88
89
90
91
# File 'lib/chronos/calendar/gregorian.rb', line 86

def inspect
  sprintf Inspect,
    self.class,
    @datetime
  # /sprintf
end

#microsecond=(value) ⇒ Object



64
65
66
# File 'lib/chronos/calendar/gregorian.rb', line 64

def microsecond=(value)
  @datetime += Chronos::Duration::Gregorian.new((value-@datetime.microsecond())*Chronos::PS_IN_MICROSECOND, 0, @language)
end

#millisecond=(value) ⇒ Object



60
61
62
# File 'lib/chronos/calendar/gregorian.rb', line 60

def millisecond=(value)
  @datetime += Chronos::Duration::Gregorian.new((value-@datetime.millisecond())*Chronos::PS_IN_MILLISECOND, 0, @language)
end

#minute=(value) ⇒ Object



52
53
54
# File 'lib/chronos/calendar/gregorian.rb', line 52

def minute=(value)
  @datetime += Chronos::Duration::Gregorian.new((value-@datetime.minute())*Chronos::PS_IN_MINUTE, 0, @language)
end

#month=(value) ⇒ Object



36
37
38
# File 'lib/chronos/calendar/gregorian.rb', line 36

def month=(value)
  @datetime += Chronos::Duration::Gregorian.new(0, (value-@datetime.month()), @language)
end

#nanosecond=(value) ⇒ Object



68
69
70
# File 'lib/chronos/calendar/gregorian.rb', line 68

def nanosecond=(value)
  @datetime += Chronos::Duration::Gregorian.new((value-@datetime.nanosecond())*Chronos::PS_IN_NANOSECOND, 0, @language)
end

#picosecond=(value) ⇒ Object



72
73
74
# File 'lib/chronos/calendar/gregorian.rb', line 72

def picosecond=(value)
  @datetime += Chronos::Duration::Gregorian.new((value-@datetime.picosecond())*Chronos::PS_IN_PICOSECOND, 0, @language)
end

#second=(value) ⇒ Object



56
57
58
# File 'lib/chronos/calendar/gregorian.rb', line 56

def second=(value)
  @datetime += Chronos::Duration::Gregorian.new((value-@datetime.second())*Chronos::PS_IN_SECOND, 0, @language)
end

#week=(value) ⇒ Object



40
41
42
# File 'lib/chronos/calendar/gregorian.rb', line 40

def week=(value)
  @datetime += Chronos::Duration::Gregorian.new((value-@datetime.week())*Chronos::PS_IN_WEEK, 0, @language)
end

#year=(value) ⇒ Object



32
33
34
# File 'lib/chronos/calendar/gregorian.rb', line 32

def year=(value)
  @datetime += Chronos::Duration::Gregorian.new(0, (value-@datetime.year())*12, @language)
end