rascal
rascal copied to clipboard
Add subtraction operator between two datetime values and produce a "duration"
I was trying to get the elapsed time between two places in code, a start point, and an end point. To do this, from the current Rascal API, I did a call to function now(), stored in a variable, and then a call to now() minus the initial stored variable. Doing so in Rascal Console I've got no errors and worked by returning a Duration type (Example: Duration: duration(0,0,0,0,0,1,182)) . But the Eclipse IDE gives me an error in the Editor and in the Problems View with the message:
Subtraction not defined on
datetimeanddatetime
To Reproduce
module Test
import DateTime;
public void main() {
start_time = now();
end_time = now() - start_time;
}
Steps to reproduce the behavior:
See error in? Eclipse Editor, Problems Log.
Expected behavior Expected no error, considering that the computation is done.
Screenshots
Stack traces
Description Resource Path Location Type Subtraction not defined on
datetimeanddatetimeFuzzerMain.rsc /rascalfuzz/src line 30 rascal_markers
Desktop (please complete the following information):
Rascal Version: 0.18.2, see |release-notes://0.18.2| Rascal Developers JUnit extension 0.18.2 rascal_developers_feature.feature.group null The Rascal MetaProgramming Language 0.18.3 rascal-feature.feature.group NWO_I_CWI
Indeed, we don't have durations as a basic time, I can agree that it's missing. The Datetime library does contain it.
But for benchmarking purposes, check out util:: Benchmark. We also have a profiler in the REPL that you can activate with :set profiling true
I would also expect - to work like this but it doesn't because the duration type is not a primitive. It should be to make the design complete. What I'm waiting for is the addition of units of measure. A duration is measured in time (seconds) for example. With the addition of units of measure we don't have to add yet another primitive type for durations. Until then, let's wait and use the library functions for datetime.
Changed this into a feature enhancement. Let's keep it open until we add it.
Indeed, we don't have durations as a basic time, I can agree that it's missing. The Datetime library does contain it.
But for benchmarking purposes, check out
util:: Benchmark. We also have a profiler in the REPL that you can activate with:set profiling true
Thanks, I didn't see this package. The function realTime deals with what I need, and I managed to use it in substitution of now.