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

Ability to only parse dates in the future #258

Open
thomasbrunstrom opened this issue Apr 11, 2016 · 13 comments
Open

Ability to only parse dates in the future #258

thomasbrunstrom opened this issue Apr 11, 2016 · 13 comments

Comments

@thomasbrunstrom
Copy link

I would like to have the possibility to set a "latest" date which the parser should match against.
For instance, if i write Sunday on a Monday, I don't want to match yesterday but next Sunday.
In my particular case i would like to only match dates in the future.

Maybe this is something that's already supported but I cant find anything in the documentation about it.

@abritinthebay
Copy link
Owner

It's certainly not supported currently. What would be the behavior in the case of an earlier date? Return Null? Undefined? False? Throw? I'd lean towards the same behavior as non-parsable dates/invalid strings.

Thoughts?

@thomasbrunstrom
Copy link
Author

I would say that if it would'nt match "yesterday" for instance, just return the same result as non-parsable date. What I've seen in other libraries is that you can pass a reference date to parser which could be nice.
In sugar.js there is two functions called future and past that do this, as far as I can tell. Maybe that is something to look into?

@abritinthebay
Copy link
Owner

Well the sugar.js ones merely prefer past or future dates - they don't limit. Rather major difference.

Would that be preferable or were you specifically looking for a limit?

@thomasbrunstrom
Copy link
Author

Well, for my specific purpose I would like to be able to limit the parsing to dates in the future. For instance, if I'm selling tickets for events, there is no point in trying to sell tickets in the past.
And my concern in this case is that if i write monday today(wednesday) I would like to get the next monday, not the day before yesterday.

@abritinthebay
Copy link
Owner

Ah, yeah... that specific behavior is a fun one.

Well in your case the "prefer" behavior would work best anyhow really wouldn't it? it would prefer next monday not this monday and therefore satisfy the requirements?

I like the idea of the .past and .future functions but would prefer to keep a common API as one has been established by Sugar.js in this case.

@thomasbrunstrom
Copy link
Author

I'm sorry, I'm not following now. If you don't want to add .past and .future, how would you want to handle it?

@abritinthebay
Copy link
Owner

No, I DO want to. Just clarifying that if I did and followed the Sugar,js API and behavior that that would work for you...?

@thomasbrunstrom
Copy link
Author

Yes, absolutely. I would gladly help but at the moment it would take to much time to just figure out the flow of the parsing and such. Do you have any idea of a time scale on this?

@abritinthebay
Copy link
Owner

Unfortunately it's not going to be very soon - I'm really the sole developer on this and have had my time taken up with paid work, and will likely be pretty swamped during the summer.

@thomasbrunstrom
Copy link
Author

Oh ok, well in that case I might be able to get something sorted out sooner. Kind of new to how github works, but do i just check out the code, modify and do a pull request?
If you allow contributors that is?

@abritinthebay
Copy link
Owner

Yup! I'd highly encourage contributors! Not least because I have limited time lately.

Basically you fork the repo, make the edits, add some tests, and then create a Pull Request for it. Then I can review the changes, and we can discuss any tweaks, and it can be merged into the master branch here.

@thomasbrunstrom
Copy link
Author

Ok, sounds solid! I'll see what I can get rolling in the next couple of days. But just to be clear, a .past .future solution is preferred?

@abritinthebay
Copy link
Owner

Yep! One that doesn't ignore dates (you might explicitly pass a past date in) but prefers them (like in your use case of when "monday" is)

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

No branches or pull requests

2 participants