Files
remark42/frontend/app/utils/ttl-to-time.ts
T
Pavel MineevandUmputun 5825a55b69 Update frontend
* change root dit and change way to import modules
* update deps to latest versions
* use latest tools for building bundles
* rewrite webpack config
* use nomodule technique for loading modern bundle
* inject polyfills by babel usebuiltins
* update eslint rules
* rename all style files to CSS
* use postcss preset env for building styles
* proper typescript typing
* put all html files to templates folder
* etc
2021-01-12 13:39:26 -06:00

26 lines
619 B
TypeScript

import { BlockTTL } from 'common/types';
export function ttlToDate(ttl: BlockTTL): Date {
const date = new Date();
switch (ttl) {
case 'permanently':
date.setFullYear(date.getFullYear() + 100);
return date;
case '43200m':
date.setMonth(date.getMonth() + 1);
return date;
case '10080m':
date.setDate(date.getDate() + 7);
return date;
case '1440m':
date.setDate(date.getDate() + 1);
return date;
default:
throw new Error('unknown block ttl');
}
}
export function ttlToTime(ttl: BlockTTL): string {
return ttlToDate(ttl).toISOString();
}