Skip to content

Instantly share code, notes, and snippets.

@Swivelgames
Last active November 13, 2017 17:46
Show Gist options
  • Save Swivelgames/c80e1e0dd5fcbef577331696df3f885c to your computer and use it in GitHub Desktop.
Save Swivelgames/c80e1e0dd5fcbef577331696df3f885c to your computer and use it in GitHub Desktop.

Revisions

  1. Swivelgames revised this gist Nov 13, 2017. 1 changed file with 6 additions and 13 deletions.
    19 changes: 6 additions & 13 deletions toTwelveHour.js
    Original file line number Diff line number Diff line change
    @@ -5,16 +5,9 @@ const toTwelveHour = time => {
    }

    /* expanded utility */
    const toTwelveHour = time => {
    let [hr,min] = time.split(':');
    let suffix = 'AM';

    if (hr == 0) {
    hr = 12;
    } else if (hr > 12) {
    hr -= 12;
    suffix = 'PM';
    }

    return `${hr}:${min}${suffix}`;
    }
    const toTwelveHour = (time) => {
    const [hour, min] = time.split(':');
    const suffix = hour > 12 ? 'PM' : 'AM';
    const hr = hour > 12 ? hour - 12 : parseInt(hour, 10);
    return `${hr === 0 ? 12 : hr}:${min}${suffix}`;
    };
  2. Swivelgames created this gist Nov 13, 2017.
    20 changes: 20 additions & 0 deletions toTwelveHour.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    /* golf */
    const toTwelveHour = time => {
    const [hr,min] = time.split(':');
    return `${hr>12?hr-12:hr==0?12:hr}:${min}${hr>12?'PM':'AM'}`;
    }

    /* expanded utility */
    const toTwelveHour = time => {
    let [hr,min] = time.split(':');
    let suffix = 'AM';

    if (hr == 0) {
    hr = 12;
    } else if (hr > 12) {
    hr -= 12;
    suffix = 'PM';
    }

    return `${hr}:${min}${suffix}`;
    }