Class: Miti::AdToBs

Inherits:
Object
  • Object
show all
Defined in:
lib/miti/ad_to_bs.rb

Overview

class to handle the algorithm for converting AD to BS

Instance Method Summary collapse

Constructor Details

#initialize(english_date) ⇒ AdToBs

Initializes a AdToBs object

Parameters:

  • @english_date (Date)


9
10
11
# File 'lib/miti/ad_to_bs.rb', line 9

def initialize(english_date)
  @english_date = english_date
end

Instance Method Details

#convertMiti::NepaliDate

Converts the @english_date to nepali date

Returns:



17
18
19
20
21
22
23
24
# File 'lib/miti/ad_to_bs.rb', line 17

def convert
  year, month, day = nepali_date_for_new_year
  # Jan 1 can be poush 16, 17 or 18. The gatey obtained has to be subtracted because
  # days in month is added in days calculation and jan 1 is in mid poush.
  day_count_from_poush1 = 1 - day
  nepali_date = corresponding_nepali_date(year, month - 1, day_count_from_poush1)
  Miti::NepaliDate.new(**nepali_date)
end