Skip to content

Typescript

spencer kelly edited this page Oct 31, 2020 · 2 revisions

Spacetime publishes typescript types, which should 'just work' with most setups.

make sure to add this to your tsconfig.json:

{
  "compilerOptions": {
    "esModuleInterop": true
  }
}
import spacetime from 'spacetime';
import { Spacetime } from 'spacetime/types/types';

export function demo() {
	let now = new Date();
	let nowS = spacetime(now);
	let nextS = spacetime(now).add(1, 'day');
	console.log(nowS.isSame(nextS, 'week'));

	console.log(nowS.format('iso-utc'));
	const spaceNow = spacetime.now();
	console.log(spaceNow.startOf('century'));

	let millies: number = spaceNow.millisecond();
	let updated: Spacetime = spaceNow.millisecond(123123);
}
Clone this wiki locally