| 1857 | |
| 1858 | @staticmethod |
| 1859 | def parse_timeframe(timeframe): |
| 1860 | amount = int(timeframe[0:-1]) |
| 1861 | unit = timeframe[-1] |
| 1862 | if 'y' == unit: |
| 1863 | scale = 31536000 # 60 * 60 * 24 * 365 |
| 1864 | elif 'M' == unit: |
| 1865 | scale = 2592000 # 60 * 60 * 24 * 30 |
| 1866 | elif 'w' == unit: |
| 1867 | scale = 604800 # 60 * 60 * 24 * 7 |
| 1868 | elif 'd' == unit: |
| 1869 | scale = 86400 # 60 * 60 * 24 |
| 1870 | elif 'h' == unit: |
| 1871 | scale = 3600 # 60 * 60 |
| 1872 | elif 'm' == unit: |
| 1873 | scale = 60 |
| 1874 | elif 's' == unit: |
| 1875 | scale = 1 |
| 1876 | else: |
| 1877 | raise NotSupported('timeframe unit {} is not supported'.format(unit)) |
| 1878 | return amount * scale |
| 1879 | |
| 1880 | @staticmethod |
| 1881 | def round_timeframe(timeframe, timestamp, direction=ROUND_DOWN): |