0.20.1 • Published 3 years ago

@terra-dev/use-time-end v0.20.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
3 years ago

@terra-dev/use-time-end

Print the remain times

https://anchor-storybook.vercel.app/?path=/story/packages-use-time-end--component

API

index.ts

export function useTimeEnd(endTime: Date): string {}

export function TimeEnd({ endTime }: { endTime: Date }) {}

export const timeGap = (endTime: Date, now: Date) => {};

Spec

__tests__/use-time-end.test.ts

import { timeGap } from '@terra-dev/use-time-end';

describe('use-time-end', () => {
  test('should get time gap', () => {
    const now = new Date(Date.parse('Thu, Feb 18 2020 00:00:00 GMT'));

    expect(
      timeGap(new Date(Date.parse('Wed, Feb 17 2020 18:30:00 GMT')), now),
    ).toBe('00:00:00');

    expect(
      timeGap(new Date(Date.parse('Thu, Feb 18 2020 00:00:30 GMT')), now),
    ).toBe('00:00:30');

    expect(
      timeGap(new Date(Date.parse('Thu, Feb 18 2020 00:30:30 GMT')), now),
    ).toBe('00:30:30');

    expect(
      timeGap(new Date(Date.parse('Thu, Feb 18 2020 10:30:30 GMT')), now),
    ).toBe('10:30:30');

    expect(
      timeGap(new Date(Date.parse('Thu, Feb 25 2020 10:30:30 GMT')), now),
    ).toBe('7 Days');
  });
});

Stories

__stories__/use-time-end.stories.tsx

import { DAY, HOUR, MINUTE, useTimeEnd, TimeEnd } from '../';

export default {
  title: 'packages/use-time-end',
};

export const Hook = () => {
  const p = useTimeEnd(new Date(Date.now() - DAY));
  const m30 = useTimeEnd(new Date(Date.now() + MINUTE * 30));
  const h2 = useTimeEnd(new Date(Date.now() + HOUR * 2));
  const d2 = useTimeEnd(new Date(Date.now() + DAY * 2));
  const d9 = useTimeEnd(new Date(Date.now() + DAY * 9));

  return (
    <ul>
      <li>{p}</li>
      <li>{m30}</li>
      <li>{h2}</li>
      <li>{d2}</li>
      <li>{d9}</li>
    </ul>
  );
};

export const Component = () => {
  return (
    <ul>
      <li>
        <TimeEnd endTime={new Date(Date.now() - DAY)} />
      </li>
      <li>
        <TimeEnd endTime={new Date(Date.now() + MINUTE * 30)} />
      </li>
      <li>
        <TimeEnd endTime={new Date(Date.now() + HOUR * 2)} />
      </li>
      <li>
        <TimeEnd endTime={new Date(Date.now() + DAY * 2)} />
      </li>
      <li>
        <TimeEnd endTime={new Date(Date.now() + DAY * 9)} />
      </li>
    </ul>
  );
};
0.20.1

3 years ago

0.20.0

3 years ago

0.19.0

3 years ago

0.17.0

3 years ago

0.18.0

3 years ago

0.17.1

3 years ago

0.16.0

3 years ago

0.16.0-alpha.4

3 years ago

0.16.0-alpha.1

3 years ago

0.16.0-alpha.3

3 years ago

0.16.0-alpha.2

3 years ago

0.14.0

3 years ago

0.15.0

3 years ago

0.13.0

3 years ago

0.13.1

3 years ago

0.12.2

3 years ago

0.10.0

3 years ago

0.11.0

3 years ago

0.10.1

3 years ago

0.12.0

3 years ago

0.10.2

3 years ago

0.8.0

3 years ago

0.12.1

3 years ago

0.5.0

3 years ago

0.4.0

3 years ago

0.7.0

3 years ago

0.6.0

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago