Why is there a preceding 0 in the "patch" version reported by `-version` flag?

0 votes
asked Feb 2, 2021 in Question / help by karfau (120 points)
When calling `java -jar plantuml-1.2021.1.jar -version` it reports `1.2021.01` but the java version of the library is `1.2021.1`.

What is this additional `0` good for?

(The previous version reported `1.2021.0`, and most likely the 11th version this year will again report `1.2021.10`, as the later versions last year did.)

This makes it harder to compare expected versions in an integration test, e.g.

https://github.com/karfau/plantuml-docker/pull/25/commits/d05fd6b0f01b746229aa6a1c3f0993164f684e6c

Could it be removed?
commented Feb 3, 2021 by Serge Wenger Work (14,600 points)
Hello,

If you sort versions as strings, the order is not correct if you have different digits count:

1.2021.0
1.2021.1
1.2021.10
1.2021.2

If you use 2 digits
1.2021.0
1.2021.01
1.2021.02
1.2021.10
commented Mar 17, 2021 by karfau (120 points)
changing the string representation of a version just for easy command line sorting doesn't make sense for me, it would mean that you know how may verisons you will have before switching to the next minor version. what if you need to have 100 versions in 2022, and why is `.0` not `.00`?

2 Answers

0 votes
answered Feb 5, 2021 by plantuml (276,340 points)
selected Mar 17, 2021 by karfau
 
Best answer
Yes, it's difficult to know which is the best...

Both have pros and cons...

However, I am wondering if we are not going to switch and remove this "additional" 0.

So, as test, we have changed -version behavior on last beta http://beta.plantuml.net/plantuml.jar

@Serge: tell us if it's an issue for you.
commented Feb 5, 2021 by Serge Wenger Work (14,600 points)
I prefer with additional 0, but it's not a problem for me.
commented Mar 17, 2021 by karfau (120 points)
Thanks a lot, I think dropping this leading 0 makes more sense.
Not sure what too say about using some simple sorting mechanism on a version number... it's not just a string that you can sort. Tere is a (numeric) meaning behind every part of the version number and there are many more cases that need to be considered when sorting. Just think about semver.
0 votes
answered May 24, 2021 by kirchsth (2,880 points)

I have written a compare function "$equalOrGreaterVersion()" which can work with both notations (If somebody needs it).
BR Helmut

!unquoted function $normalizedVersion($ver)
  ' add missing 0 if patch has only one digit
  ' 1.2021.7beta1 -> 1.2021.07beta1
  ' 1.2021.07 -> 1.2021.07
  ' 1.2021.7 -> 1.2021.07

  !local $expDigit2 =%substr($ver,8,1)
  !if ($expDigit2<"0" || $expDigit2>"9")
    !$ver = %substr($ver,0,7) + "0" + %substr($ver,7,10)
  !endif
  !return $ver
!endfunction

!unquoted function $equalOrGreaterVersion($currentVer, $requiredVer)
  ' add z that beta1,... are handled too (1.2021.7z -> 1.2021.07beta1z)
  !$currentVer = $normalizedVersion($currentVer) + "z"
  !$requiredVer = $normalizedVersion($requiredVer) + "z"
  !if ($currentVer >= $requiredVer)
    !return %true()
  !endif
  !return %false()
!endfunction

 

...