Skip to content

Instantly share code, notes, and snippets.

@CosmoAbdon
Last active June 19, 2021 11:16
Show Gist options
  • Save CosmoAbdon/520aac6dabbf078f739d8da57d47bad0 to your computer and use it in GitHub Desktop.
Save CosmoAbdon/520aac6dabbf078f739d8da57d47bad0 to your computer and use it in GitHub Desktop.

Revisions

  1. CosmoAbdon revised this gist Jun 19, 2021. 1 changed file with 1 addition and 6 deletions.
    7 changes: 1 addition & 6 deletions dateUtils.ts
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,6 @@
    const { started_at } = await fetchStreamerByUsername(channelName);

    const started_at_date = new Date(started_at);
    const date_now = new Date();

    const timeDiff = (dateNow: number, dateEarlier: number) => {
    export default const timeDiff = (dateNow: number, dateEarlier: number) => {
    let diffInMS = Math.abs(+dateFuture - (+dateNow)) / 1000;

    const days = Math.floor(diffInMS / 86400);
    @@ -23,5 +20,3 @@ const timeDiff = (dateNow: number, dateEarlier: number) => {
    return {days, minutes, seconds};
    }


    console.log(timeDiff(+date_now, +started_at_date))
  2. CosmoAbdon revised this gist Jun 19, 2021. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions dateUtils.ts
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    const date_earlier = new Date('18 June 2021 06:15:10 UTC-3');
    const { started_at } = await fetchStreamerByUsername(channelName);

    const date_now = new Date('19 June 2021 07:16:20 UTC-3');
    const started_at_date = new Date(started_at);
    const date_now = new Date();

    const timeDiff = (dateNow: number, dateEarlier: number) => {
    let diffInMS = Math.abs(+dateFuture - (+dateNow)) / 1000;
    @@ -23,4 +24,4 @@ const timeDiff = (dateNow: number, dateEarlier: number) => {
    }


    console.log(timeDiff(+date_now, +date_earlier))
    console.log(timeDiff(+date_now, +started_at_date))
  3. CosmoAbdon revised this gist Jun 19, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion dateUtils.ts
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@ const date_earlier = new Date('18 June 2021 06:15:10 UTC-3');

    const date_now = new Date('19 June 2021 07:16:20 UTC-3');

    const timeDiff = (dateFuture: number, dateNow: number) => {
    const timeDiff = (dateNow: number, dateEarlier: number) => {
    let diffInMS = Math.abs(+dateFuture - (+dateNow)) / 1000;

    const days = Math.floor(diffInMS / 86400);
  4. CosmoAbdon created this gist Jun 19, 2021.
    26 changes: 26 additions & 0 deletions dateUtils.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    const date_earlier = new Date('18 June 2021 06:15:10 UTC-3');

    const date_now = new Date('19 June 2021 07:16:20 UTC-3');

    const timeDiff = (dateFuture: number, dateNow: number) => {
    let diffInMS = Math.abs(+dateFuture - (+dateNow)) / 1000;

    const days = Math.floor(diffInMS / 86400);
    diffInMS -= days * 86400;

    const hours = Math.floor(diffInMS / 3600) % 24;
    diffInMS -= hours * 3600;

    const minutes = Math.floor(diffInMS / 60) % 60;
    diffInMS -= minutes * 60;

    const seconds = Math.floor(diffInMS) % 60;
    diffInMS -= seconds * 60;

    console.log(days, minutes, seconds)

    return {days, minutes, seconds};
    }


    console.log(timeDiff(+date_now, +date_earlier))