winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
5.02k stars 197 forks source link

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

Open asterkin opened 4 months ago

asterkin commented 4 months ago

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

Chriscbr commented 3 months ago

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

github-actions[bot] commented 3 weeks ago

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!