(Object timeframe, Object timestamp, Object direction)
| 62 | |
| 63 | |
| 64 | public static Object roundTimeframe(Object timeframe, Object timestamp, Object direction) { |
| 65 | |
| 66 | int dir; |
| 67 | if (direction == null) { |
| 68 | dir = ROUND_DOWN; |
| 69 | } else if (direction instanceof Number) { |
| 70 | dir = ((Number) direction).intValue(); |
| 71 | } else { |
| 72 | throw new IllegalArgumentException("direction must be numeric or null"); |
| 73 | } |
| 74 | |
| 75 | long ms = parseTimeframe(timeframe) * 1000L; |
| 76 | |
| 77 | if (!(timestamp instanceof Number)) { |
| 78 | throw new IllegalArgumentException("timestamp must be numeric"); |
| 79 | } |
| 80 | long ts = ((Number) timestamp).longValue(); |
| 81 | |
| 82 | long offset = ts % ms; |
| 83 | |
| 84 | long result = ts - offset + ((dir == ROUND_UP) ? ms : 0L); |
| 85 | return result; |
| 86 | } |
| 87 | |
| 88 | public static Object roundTimeframe(Object timeframe, Object timestamp) { |
| 89 | return roundTimeframe(timeframe, timestamp, null); |
no test coverage detected