-
-
Save lubien/70b0743a5ed13ab49b7e17dad02b139f to your computer and use it in GitHub Desktop.
Transform 12-Hour format to 24 hour. Run: https://repl.it/Gvco/2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { | |
pipe, match, drop, head, range, map, identity, add | |
, equals, last, join, take, ifElse, adjust, always | |
} = require('ramda') | |
const leftPad = require('left-pad') | |
const leftPadZero = size => x => leftPad(x, size, '0') | |
const clockToFullHours = | |
pipe( | |
match(/^(\d{1,2}):(\d{2})(\w{2})$/i) | |
, drop(1) | |
, ifElse(pipe(last, equals('pm'))) | |
(ifElse(pipe(head, equals('12'))) | |
(adjust(always(0), 0)) | |
(adjust(add(12), 0))) | |
(identity) | |
, take(2) | |
, map(leftPadZero(2)) | |
, join(':') | |
) | |
console.log( | |
pipe( | |
map(h => [`${h}:00am`, `${h}:00pm`]) | |
, map(map(clockToFullHours) | |
) | |
)(range(0, 13)) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment