-
Notifications
You must be signed in to change notification settings - Fork 4
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
Fiscal year #5
Conversation
…ntation of FiscalYear class
There was a problem hiding this 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
lib/nepali_calendar/fiscal_year.rb
Outdated
@@ -0,0 +1,25 @@ | |||
class NepaliCalendar::FiscalYear < NepaliCalendar::Calendar |
There was a problem hiding this comment.
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.
lib/nepali_calendar/bs_calendar.rb
Outdated
# 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 |
There was a problem hiding this comment.
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
lib/nepali_calendar/bs_calendar.rb
Outdated
# 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to above.
lib/nepali_calendar/bs_calendar.rb
Outdated
# 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 |
There was a problem hiding this comment.
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
- Get fy beginning in bs date
- Convert the bs date to ad date.
lib/nepali_calendar/fiscal_year.rb
Outdated
@@ -0,0 +1,25 @@ | |||
class NepaliCalendar::FiscalYear < NepaliCalendar::Calendar |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
lib/nepali_calendar/fiscal_year.rb
Outdated
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 |
There was a problem hiding this comment.
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.
lib/.byebug_history
Outdated
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lib/nepali_calendar/bs_calendar.rb
Outdated
# 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 |
There was a problem hiding this comment.
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)
lib/nepali_calendar/ad_calendar.rb
Outdated
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 |
There was a problem hiding this comment.
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)
lib/nepali_calendar/fiscal_year.rb
Outdated
end | ||
end | ||
|
||
def self.fiscal_year_for_bs_date(bs_year, bs_month, bs_day) # (2079, 2, 12) ==> 7879 |
There was a problem hiding this comment.
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.
lib/nepali_calendar/fiscal_year.rb
Outdated
end | ||
|
||
def self.current_fiscal_year | ||
current_year = NepaliCalendar::BsCalendar.ad_to_bs(Date.today.year, Date.today.month, Date.today.day) |
There was a problem hiding this comment.
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
.
lib/nepali_calendar/fiscal_year.rb
Outdated
# FiscalYear.new(start_year, end_year).end_of_year | ||
# end | ||
|
||
def self.get_fiscal_year_from_ad(ad_date) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def self.get_fiscal_year_from_ad(ad_date) | |
def self.fiscal_year_for_ad_date(ad_date) |
There was a problem hiding this 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 In addition to my review comments above, about 10+ spec examples are currently failing. The whole suite should pass. Try running cc @Sagar535 |
@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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
No description provided.