Created
March 24, 2018 05:10
-
-
Save huwr/7c54efb5c3c56eeace92f3543980f32a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// | |
// main.swift | |
// timestamp | |
// | |
// Created by Huw Rowlands on 24/3/18. | |
// Copyright © 2018 Huw Rowlands. All rights reserved. | |
// | |
import Foundation | |
let BINARY_NAME = CommandLine.arguments[0] | |
let USAGE = "usage: \(BINARY_NAME) [TIMESTAMP]..." | |
let dateFormatter = ISO8601DateFormatter() | |
func convert(fromTimestamps timestamps: [Double]) -> [String] { | |
return timestamps | |
.map { Date(timeIntervalSince1970: $0) } | |
.map { dateFormatter.string(from: $0) } | |
} | |
func santise(commandLineArguments arguments: [String]) -> [Double] { | |
let arguments = CommandLine.arguments.dropFirst() | |
return arguments.flatMap { Double($0) } | |
} | |
let cleanArgs = santise(commandLineArguments: CommandLine.arguments) | |
if cleanArgs.count < 2 { | |
print(USAGE) | |
exit(2) | |
} else { | |
let iso8601s = convert(fromTimestamps: cleanArgs) | |
iso8601s.forEach { | |
print($0) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment