fork(2) download
  1. def timez = ['2017-12-11T13:11:51.728Z', '2017-12-11T13:21:51.728Z', '2017-12-11T13:30:00.000Z']
  2. def dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
  3. def roundValue = 15
  4. //Change timezone if needed
  5. def tz = 'IST'
  6.  
  7. TimeZone.setDefault(TimeZone.getTimeZone(tz))
  8.  
  9. Calendar calendar = Calendar.getInstance()
  10.  
  11. def getNearestMinutes
  12. //Closure which gets called recursive
  13. getNearestMinutes = { cmin, nearMin = roundValue ->
  14. def tempResult = cmin % nearMin
  15. if ( tempResult < nearMin && (0 < (nearMin - cmin)) ) {
  16. return (nearMin - cmin)
  17. } else {
  18. return getNearestMinutes(cmin, nearMin+roundValue)
  19. }
  20. }
  21.  
  22.  
  23. //Loop thru times and round the time
  24. timez.each {
  25. calendar.time = Date.parse(dateFormat,it)
  26. def currentMinute = calendar.get(Calendar.MINUTE)
  27. def cof = currentMinute % roundValue
  28. if (cof) {
  29. currentMinute += getNearestMinutes(currentMinute)
  30. }
  31. calendar.set(Calendar.MINUTE, currentMinute )
  32. calendar.set(Calendar.SECOND, 0)
  33. calendar.set(Calendar.MILLISECOND, 0)
  34. println calendar.time.format(dateFormat)
  35. }
Success #stdin #stdout 1.02s 90560KB
stdin
Standard input is empty
stdout
2017-12-11T13:15:00.000Z
2017-12-11T13:30:00.000Z
2017-12-11T13:30:00.000Z