OData / OData/AspNetCoreOData

$compute Arithmetic Operators with DateTime, Duration not working as expected

Open
#556 1 comment 2 reactions 1 assignee View on GitHub

@habbes is already working on this.

Since Apr 12, 2022.

bug investigating
Dominant language
C#
Stars
505
Forks
186
PR merge metrics
No merged PRs in 30d

Description

Assemblies affected: ASP.NET Core OData 8.0.8

Due to lack of documentation, OData is an obscure framework to use.
According to this OData v4 documentation http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_ArithmeticOperators, when we use $compute=InitialDate sub now() the returned value should be an Edm.Duration being InitialDate and now() Edm.DateTimeOffset. when we call $compute=InitialDate sub duration'P2D' the returned value should be an Edm.DateTimeOffset.

Both calls return cast excepetion, unless we cast the result to Edm.String. The problem is we can't parse that string to use in a $filter or something like that.

Reproduce steps
Run: $compute=now() sub 2021-01-01T00:00:00-00:00 as TimeToYearStart
Or: $compute=now() sub duration'P7D' as LastWeek

Expected behavior
TimeToCentury: ~ duration'P100D'
LastWeek: ~ 2021-04-01T00:00:00-00:00

Workaround
$compute=cast(now() sub 2021-01-01T00:00:00-00:00, Edm.String) as TimeToYearStart
$compute=cast(now() sub duration'P7D', Edm.String) as LastWeek

TimeToYearStart: "220305172941.000000"
LastWeek: "20220404493051.000000"

Screenshots
Image20220406142423

Additional context
If someone has any updated documentation, please share! We shouldn't have to read all the source code of a framework in order to use it

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.