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

Adding daysRemaining(in:) to DateExtensions. #982

Closed
wants to merge 3 commits into from

Conversation

pbeyer08
Copy link

@pbeyer08 pbeyer08 commented Aug 31, 2021

Addresses #552.

This PR adds a Date extension which returns the number of days remaining in various Calendar.Components such as .month or .year.

Checklist

  • I checked the Contributing Guidelines before creating this request.
  • New extensions are written in Swift 5.0.
  • New extensions support iOS 10.0+ / tvOS 9.0+ / macOS 10.10+ / watchOS 2.0+, or use @available if not.
  • I have added tests for new extensions, and they passed.
  • All extensions have a clear comments explaining their functionality, all parameters and return type in English.
  • All extensions are declared as public.
  • I have added a changelog entry describing my changes.

@pbeyer08
Copy link
Author

NOTE: This extension uses end(of:) and daysSince(:) extensions, which in turn depend on various other Date extensions. I assume the following contribution rule does not apply here:

Do not use an existing SwifterSwift extension inside another SwifterSwift extension. All extensions should be able to be copied and pasted and work immediately without having to copy another extension.

@pbeyer08 pbeyer08 marked this pull request as ready for review September 1, 2021 15:37
return Int(daysRemaining)
}
default:
()
Copy link
Contributor

@erikdrobne erikdrobne Sep 3, 2021

Choose a reason for hiding this comment

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

You could also return nil in the default case:

default:
    return nil

Copy link
Contributor

Choose a reason for hiding this comment

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

You have to return from this function outside the switch, so better to use

Suggested change
()
break

Copy link
Contributor

@guykogus guykogus left a comment

Choose a reason for hiding this comment

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

Nice. Just a few small suggestions.
N.B. Agree that it makes sense here to use another end(of:), more because it's a pretty complicated function than because that one already uses others.

@@ -57,6 +57,8 @@ The changelog for **SwifterSwift**. Also see the [releases](https://github.com/S
- Added `loadFromNib(withClass:)`, which loads a UIView of a particular type from a nib file. [#885](https://github.com/SwifterSwift/SwifterSwift/pull/885) by [gurgeous](https://github.com/gurgeous)
- Added `findConstraint` for finding an existing constraint. [#886](https://github.com/SwifterSwift/SwifterSwift/pull/886) by [gurgeous]
- Added `widthConstraint`, `heightConstraint`, `leadingConstraint`, `trailingConstraint`, `topConstraint`, and `bottomConstraint` for finding specific constraints. [#886](https://github.com/SwifterSwift/SwifterSwift/pull/886) by [gurgeous]
**Date**:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
**Date**:
- **Date**:

XCTAssertEqual(Date(year: 2021, month: 8, day: 31, hour: 1)?.daysRemaining(in: .weekOfYear), 4)
XCTAssertEqual(Date(year: 2021, month: 9, day: 11, hour: 1)?.daysRemaining(in: .weekOfYear), 0)
XCTAssertEqual(Date(year: 2020, month: 2, day: 23, hour: 1)?.daysRemaining(in: .weekOfMonth), 6) // leap

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove empty line

return Int(daysRemaining)
}
default:
()
Copy link
Contributor

Choose a reason for hiding this comment

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

You have to return from this function outside the switch, so better to use

Suggested change
()
break

@codecov
Copy link

codecov bot commented Sep 12, 2021

Codecov Report

Merging #982 (e8cf920) into master (b161dc0) will increase coverage by 0.04%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #982      +/-   ##
==========================================
+ Coverage   92.92%   92.97%   +0.04%     
==========================================
  Files         102      103       +1     
  Lines        3691     3717      +26     
==========================================
+ Hits         3430     3456      +26     
  Misses        261      261              
Flag Coverage Δ
ios 95.52% <100.00%> (+0.03%) ⬆️
macos 83.01% <100.00%> (+0.17%) ⬆️
tvos 95.66% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...urces/SwifterSwift/Foundation/DateExtensions.swift 100.00% <100.00%> (ø)
...terSwift/SwiftStdlib/BinaryIntegerExtensions.swift 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b161dc0...e8cf920. Read the comment docs.

@SwifterSwiftBot
Copy link

1 Message
📖 Thank you for submitting a pull request to SwifterSwift. The team will review your submission as soon as possible.

Generated by 🚫 Danger

@stale
Copy link

stale bot commented Apr 16, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants