Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fiscal year #5

Merged
merged 21 commits into from
Jun 10, 2022
Merged

Fiscal year #5

merged 21 commits into from
Jun 10, 2022

Conversation

sangamsth
Copy link

No description provided.

@sarojkh sarojkh mentioned this pull request May 31, 2022
Copy link
Collaborator

@sarojkh sarojkh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to my comments below, just a general thumb of rule, the classes AdCalendar and BsCalendar should not mention or have implementations related to Fiscal Year. Remove them, and port to FiscalYear.

Kinda leaning toward the single responsibility principle. https://www.digitalocean.com/community/conceptual_articles/s-o-l-i-d-the-first-five-principles-of-object-oriented-design#single-responsibility-principle

@@ -0,0 +1,25 @@
class NepaliCalendar::FiscalYear < NepaliCalendar::Calendar
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any benefit for inheriting from NepaliCalendar::Calendar. Please remove it.

Comment on lines 57 to 61
# Returns the bs date that is the beginning of the provided fiscal_year.
def self.beginning_of_fiscal_year_in_bs(fiscal_year)
start_year = fiscal_year.to_s.slice(0, 2).prepend('20')
start_date = NepaliCalendar::Calendar.new(nil, {year: start_year, month: 4, day: 1}) #start date of fiscal year
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should instead be handled by NepaliCalendar::FiscalYear.new(77, 78).beginning_of_year or NepaliCalendar::FiscalYear.beginning_of_year(77,78), whichever you find preferable. In the former, beginning_of_year would be an instance method, in the latter, it would be a class method.

The latter would look something like this (you might be new to this pattern).

def self.beginning_of_year(start_year, end_year)
  new(start_year, end_year).beginning_of_year
end

Comment on lines 64 to 68
# Returns the bs date that is the end of the provided fiscal_year.
def self.end_of_fiscal_year_in_bs(fiscal_year)
end_year = fiscal_year.to_s.slice(2, 2).prepend('20')
end_date = NepaliCalendar::Calendar.new(nil, {year: end_year, month: 3, day: NepaliCalendar::BS[end_year.to_i][3]}) #end date of fiscal year
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to above.

Comment on lines 71 to 81
# Returns the ad date that is the beginning of the provided fiscal_year.
def self.beginning_of_fiscal_year_in_ad(fiscal_year)
bs_start_date= beginning_of_fiscal_year_in_bs(fiscal_year)
NepaliCalendar::AdCalendar.bs_to_ad(bs_start_date.year, bs_start_date.month, bs_start_date.day) #stard date in AD of the corresponding nepali date
end

# Returns the ad date that is the end of the provided fiscal_year.
def self.end_of_fiscal_year_in_ad(fiscal_year)
ad_end_date = end_of_fiscal_year_in_bs(fiscal_year)
NepaliCalendar::AdCalendar.bs_to_ad(ad_end_date.year, ad_end_date.month, ad_end_date.day) #end date in AD of the fiscal year
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's get rid of this method. Now that I think about it, it adds unnecessary complexity.

To achieve same, we could rather use

  1. Get fy beginning in bs date
  2. Convert the bs date to ad date.

@@ -0,0 +1,25 @@
class NepaliCalendar::FiscalYear < NepaliCalendar::Calendar
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class apparently also needs current_fiscal_year class method; which is currently implemented ditto-ish in two different places - bs_calendar.rb and ad_calendar.rb. Remove the existing implementations.

@sangamsth sangamsth requested a review from sarojkh May 31, 2022 09:35
Copy link
Collaborator

@sarojkh sarojkh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to pair with @Sagar535 if there are any confusions.

Comment on lines 22 to 29
def self.current_fiscal_year
current_year = NepaliCalendar::BsCalendar.ad_to_bs(Date.today.year, Date.today.month, Date.today.day)
if current_year.month < 4
fiscal_year = (current_year.year-1).to_s.slice(2,2) + current_year.year.to_s.slice(2,2)
else
fiscal_year = current_year.year.to_s.slice(2,2) + (current_year.year+1).to_s.slice(2,2)
end
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should return FiscalYear object.

Comment on lines 1 to 12
c
cal.send :to_bs_date, bs_date
bs_date = "2079-1-1"
cal.send :to_bs_date, bs_date
bs_date
cal.to_bs_date bs_date
cal = NepaliCalendar::BsCalendar.new "", year: 2079, month: 1, day: 1
cal = NepaliCalendar::BsCalendar.new
to_bs_date(bs_date)
bs_date.to_bs_date
bs_date.class
bs_date
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this file. Also, maybe update the .gitignore rules so that it's excluded from the future. Also, I wonder why this is inside your 'lib' folder.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 57 to 102
# Returns the bs date that is the beginning of the provided fiscal_year.
def self.beginning_of_fiscal_year_in_bs(fiscal_year)
start_year = fiscal_year.to_s.slice(0, 2)
end_year = fiscal_year.to_s.slice(2,2)
NepaliCalendar::FiscalYear.new(start_year, end_year).beginning_of_year #start date of fiscal year
end


# Returns the bs date that is the end of the provided fiscal_year.
def self.end_of_fiscal_year_in_bs(fiscal_year)
start_year = fiscal_year.to_s.slice(0, 2)
end_year = fiscal_year.to_s.slice(2,2)
NepaliCalendar::FiscalYear.new(start_year, end_year).end_of_year
end

# Returns the fiscal year represented as a string in the form of 7778.
def self.fiscal_year_for_bs_date(bs_year, bs_month, bs_day) # (2079, 2, 12) ==> 7879
if bs_month < 4 #compare with start date of nepali fiscal year to determine the fiscal year
fiscal_year = (bs_year - 1).to_s.slice(2,2).to_s + bs_year.to_s.slice(2,2).to_s
else
fiscal_year = bs_year.to_s.slice(2,2).to_s + (bs_year + 1).to_s.slice(2,2).to_s
end
end

# [date] -> This is a Date object (and obviously represents AD date)
# Returns the fiscal year represented as a string in the form of 7778.
def self.fiscal_year_for_ad_date(date)
bs_date = BsCalendar.ad_to_bs(date.year.to_s, date.month.to_s, date.day.to_s)
if bs_date.month < 4
fiscal_year = ((bs_date.year - 1).to_s.slice(2,2)).to_s + bs_date.year.to_s.slice(2,2).to_s
else
fiscal_year =bs_date.year.to_s.slice(2,2).to_s + ((bs_date.year + 1).to_s.slice(2,2)).to_s
end

end

def self.get_fiscal_year(bs_date)
year = bs_date.slice(0,4).to_i
month = bs_date.slice(4, 2).to_i
day = bs_date.slice(6, 2).to_i
if month < 4 #compare with start date of nepali fiscal year to determine the fiscal year
fiscal_year = (year - 1).to_s.slice(2,2).to_s + year.to_s.slice(2,2).to_s
else
fiscal_year = year.to_s.slice(2,2) + (year + 1).to_s.slice(2,2)
end
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see review description #5 (review)

Comment on lines 54 to 61
def self.get_fiscal_year(ad_date)
bs_date = NepaliCalendar::BsCalendar.ad_to_bs(ad_date.year.to_s, ad_date.month.to_s, ad_date.day.to_s)
if bs_date.month < 4
fiscal_year = ((ad_date.year - 1).to_s.slice(2,2)).to_s + ad_date.year.to_s.slice(2,2).to_s
else
fiscal_year =ad_date.year.to_s.slice(2,2).to_s + ((ad_date.year + 1).to_s.slice(2,2)).to_s
end
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see review description #5 (review)

@sangamsth sangamsth requested a review from sarojkh May 31, 2022 11:35
end
end

def self.fiscal_year_for_bs_date(bs_year, bs_month, bs_day) # (2079, 2, 12) ==> 7879
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not separately support the passing of the year, month, and day. Instead, let's have it take one parameter, which should be the 'NepaliCalendar::Calendar' object.

end

def self.current_fiscal_year
current_year = NepaliCalendar::BsCalendar.ad_to_bs(Date.today.year, Date.today.month, Date.today.day)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wording of this variable - current_year - is not intuitive, since it is actually storing bs date (or NepaliCalendar::BsCalendar object to be precise). Rename it to bs_date_today or today_in_bs.

# FiscalYear.new(start_year, end_year).end_of_year
# end

def self.get_fiscal_year_from_ad(ad_date)
Copy link
Collaborator

@sarojkh sarojkh Jun 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def self.get_fiscal_year_from_ad(ad_date)
def self.fiscal_year_for_ad_date(ad_date)

@sangamsth sangamsth requested a review from sarojkh June 3, 2022 04:23
Copy link
Collaborator

@sarojkh sarojkh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sangamsth LGTM, but still needs comprehensive specs to cover new modifications (additions/deletions/adjustments)

@sangamsth sangamsth requested a review from sarojkh June 7, 2022 09:35
lib/nepali_calendar/fiscal_year.rb Outdated Show resolved Hide resolved
lib/nepali_calendar/fiscal_year.rb Outdated Show resolved Hide resolved
lib/nepali_calendar/fiscal_year.rb Outdated Show resolved Hide resolved
lib/nepali_calendar/fiscal_year.rb Outdated Show resolved Hide resolved
lib/nepali_calendar/fiscal_year.rb Outdated Show resolved Hide resolved
lib/nepali_calendar/fiscal_year.rb Outdated Show resolved Hide resolved
lib/nepali_calendar/fiscal_year.rb Outdated Show resolved Hide resolved
lib/nepali_calendar/fiscal_year.rb Outdated Show resolved Hide resolved
lib/nepali_calendar/fiscal_year.rb Outdated Show resolved Hide resolved
@sarojkh
Copy link
Collaborator

sarojkh commented Jun 8, 2022

@sangamsth In addition to my review comments above, about 10+ spec examples are currently failing. The whole suite should pass. Try running rspec . in the project home directory.

cc @Sagar535

@sangamsth sangamsth requested a review from sarojkh June 8, 2022 09:57
@sarojkh
Copy link
Collaborator

sarojkh commented Jun 8, 2022

@sangamsth Ideally we want to re-request for a review, after the author of the PR has made necessary changes from the review, or else has put an argument against the requested changes.

Removing the review request for now. Re-request again, when applicable.

@sarojkh sarojkh removed their request for review June 8, 2022 10:32
@sangamsth sangamsth requested a review from sarojkh June 10, 2022 07:39
Copy link
Collaborator

@sarojkh sarojkh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@sarojkh sarojkh merged commit 51bda35 into Daanphe:master Jun 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants