207 lines
14 KiB
HTML
207 lines
14 KiB
HTML
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<link rel="stylesheet" href="../../../coverage.css"/> <title> dog_and_duck/quack/picky/time.clj </title>
|
|
</head>
|
|
<body>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
001 (ns dog-and-duck.quack.picky.time
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
002 "Time, gentleman, please! Recognising and validating date time values."
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
003 (:require [dog-and-duck.quack.picky.utils :refer [cond-make-fault-object
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
004 make-fault-object
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
005 truthy?]]
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
006 [scot.weft.i18n.core :refer [get-message]]
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
007 [taoensso.timbre :refer [warn error]])
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
008 (:import [java.time LocalDateTime]
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
009 [java.time.format DateTimeFormatter DateTimeParseException]
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
010 [javax.xml.datatype DatatypeFactory]))
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
011
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
012 ;;; Copyright (C) Simon Brooke, 2023
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
013
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
014 ;;; This program is free software; you can redistribute it and/or
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
015 ;;; modify it under the terms of the GNU General Public License
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
016 ;;; as published by the Free Software Foundation; either version 2
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
017 ;;; of the License, or (at your option) any later version.
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
018
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
019 ;;; This program is distributed in the hope that it will be useful,
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
020 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
021 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
022 ;;; GNU General Public License for more details.
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
023
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
024 ;;; You should have received a copy of the GNU General Public License
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
025 ;;; along with this program; if not, write to the Free Software
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
026 ;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
027
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
028 (defn xsd-date-time?
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
029 "Return `true` if `value` matches the pattern for an
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
030 [xsd:dateTime](https://www.w3.org/TR/xmlschema11-2/#dateTime), else `false`"
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
031 [^String value]
|
|
</span><br/>
|
|
<span class="partial" title="1 out of 3 forms covered">
|
|
032 (try
|
|
</span><br/>
|
|
<span class="partial" title="5 out of 6 forms covered">
|
|
033 (if (LocalDateTime/from (.parse DateTimeFormatter/ISO_DATE_TIME value)) true false)
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
034 (catch DateTimeParseException _
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 20 forms covered">
|
|
035 (warn (get-message :bad-date-time) ":" value)
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
036 false)
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
037 (catch Exception e
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 18 forms covered">
|
|
038 (error "Exception thrown while parsing date" value e)
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
039 false)))
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
040
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
041 (defn xsd-duration?
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
042 "Return `true` if `value` matches the pattern for an
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
043 [xsd:duration](https://www.w3.org/TR/xmlschema11-2/#duration), else `false`"
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
044 [value]
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 2 forms covered">
|
|
045 (truthy?
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 10 forms covered">
|
|
046 (and (string? value)
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 3 forms covered">
|
|
047 (try (.newDuration (DatatypeFactory/newInstance) value)
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
048 (catch IllegalArgumentException _
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 20 forms covered">
|
|
049 (warn (get-message :bad-duration) ":" value)
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
050 false)
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
051 (catch Exception e
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 18 forms covered">
|
|
052 (error "Exception thrown while parsing duration" value e)
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
053 false)))))
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
054
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
055 (defn date-time-property-or-fault
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
056 "If the value of this `property` of object `x` is a valid xsd:dateTime
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
057 value, return a fault object with this `token` and `severity`.
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
058
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
059 If `required?` is false and there is no such property, no fault will be
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
060 returned."
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
061 [x property severity token required?]
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 4 forms covered">
|
|
062 (let [value (property x)]
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 11 forms covered">
|
|
063 (if (and required? (not (x property)))
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 4 forms covered">
|
|
064 (make-fault-object severity token)
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 2 forms covered">
|
|
065 (cond-make-fault-object
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 10 forms covered">
|
|
066 (and value (xsd-date-time? value)) severity token))))
|
|
</span><br/>
|
|
</body>
|
|
</html>
|