Skip to content

Instantly share code, notes, and snippets.

@juanpabloprado
Created April 27, 2019 20:56
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/dd8ba6fb5459629c4205f8d183482d88 to your computer and use it in GitHub Desktop.
Save juanpabloprado/dd8ba6fb5459629c4205f8d183482d88 to your computer and use it in GitHub Desktop.
Period is[state] methods on the Java Shell tool
jshell> Period p1 = Period.parse("P10D").minusDays(10);
p1 ==> P0D
jshell> "Is zero: " + p1.isZero();
$24 ==> "Is zero: true"
jshell> // Period equals negative value
jshell> Period p2 = Period.parse("P2019M");
p2 ==> P2019M
jshell> p2 = p2.minusMonths(2020); // 2019-2020 is -1 Months
p2 ==> P-1M
jshell> "Is negative: " + p2.isNegative();
$27 ==> "Is negative: true"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment