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

Create Date/DateInRegion at the next day of the week (ie. "Next Friday" [since ref date]) #214

Closed
otymartin opened this issue May 15, 2016 · 8 comments
Assignees
Milestone

Comments

@otymartin
Copy link

@malcommac
I'm new to this library so I haven't discovered yet how to create these objects. I couldn't find any direct references in the swift files.

Next Friday
Next Saturday
Next Sunday

@malcommac
Copy link
Owner

malcommac commented May 24, 2016

We don't support it yet, but seems a nice addition.
Meanwhile you can user NSCalendar's nextDateAfterDate() method.
Let me show to you an example about:

let components = NSDateComponents()
components.weekday = 1 // in Gregorian 1 is Sunday
let nextSunday = self.calendar.nextDateAfterDate(self.absoluteTime, matchingComponents: components, options: [.MatchNextTimePreservingSmallerUnits])

@Hout
Copy link
Contributor

Hout commented May 24, 2016

If added then please add to docs that next Friday means the first Friday after today.
Not to be confused with the Friday in next week.

@otymartin
Copy link
Author

otymartin commented May 25, 2016

@malcommac Thanks

I had since simplified what i was trying to do however I believe that would be a really handy convenience method to offer. I basically wanted my users to create events. Using UIDatePicker I wanted to limit the possible options to the following Friday Saturday or Sunday on the condition that those days are atleast 5 days away. (Gives users time to organize themselves, Didn't want next Friday to be tomorrow)

So my first time using the library, i was playing around trying to create these objects with this syntax
var nextFriday = NSDate().nextFriday I guess it just felt natural even though the method didn't exist.
etc..

//My simplified solution 😂

       let today = NSDate()
        let day1 = today + 1.days
        let day2 = today + 2.days
        let day3 = today + 3.days
        let day4 = today + 4.days
        let day5 = today + 5.days
        let day6 = today + 6.days
        let day7 = today + 7.days
e.tc..

@malcommac malcommac added this to the 4.1.0 milestone Sep 30, 2016
@malcommac malcommac self-assigned this Sep 30, 2016
@malcommac
Copy link
Owner

I've scheduled it for 4.1.0.

@otymartin
Copy link
Author

@malcommac Dope 🙌

@malcommac malcommac modified the milestones: 4.0.8, 4.1.0 Nov 30, 2016
@malcommac malcommac changed the title Create Date Objects for Specific Days of the Week Create Date/DateInRegion at the next day of the week (ie. "Next Friday" [since ref date]) Nov 30, 2016
@malcommac
Copy link
Owner

malcommac commented Nov 30, 2016

Added in 4.0.8 (b9d6cec).
We have .next() func both for Date and DateInRegion objects.

Examples:

let now = DateInRegion() // 30 nov 2016, 13:55:04 CET
let nextFriday = now.next(day: .friday) // 02 dic 2016, 00:00:00 CET
let nextMonday = now.next(day: .monday) // 05 dic 2016, 00:00:00 CET

malcommac added a commit that referenced this issue Nov 30, 2016
@otymartin
Copy link
Author

beautiful thanks @malcommac

@malcommac
Copy link
Owner

Thank you for your suggestion :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants