<commit_before>;; Time Conversion
;; https://www.hackerrank.com/challenges/time-conversion

(ns hackerrank.time-conversion
	(:require [clojure.java.io :as io])
  (:use [clojure.string :only (split join)]))

(defn substr? [str substr]
  (boolean
    (re-find substr str)))

(defn pm? [str]
  (substr? str #"PM"))

(defn am? [str]
  (substr? str #"AM"))

(defn time-parts [time]
  (split time #":"))

(defn hour [time]
  (Integer/parseInt (first (time-parts time))))

(defn format-hour [time]
  (format "%02d" (hour time)))

(defn remove-am-pm [time]
  (subs time 0 (- (count time) 2)))

; http://clojure.org/reference/sequences
; https://clojuredocs.org/clojure.string/join
(defn pm-time [time]
  (let [hours (+ (hour time) 12)
        minutes-and-seconds (rest (time-parts time))]
    (clojure.string/join ":" (cons hours minutes-and-seconds))))

(defn hour-time [hours time]
   (clojure.string/join ":" (cons hours (rest (time-parts time)))))

(defn format-24h [time]
  (if (and (pm? time) (not (= (hour time) 12)))
    (remove-am-pm (pm-time time))
    (remove-am-pm time)))

; https://clojuredocs.org/clojure.core/cond
(defn pm-am-time [time]
  (let [hours (hour time)
        time24 (cond
          (and (pm? time) (not (= hours 12))) (hour-time (+ hours 12) time)
          (and (am? time) (= hours 12)) (hour-time 0 time)
          :else time)]
    (remove-am-pm time24)))

(defn time-conversion [line]
  (pm-am-time line))

(println (time-conversion "07:05:45PM"))<commit_msg>cleaned solution, todo<commit_after>;; Time Conversion
;; https://www.hackerrank.com/challenges/time-conversion

(ns hackerrank.time-conversion
	(:require [clojure.java.io :as io])
  (:use [clojure.string :only (split join)]))

(defn substr? [str substr]
  (boolean
    (re-find substr str)))

(defn pm? [str]
  (substr? str #"PM"))

(defn am? [str]
  (substr? str #"AM"))

(defn time-parts [time]
  (split time #":"))

(defn hour [time]
  (Integer/parseInt (first (time-parts time))))

(defn format-hour [time]
  (format "%02d" (hour time)))

(defn remove-am-pm [time]
  (subs time 0 (- (count time) 2)))

(defn pm-time [time]
  (let [hours (+ (hour time) 12)
        minutes-and-seconds (rest (time-parts time))]
    (join ":" (cons hours minutes-and-seconds))))

(defn hour-time [hours time]
   (join ":" (cons hours (rest (time-parts time)))))

(defn format-24h [time]
  (if (and (pm? time) (not (= (hour time) 12)))
    (remove-am-pm (pm-time time))
    (remove-am-pm time)))

(defn pm-am-time [time]
  (let [hours (hour time)
        time24 (cond
          (and (pm? time) (not (= hours 12))) (hour-time (+ hours 12) time)
          (and (am? time) (= hours 12)) (hour-time 0 time)
          :else time)]
    (remove-am-pm time24)))

(defn time-conversion [line]
  (pm-am-time line))

;; (println (time-conversion "07:05:45PM"))
;; for hackerrank
;; (println (time-conversion (read-line)))

;; 2016-08-03 13:50 run at hackerrank: 7/10 solution - 3 fails
;; o preper more test cases
{'fraction_non_alphanumeric': 0.19057239057239056, 'fraction_numerical': 0.02356902356902357, 'mean_word_length': 3.4211309523809526, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1667968', 'n_tokens_mistral': 1200, 'n_tokens_neox': 1115, 'n_words': 311}