Implementation of operation (TimeOnly - TimeOnly) #60056
-
Hello, runtime/src/libraries/System.Private.CoreLib/src/System/TimeOnly.cs Lines 249 to 255 in d2cef2f Could anybody explain (or point the exists discussion) the reason of this implementation?
Current implementation returns time in data type for interval. It is correct? Reason of this question. In provider for EFCore need map this operation to SQL. DBMS (PG, Firebird) for expression time '01:00:00' - time '03:00:00' returns negative value: -02:00:00. Subtract operator of TimeOnly returns positive value "22:00:00". Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
In the ISO world (and in reality), there is no such thing as a negative duration. (Although I personally agree with you here, that it does make some operations easier). This was debated at design time, and changing it now would be a massive breaking change.
"Time" has multiple uses in English - the phrase "time me", for instance, is asking for a duration, not the wall-clock time. Hence why it's "elapsed time" in the method documentation.
If the values are subtracted on the database side, the value returned will be a negative timestamp. If you're emulating this in the EFCore mapping, you need to add an extra check. |
Beta Was this translation helpful? Give feedback.
-
"elapsed time" is the same as "a span of time", so TimeSpan is correct for that one.
|
Beta Was this translation helpful? Give feedback.
-
When you have a The result is a |
Beta Was this translation helpful? Give feedback.
In the ISO world (and in reality), there is no such thing as a negative duration. (Although I personally agree with you here, that it does make some operations easier). This was debated at design time, and changing it now would be a massive breaking change.
"Time" has multiple uses in English - the phrase "time me", for instance, is asking for a duration, not the wall-clock time. Hence why it's "elapsed time" in the method documentation.