time.spec.ts 961 B

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