wing icon indicating copy to clipboard operation
wing copied to clipboard

Additional arithmetics, formatting and parsing functions for std.Datetime.

Open asterkin opened this issue 1 year ago • 2 comments

Use Case

  1. There is a need to perform simple plus/minus arithmetics between std.DateTime and Duration: let now = datetime.systemNow(); let expiration = now + duration.fromHours(1); let validFor = expiration - now; assert(now <= expiration); assert(expiration > now); ...
  2. There is a need for additional formatting and parsing functions: let now = datetime.utcNow(); log(now.toUtcString()); let sd = "2024/06/18 16:15"; let d = datetime.parse(sd, datetime.YYYYMM_HHMM); assert(d.format(datetime.YYYYMM_HHMM), sd);

Proposed Solution

You may find a sample implementation here: https://github.com/asterkin/endor.w/tree/main/datetimex

Implementation Notes

Some conversions from JavaScript Date to Wing DateTime are performed via ISO string which is inefficient.

Component

SDK

Community Notes

  • Please vote by adding a 👍 reaction to the issue to help us prioritize.
  • If you are interested to work on this issue, please leave a comment.
  • If this issue is labeled needs-discussion, it means the spec has not been finalized yet. Please reach out on the #dev channel in the Wing Discord.

asterkin avatar Jun 18 '24 13:06 asterkin

I ran into friction with this as well -- it would be great to have more operations adding, subtracting, and comparing dates and durations where appropriate. See also these issues (https://github.com/winglang/wing/issues/6297) and (https://github.com/winglang/wing/issues/6298).

An example would be "I would like to obtain a datetime value representing one week from now".

Formatters for converting datetime to strings would also be helpful

Chriscbr avatar Jun 26 '24 21:06 Chriscbr

Hi,

This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!

github-actions[bot] avatar Sep 25 '24 06:09 github-actions[bot]