fork download
  1. import static java.time.LocalDateTime.parse
  2. import static java.time.Duration.between
  3.  
  4. def t1 = '2007-12-03T10:15:30'
  5. def t2 = '2007-12-11T16:01:10'
  6. def t3 = '2007-12-23T11:11:10'
  7.  
  8.  
  9. def getDuration = { date1, date2 ->
  10. def result
  11. switch(between(parse(date1), parse(date2)).toDays() as Integer) {
  12. case 8..15:
  13. result = 'Fortnight'
  14. break
  15. case 16..31:
  16. result = 'Month'
  17. break
  18. default:
  19. result = 'Not matching'
  20. break
  21. }
  22. result
  23. }
  24.  
  25. println getDuration(t1, t2)
  26. println getDuration(t2, t3)
  27. println getDuration(t1, t3)
Success #stdin #stdout 2.14s 140120KB
stdin
Standard input is empty
stdout
Fortnight
Fortnight
Month