stsc / DateTime-Format-Natural

Parse informal natural language date/time strings
5 stars 5 forks source link

Wishlist: add quarter as a keyword #5

Closed xiaoyafeng closed 1 year ago

xiaoyafeng commented 5 years ago

what's one of the best on DT::F::N is that it provides a handy jump: last this next, 1st, 2nd etc which I can set a people-read unit: day, week, month or may july, june etc. Recently my customer would like to request a new unit: "quarter". from my respective, quarter is just an alias of month: quarter1 is January; quarter2 is April quarter3 is July quarter4 is October this quarter: my $dt = DateTime->now; $dt->clone->subtract(days, $dt->doq); last quarter: my $dt = DateTime->now; $dt->clone->subtract(days, $dt->doq)->subtract(months, 3); ........ I could make another rewrite function to treat quarter before sending the string to DT::F::N, but since quarter as a time unit is very popular and useful on financial area, I suggest you could consider adding it on next version. Thanks.

stsc commented 5 years ago

Can you please apply following patch to DT::F::N v1.06 (as on CPAN) and let me know if it works for you as a starting point? dtfn.diff.txt

xiaoyafeng commented 5 years ago

Wow! thanks for your prompt reply! I'm been so busy recently(life is always busy!;() that I can't perform full test on this. but I did some test manually and it runs as I want. just 2 things:

  1. it's my fault, this quarter should be $dt->subtract(days, $dt->doq -1)
  2. As my first post, beside "quarter", quarter alias of January, April July and October is also required. like: last quarter1( means last January), this quarter4 (means this October ) etc.
stsc commented 5 years ago
  1. No idea, I just trust you :-).
  2. quarter1, quarter2, ... are barely "human-readable", so I'm reluctant to include it as is. If you can come up with something more sensible :-), i'm willing to consider it.
xiaoyafeng commented 5 years ago

I've advised with my accounting colleagues about "fiscal year". Q1, Q2... are terms of 3 months period on financial calendar. You can refer to thishttps://www.investopedia.com/terms/q/quarter.asp But there raise another issue that because not all financial quarter correspond to normal calendar quarter and user can set beginning of week/month/quarter/year as needed, unfortunately DT::F::N doesn't support it yet(as I know). since there are already some fiscal/financial DateTime module on CPAN, so I think it's up to you, either add fully financial calendar support on future version or simply set quarter1,2,3,4 as I mentioned on first post. I just point out quarter1,quarter2 are not just barely "human-readable". ;)

stsc commented 5 years ago

Made a release (v1.06_01) which partially addresses your wish(es). Let me know, if it works for you so far!

xiaoyafeng commented 5 years ago

It perfectly meet what I need, Thanks!

stsc commented 5 years ago

As for 2: can't "we" just use Q1, Q2, Q3 & Q4 instead (and ignore non-standard quarters, until the need to parse them arises? :-)

stsc commented 1 year ago

Closing. Feel free to raise another issue if desired.