1

Is there any FO-native possibility for getting the exact difference between two abas date objects?

I have a AJO-based solution comparing two Calendar-Objects, but it's too slow for my use-case (it's called to many times) and I hope there is a native solution.

And what is the highest accuracy the abas dates (GD-Fields) can represent? Just Seconds or is there a way to get a UNIX-time-stamp or something comparable for a higher precision.

aphex
  • 3,372
  • 2
  • 28
  • 56
mupfin
  • 49
  • 7

1 Answers1

1

Yes, you can use the GP4 type.

.type GD19 xdbegin xdend
.type GP4  xgdiff
.formula U|xdbegin = "1.1.2015 00:00:00"
.formula U|xdend   = "1.1.2016 00:00:00"
.formula U|xgdiff  = U|xdend-U|xdbegin
'U|xgdiff'

output will be 365D00h00m00s

Now you can convert it e.g. into seconds:

.type text xtcmd
.type int  xisec
.formula U|xtcmd = "formula U|xisec = " + F|regreplace(F|regreplace(F|regreplace(F|regreplace('U|xgdiff', "D", "*24*60*60+"), "h", "*60*60+"), "m", "*60+"), "s", "")
.'U|xtcmd'

As far as I know "seconds" is the highest precision you can use in FO. If you need more, you have to use (as you already mentioned) UNIX-time-stamps

Alexander Baltasar
  • 1,044
  • 1
  • 12
  • 25
  • 1
    Do you know a possibility to get the seconds of a GP4 type? Or do I have to parse it? – mupfin Nov 03 '15 at 14:19
  • Unfortunately you have to parse it. What exactly are you trying to do with the "seconds" part? – Alexander Baltasar Nov 03 '15 at 14:30
  • It's just for the output. In some cases it's more pretty to see 95 seconds instead of 1m35s. But this GP4 type is a good solution and works for me. thanks =) – mupfin Nov 04 '15 at 07:00
  • If a a GP4 type could return the result in seconds it would be much easier to convert in different output formats. – mupfin Nov 04 '15 at 14:53
  • Now I have a use case where I need a percentage part of a time difference. Here an easy second conversion would be helpful too, because you can not calculate with the GP4 (only addition and subtraction). – mupfin Nov 09 '15 at 09:15
  • Just see my answer. I already showed how to convert a GP4 value into seconds. – Alexander Baltasar Nov 09 '15 at 09:21
  • Yes I know... but I don't like the solution and it's annoying that abas have such horrible methods for handling dates and times. It was more a flame comment, sorry ;D – mupfin Nov 09 '15 at 10:12
  • And I like your solution!!!! What I don't like is the FO-solution for handling time and dates ^^ – mupfin Nov 09 '15 at 10:21