go-dateparser icon indicating copy to clipboard operation
go-dateparser copied to clipboard

last day/week/month should return the start of the time period?

Open a5r0n opened this issue 2 years ago • 1 comments

a5r0n avatar Aug 09 '24 08:08 a5r0n

Sorry for the late response.

Unfortunately, your request is a bit too vague for me to act on directly. However, if I understand correctly, you're suggesting that:

  • "yesterday" should return midnight of the previous day, e.g. if the current time is 2025-04-30 07:04, then "yesterday" would return 2025-04-29 00:00
  • "last week" should return the Monday of the previous week, e.g. if today is Wednesday, 30 April 2025, then "last week" would return Monday, 21 April 2025 00:00
  • "last month" should return the 1st of the previous month

If that's the case, then unfortunately this behavior isn't supported. go-dateparser follows the behavior of Python’s dateparser, which fills in any missing date components using the current time. For relative patterns like "last week" or "last month", the date is calculated mathematically based on the current timestamp. So, using 2025-04-30 07:04 as the current time:

  • "yesterday" returns 2025-04-29 07:04
  • "last week" returns 2025-04-23 07:04 (Wednesday of the previous week)
  • "last month" returns 2025-03-30 07:04

There are currently no plans to change this behavior, as doing so would break existing code that relies on the current interpretation.

Hope that clears things up.

RadhiFadlillah avatar Apr 30 '25 00:04 RadhiFadlillah