-
Notifications
You must be signed in to change notification settings - Fork 5
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
Provide functions to check bounds for the input provided. #44
Conversation
Pull Request Test Coverage Report for Build 185
💛 - Coveralls |
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.
Thanks for the change! This should be helpful
I added a few comments otherwise it looks good to merge
cli.go
Outdated
@@ -35,6 +35,11 @@ func (nepcalCli) convADToBS(c *cli.Context) { | |||
|
|||
mm, dd, yy, _ := parseRawDate(c.Args().First()) | |||
adDate := toTime(yy, time.Month(mm), dd) | |||
if err := dateconv.CheckBoundsAD(adDate); err != nil { | |||
fmt.Println(err) |
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.
write to stderr
- fmt.Println(err)
+ fmt.Fprintln(os.Stderr, err)
cli.go
Outdated
@@ -48,6 +53,12 @@ func (nepcalCli) convBSToAD(c *cli.Context) { | |||
} | |||
|
|||
mm, dd, yy, _ := parseRawDate(c.Args().First()) | |||
bsdate := dateconv.NewBSDate(yy, mm, dd) | |||
if err := bsdate.CheckBounds(); err != nil { | |||
fmt.Println(err) |
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.
same here
@@ -47,6 +47,30 @@ func (b BSDate) After(u BSDate) bool { | |||
return dateA > dateB | |||
} | |||
|
|||
// CheckBounds checks if the conversion is possible. Raises an error is an out | |||
// of bound input is provided. Date after 2000 Baisakh 1 should be provided. | |||
func (b BSDate) CheckBounds() error { |
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 add some tests for these, would rather merge these in with some (trivial) tests even though they are pretty simple.
Instead of panicking in the user facing interface for invalid date. Log an error instead.
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.
👍
Instead of panicking in the user facing interface for invalid date. Log an error instead.