icza / gox

Minimalistic extension to Go. It means to be a complement to the standard library.
Apache License 2.0
132 stars 14 forks source link

Added NextWeekday function #3

Closed bincyber closed 3 years ago

bincyber commented 3 years ago

Hi :wave:

I came across this library via StackOverflow when looking for a way to parse a weekday string into a time.Weekday. Thanks for open sourcing this.

This PR adds a NextWeekday utility function to answer the question of:

Given an arbitrary date, what is the date of the next weekday (eg, Friday)?

Example usage:

// Given the date today is Tuesday, Jan 26th, 2021
now := time.Date(2021, time.January, 26, 11, 0, 0, 0, time.UTC)

// Get the timestamp of next Friday at 12pm UTC
t := NextWeekday(now, "Friday", 12, time.UTC)
icza commented 3 years ago

Hi. Thanks for your PR.

I'm hesitating to merge it. I try to keep this library small, as its description says: "Minimalistic extension to Go". I'm not sure this addition is common enough to be included. I've never needed this functionality / utility.

bincyber commented 3 years ago

Thanks for reviewing. I'll close this PR.