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

Provide functions to check bounds for the input provided. #44

Merged
merged 1 commit into from
Jan 17, 2020

Conversation

axispx
Copy link
Contributor

@axispx axispx commented Jan 1, 2020

Instead of panicking in the user facing interface for invalid date. Log an error instead.

@coveralls
Copy link

coveralls commented Jan 1, 2020

Pull Request Test Coverage Report for Build 185

  • 12 of 29 (41.38%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-2.3%) to 72.404%

Changes Missing Coverage Covered Lines Changed/Added Lines %
dateconv/dateconv.go 12 18 66.67%
cli.go 0 11 0.0%
Totals Coverage Status
Change from base Build 179: -2.3%
Covered Lines: 244
Relevant Lines: 337

💛 - Coveralls

Copy link
Owner

@srishanbhattarai srishanbhattarai left a 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)
Copy link
Owner

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)
Copy link
Owner

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 {
Copy link
Owner

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.

@srishanbhattarai srishanbhattarai added the enhancement New feature or request label Jan 2, 2020
Instead of panicking in the user facing interface for invalid date. Log an error instead.
Copy link
Owner

@srishanbhattarai srishanbhattarai left a comment

Choose a reason for hiding this comment

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

👍

@srishanbhattarai srishanbhattarai merged commit 8923872 into srishanbhattarai:master Jan 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants