Skip to content

Instantly share code, notes, and snippets.

@juanpabloprado
Created April 27, 2019 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanpabloprado/8d35aeb59d9b2a32cf1c1e22002d1d1c to your computer and use it in GitHub Desktop.
Save juanpabloprado/8d35aeb59d9b2a32cf1c1e22002d1d1c to your computer and use it in GitHub Desktop.
Period normalized method on the Java Shell tool
jshell> Period p1 = Period.parse("P0Y13M");
p1 ==> P13M
jshell> "Original: " + p1 + " Normalized: " + p1.normalized();
$36 ==> "Original: P13M Normalized: P1Y1M"
jshell> Period p2 = Period.parse("P2Y-1M");
p2 ==> P2Y-1M
jshell> "Original: " + p2 + " Normalized: " + p2.normalized();
$38 ==> "Original: P2Y-1M Normalized: P1Y11M"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment