| 12 | public static int ROUND_DOWN = Exchange.ROUND_DOWN; |
| 13 | |
| 14 | public static int parseTimeframe(Object timeframe2) { |
| 15 | if (!(timeframe2 instanceof String)) { |
| 16 | throw new IllegalArgumentException("Invalid timeframe: " + timeframe2); |
| 17 | } |
| 18 | |
| 19 | String timeframe = ((String) timeframe2).trim(); |
| 20 | if (timeframe.length() < 2) { |
| 21 | throw new IllegalArgumentException("Invalid timeframe: " + timeframe); |
| 22 | } |
| 23 | |
| 24 | int amount; |
| 25 | try { |
| 26 | amount = Integer.parseInt(timeframe.substring(0, timeframe.length() - 1)); |
| 27 | } catch (NumberFormatException e) { |
| 28 | throw new IllegalArgumentException("Invalid timeframe: " + timeframe); |
| 29 | } |
| 30 | |
| 31 | String unit = timeframe.substring(timeframe.length() - 1); |
| 32 | int scale; |
| 33 | |
| 34 | switch (unit) { |
| 35 | case "y": |
| 36 | scale = 60 * 60 * 24 * 365; |
| 37 | break; |
| 38 | case "M": |
| 39 | scale = 60 * 60 * 24 * 30; |
| 40 | break; |
| 41 | case "w": |
| 42 | scale = 60 * 60 * 24 * 7; |
| 43 | break; |
| 44 | case "d": |
| 45 | scale = 60 * 60 * 24; |
| 46 | break; |
| 47 | case "h": |
| 48 | scale = 60 * 60; |
| 49 | break; |
| 50 | case "m": |
| 51 | scale = 60; |
| 52 | break; |
| 53 | case "s": |
| 54 | scale = 1; |
| 55 | break; |
| 56 | default: |
| 57 | throw new IllegalArgumentException("Invalid timeframe: " + timeframe); |
| 58 | } |
| 59 | |
| 60 | return amount * scale; |
| 61 | } |
| 62 | |
| 63 | |
| 64 | public static Object roundTimeframe(Object timeframe, Object timestamp, Object direction) { |