<commit_before>(ns cmr.common.date-time-parser
  "Contains helper to parse datetime string to clj-time"
  (:require [clj-time.format :as f]))

;; Define the regex for datetime parsing. It will match something like "1986-10-14T04:03:27.456-05:00Z"
(def datetime-regex #"^(\d\d\d\d-(\d)?\d-(\d)?\dT(\d)?\d:(\d)?\d:(\d)?\d(\.\d+)?)(([+-]\d\d:\d\d)|Z)?$")

(defn string->datetime
  "Convert datetime string to Joda DateTime"
  [value]
  (if-let [matches (re-find datetime-regex value)]
    (let [match (get matches 1)
          conformed-value (if (re-find #"\." match) match (str match ".000"))]
      (f/parse (f/formatters :date-hour-minute-second-fraction) conformed-value))
    (throw (Exception. (format "Invalid DateTime string: %s" value)))))<commit_msg>Deprecated time parser namespace.<commit_after>(ns cmr.common.date-time-parser
  "Contains helper to parse datetime string to clj-time"
  (:require [clj-time.format :as f]))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; DEPRECATED
;; Each project should do it's own time parsing using clj-time.format

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Define the regex for datetime parsing. It will match something like "1986-10-14T04:03:27.456-05:00Z"
(def datetime-regex #"^(\d\d\d\d-(\d)?\d-(\d)?\dT(\d)?\d:(\d)?\d:(\d)?\d(\.\d+)?)(([+-]\d\d:\d\d)|Z)?$")

(def formatter
  "The formatter used to parse date time strings"
  (f/formatters :date-hour-minute-second-fraction))

(defn string->datetime
  "Convert datetime string to Joda DateTime"
  [value]
  (if-let [matches (re-find datetime-regex value)]
    (let [match (get matches 1)
          conformed-value (if (re-find #"\." match) match (str match ".000"))]
      (f/parse formatter conformed-value))
    (throw (Exception. (format "Invalid DateTime string: %s" value)))))
{'fraction_non_alphanumeric': 0.23764575235980012, 'fraction_numerical': 0.0277623542476402, 'mean_word_length': 4.033519553072626, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3813406', 'n_tokens_mistral': 696, 'n_tokens_neox': 630, 'n_words': 160}