Class: Coligny::ColignyDate
- Inherits:
-
Object
- Object
- Coligny::ColignyDate
- Defined in:
- lib/coligny.rb
Instance Attribute Summary collapse
-
#day ⇒ Object
Returns the value of attribute day.
-
#month ⇒ Object
Returns the value of attribute month.
-
#months ⇒ Object
Returns the value of attribute months.
-
#year ⇒ Object
Returns the value of attribute year.
Instance Method Summary collapse
- #calc_days(add) ⇒ Object
- #days_exceed_over ⇒ Object
- #days_exceed_under ⇒ Object
- #earlier_check(check_date) ⇒ Object
-
#initialize(year, month, day, is_metonic = false) ⇒ ColignyDate
constructor
A new instance of ColignyDate.
- #later_check(check_date) ⇒ Object
- #to_gregorian_date ⇒ Object
Constructor Details
#initialize(year, month, day, is_metonic = false) ⇒ ColignyDate
Returns a new instance of ColignyDate.
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/coligny.rb', line 297 def initialize(year, month, day, is_metonic=false) @is_metonic = is_metonic @year = year @day = day if @is_metonic @start_year = 4999 @start_date = Date.new(1999, 5, 22) @months = ColignyYear.new(year, true).months else @start_year = 4998 @start_date = Date.new(1998, 5, 3) @months = ColignyYear.new(year).months end @month = @months.find { |s| s.name == month } end |
Instance Attribute Details
#day ⇒ Object
Returns the value of attribute day.
295 296 297 |
# File 'lib/coligny.rb', line 295 def day @day end |
#month ⇒ Object
Returns the value of attribute month.
295 296 297 |
# File 'lib/coligny.rb', line 295 def month @month end |
#months ⇒ Object
Returns the value of attribute months.
295 296 297 |
# File 'lib/coligny.rb', line 295 def months @months end |
#year ⇒ Object
Returns the value of attribute year.
295 296 297 |
# File 'lib/coligny.rb', line 295 def year @year end |
Instance Method Details
#calc_days(add) ⇒ Object
345 346 347 348 349 350 351 352 353 354 355 |
# File 'lib/coligny.rb', line 345 def calc_days(add) @day += add while @day > @month.days days_exceed_over end while @day < 1 days_exceed_under end end |
#days_exceed_over ⇒ Object
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/coligny.rb', line 313 def days_exceed_over if @months[@months.index(@month) + 1].nil? @day = @day - @month.days @year += 1 if @is_metonic @months = ColignyYear.new(@year, true).months else @months = ColignyYear.new(@year).months end @month = @months[0] else @day = @day - @month.days @month = @months[@months.index(@month) + 1] end end |
#days_exceed_under ⇒ Object
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
# File 'lib/coligny.rb', line 329 def days_exceed_under if @month == @months[0] @year -= 1 if @is_metonic @months = ColignyYear.new(@year, true).months else @months = ColignyYear.new(@year).months end @month = @months[-1] @day = @month.days + (@day) else @month = @months[@months.index(@month) - 1] @day = @month.days + (@day) end end |
#earlier_check(check_date) ⇒ Object
357 358 359 360 361 362 363 364 365 366 |
# File 'lib/coligny.rb', line 357 def earlier_check(check_date) day_count = 0 until self.month.name == check_date.month.name && self.day == check_date.day && self.year == check_date.year self.calc_days(1) day_count += 1 end return day_count end |
#later_check(check_date) ⇒ Object
368 369 370 371 372 373 374 375 376 377 |
# File 'lib/coligny.rb', line 368 def later_check(check_date) day_count = 0 until check_date.month.name == self.month.name && check_date.day == self.day && check_date.year == self.year check_date.calc_days(1) day_count += 1 end return day_count end |
#to_gregorian_date ⇒ Object
379 380 381 382 383 384 385 386 387 388 389 390 391 |
# File 'lib/coligny.rb', line 379 def to_gregorian_date if @is_metonic start = ColignyDate.new(4999, "Samonios", 1, true) else start = ColignyDate.new(4998, "Quimonios", 1) end if (@year < @start_year) return @start_date - earlier_check(start) else return @start_date + later_check(start) end end |