61 lines
1.0 KiB
Go
61 lines
1.0 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"bufio"
|
||
|
"fmt"
|
||
|
"io"
|
||
|
"os"
|
||
|
"strings"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
/*
|
||
|
* Complete the 'timeConversion' function below.
|
||
|
*
|
||
|
* The function is expected to return a STRING.
|
||
|
* The function accepts STRING s as parameter.
|
||
|
*/
|
||
|
|
||
|
func timeConversion(s string) string {
|
||
|
dt, err := time.Parse("03:04:05PM", s)
|
||
|
if err != nil {
|
||
|
println(err.Error())
|
||
|
return ""
|
||
|
}
|
||
|
return dt.Format("15:04:05")
|
||
|
}
|
||
|
|
||
|
func main() {
|
||
|
reader := bufio.NewReaderSize(os.Stdin, 16 * 1024 * 1024)
|
||
|
|
||
|
stdout, err := os.Create(os.Getenv("OUTPUT_PATH"))
|
||
|
checkError(err)
|
||
|
|
||
|
defer stdout.Close()
|
||
|
|
||
|
writer := bufio.NewWriterSize(stdout, 16 * 1024 * 1024)
|
||
|
|
||
|
s := readLine(reader)
|
||
|
|
||
|
result := timeConversion(s)
|
||
|
|
||
|
fmt.Fprintf(writer, "%s\n", result)
|
||
|
|
||
|
writer.Flush()
|
||
|
}
|
||
|
|
||
|
func readLine(reader *bufio.Reader) string {
|
||
|
str, _, err := reader.ReadLine()
|
||
|
if err == io.EOF {
|
||
|
return ""
|
||
|
}
|
||
|
|
||
|
return strings.TrimRight(string(str), "\r\n")
|
||
|
}
|
||
|
|
||
|
func checkError(err error) {
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
}
|