-
Notifications
You must be signed in to change notification settings - Fork 6
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
Date utilities module #17
Comments
For epoch we have : To Epoc %dw 2.0
output application/json
---
now() as Number {unit: "seconds"} From Epoc %dw 2.0
output application/json
---
1592601210 as DateTime {unit: "seconds"} Days in a month is tricky as it may depend in the year (We all like feb) But the other day a request came that we should be able to extract more information from timezeone {
"displayName": "Eastern Standard Time",
"dstSavings": 3600000,
"id": "America/New_York",
"observesDaylightTime": true,
"rawOffset": -18000000,
"useDaylightTime": true
} This kind of information. This may be interesting to analyze. Regarding date functions I think we also need Period factory methods. Today if I want to substract a dynamic amount of days I need to use string interpolation and coercion. now() - Period::days(1) |
|
As Jerney said, days in month is easy, if you have a given date. A little weird, but I use something similar to get the first or last day of the month. I wrote my own date module for stuff like this.
Results:
|
I love this idea, the string interpolation for dynamic periods is really annoying when you don't know how to do it. Easy, like most things, after you figure it out. |
I'm going to separate this thing in two parts
|
I propose one single module %dw 2.0
fun today():Date =
now() as Date
fun month(months: Number):Period =
"P$(months)M" as Period
fun years(months: Number):Period =
"P$(months)Y" as Period
fun days(nDays: Number):Period =
"P$(nDays)D" as Period
fun hours(nHours: Number):Period =
"PT$(nHours)H" as Period
fun minutes(nMinutes: Number):Period =
"PT$(nMinutes)M" as Period
fun seconds(nSecs: Number):Period =
"PT$(nSecs)S" as Period
fun toBeginningOfHour(dateTime: DateTime) =
"$(dateTime as Date)T$(dateTime.hour):00:00.000$(dateTime.timezone)" as DateTime
fun toBeginningOfDay(dateTime: DateTime) =
"$(dateTime as Date)T00:00:00.000$(dateTime.timezone)" as DateTime
fun toBeginningOfMonth(dateTime: DateTime) =
"$(dateTime as Date - days(dateTime.day))T00:00:00.000$(dateTime.timezone)" as DateTime
fun toBeginningOfWeek(dateTime: DateTime) =
"$(dateTime as Date - days(dateTime.dayOfWeek))T00:00:00.000$(dateTime.timezone)" as DateTime
fun toBeginningOfYear(dateTime: DateTime) =
"$(dateTime as Date - days(dateTime.dayOfYear))T00:00:00.000$(dateTime.timezone)" as DateTime Now we also have things like : {
"wday": now().dayOfWeek, //This will return 2
"yday": |2020-09-29T16:11:12.195-03:00|.dayOfYear, // This return the day of the year for example 273
} The question is shouldn't this be functions? there are transformations in this selection. For me |
It could be useful to have a date module, with common operations that are used in businesses, like days in a month, and epoch time conversion to date/time.
The text was updated successfully, but these errors were encountered: