time.spec.ts 977 B

123456789101112131415161718192021222324252627282930
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. import 'jest';
  4. import { Time } from '@jupyterlab/coreutils';
  5. describe('@jupyterlab/coreutils', () => {
  6. describe('Time', () => {
  7. describe('.formatHuman()', () => {
  8. it('should convert a time to a human readable string', () => {
  9. const date = new Date();
  10. date.setSeconds(date.getSeconds() - 10);
  11. const value = Time.formatHuman(date);
  12. expect(value).toBe('seconds ago');
  13. date.setMinutes(date.getMinutes() - 3);
  14. expect(Time.formatHuman(date.toISOString())).toBe('3 minutes ago');
  15. });
  16. });
  17. describe('.format()', () => {
  18. it('should convert a timestring to a date format', () => {
  19. expect(Time.format(new Date()).length).toBe(16);
  20. const date = new Date();
  21. const value = Time.format(date.toISOString(), 'MM-DD');
  22. expect(value.length).toBe(5);
  23. });
  24. });
  25. });
  26. });