Open machaval opened 4 years ago
This is releated from #17
I think
var nHours = period.hours default 0 + ((nDays - days) * 60)
should be
var nHours = period.hours default 0 + ((nDays - days) * 24)
Would it be possible to set a return format for the between function? This would allow the function to return different time formats. Example:
import * from dw::core::Periods
output application/json
---
{
a: between(|2010-12-12|,|2010-12-10|) // default, returns a period
b: between(|2010-12-12|,|2010-12-10|, "seconds") // returns difference in seconds
c: between(|2010-12-12|,|2010-12-10|, "hours") // returns difference in hours
}
==== Output
{
"a": "P2D",
"b": 172800,
"c": 48
}
The idea is to not truncate seconds
anywhere to handle milis or even nanos? What does Period support? I'm thinking about problems that can arise about not defining hard limits.
Would it be possible to set a return format for the between function? This would allow the function to return different time formats...
Now you can do:
between(|2010-12-12|,|2010-12-10|) as Number {unit: "months"}
Not very intuitive to guess you need to write "months" neither.
The other way can be also to create casting functions like toDays()
but you will end with a full list of methods like this one. I'm not sure which is the cleanest way.
Sorry for not explaining between
function was introduce because of a backwards comp issue. For date - date operator it used to return a Period and not a Duration. This was very problematic as Duration is the only thing that can be translated to millis o any other unit of time. So we changed date - date
to return Period so it is consistent with datetime - datetime
etc... but in order to have a migration path we introduce a System property that behaves just as it used to be and we also introduce this function that returns the Period between the two dates.
Regarding type conversions we have a separate issue #18 where we should start talking about this kind of things. We know is it not intuitive to do this so we think we should start working on a new way of doing this things.
I see we are tackling durations against Time, but what about working with durations to sum or subtract them? Would simplify this scenario https://stackoverflow.com/questions/68958484/how-to-aggregate-data-with-particular-column-using-dataweave-2-0
After discussing that dates manipulation is hard we started working on a way to create Periods. I would like to start discussing the new additions
dw::core::Periods
Examples
A duration is a Time Based Period. And a Period is a Date base Period.
Time based does support decimal numbers and the correct calculation should be done. Date based DOESN'T support decimal numbers and it will FAIL.