-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
172 additions
and
66 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,48 @@ | ||
(ns lipas.schema.sports-sites.activities | ||
(:require [lipas.data.activities :as activities-data])) | ||
(:require [clojure.string :as str] | ||
[lipas.data.activities :as activities-data] | ||
[lipas.data.types :as types] | ||
[malli.util :as mu])) | ||
|
||
(def activity (into [:enum] (keys activities-data/activities))) | ||
(def activities | ||
[:set {:title "Activities" | ||
:description "Enriched activity related content for Luontoon.fi service. Certain sports facility types may contain data about activities that can be practiced at the facility."} | ||
activity]) | ||
|
||
(def fishing activities-data/fishing-schema) | ||
(def outdoor-recreation-areas activities-data/outdoor-recreation-areas-schema) | ||
(def outdoor-recreation-routes activities-data/outdoor-recreation-routes-schema) | ||
(def outdoor-recreation-facilities activities-data/outdoor-recreation-facilities-schema) | ||
(def cycling activities-data/cycling-schema) | ||
(def paddling activities-data/paddling-schema) | ||
(def birdwatching activities-data/birdwatching-schema) | ||
(defn -append-description | ||
[schema {:keys [type-codes label]}] | ||
(let [s (str (:en label) | ||
" is an activity associated with facility types " | ||
(str/join ", " (for [[k m] (select-keys types/all type-codes)] | ||
(str k " " (get-in m [:name :en])))) | ||
". Enriched activity information is collected for Luontoon.fi service.")] | ||
(mu/update-properties schema assoc :description s))) | ||
|
||
(def fishing (-append-description | ||
activities-data/fishing-schema | ||
activities-data/fishing)) | ||
|
||
(def outdoor-recreation-areas (-append-description | ||
activities-data/outdoor-recreation-areas-schema | ||
activities-data/outdoor-recreation-areas)) | ||
|
||
(def outdoor-recreation-routes (-append-description | ||
activities-data/outdoor-recreation-routes-schema | ||
activities-data/outdoor-recreation-routes)) | ||
|
||
(def outdoor-recreation-facilities (-append-description | ||
activities-data/outdoor-recreation-facilities-schema | ||
activities-data/outdoor-recreation-facilities)) | ||
|
||
(def cycling (-append-description | ||
activities-data/cycling-schema | ||
activities-data/cycling)) | ||
|
||
(def paddling (-append-description | ||
activities-data/paddling-schema | ||
activities-data/paddling)) | ||
|
||
(def birdwatching (-append-description | ||
activities-data/birdwatching-schema | ||
activities-data/birdwatching)) |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
(ns lipas.timestamps-test | ||
(:require [clojure.test :refer [deftest testing is]] | ||
[lipas.schema.common :as common-schema])) | ||
|
||
(def iso8601-pattern common-schema/-iso8601-pattern) | ||
|
||
(deftest iso8601-timestamp-test | ||
(testing "Valid UTC timestamps" | ||
(is (re-matches iso8601-pattern "2024-12-27T13:25:00Z")) | ||
(is (re-matches iso8601-pattern "2024-12-27T13:25:00.123Z")) | ||
(is (re-matches iso8601-pattern "2024-01-01T00:00:00Z")) | ||
(is (re-matches iso8601-pattern "2024-12-31T23:59:59Z")) | ||
(is (re-matches iso8601-pattern "2024-02-29T00:00:00Z")) ; Valid leap year | ||
(is (re-matches iso8601-pattern "2000-02-29T00:00:00Z"))) ; Valid century leap year | ||
|
||
(testing "Invalid timestamps" | ||
; Non-UTC timestamps (should all fail) | ||
(is (nil? (re-matches iso8601-pattern "2024-12-27T13:25:00+02:00"))) | ||
(is (nil? (re-matches iso8601-pattern "2024-12-27T13:25:00-02:00"))) | ||
(is (nil? (re-matches iso8601-pattern "2024-12-27T13:25:00.123+02:00"))) | ||
|
||
; Invalid dates | ||
(is (nil? (re-matches iso8601-pattern "2024-13-01T00:00:00Z"))) ; Invalid month | ||
(is (nil? (re-matches iso8601-pattern "2024-00-01T00:00:00Z"))) ; Invalid month | ||
(is (nil? (re-matches iso8601-pattern "2024-12-32T00:00:00Z"))) ; Invalid day | ||
(is (nil? (re-matches iso8601-pattern "2024-12-00T00:00:00Z"))) ; Invalid day | ||
(is (nil? (re-matches iso8601-pattern "2023-02-29T00:00:00Z"))) ; Invalid leap year date | ||
|
||
; Invalid times | ||
(is (nil? (re-matches iso8601-pattern "2024-12-27T24:00:00Z"))) ; Invalid hour | ||
(is (nil? (re-matches iso8601-pattern "2024-12-27T12:60:00Z"))) ; Invalid minute | ||
(is (nil? (re-matches iso8601-pattern "2024-12-27T12:00:60Z"))) ; Invalid second | ||
|
||
; Invalid formats | ||
(is (nil? (re-matches iso8601-pattern "2024-12-27 12:00:00Z"))) ; Space instead of T | ||
(is (nil? (re-matches iso8601-pattern "2024-12-27T12:00:00"))) ; Missing Z | ||
(is (nil? (re-matches iso8601-pattern "24-12-27T12:00:00Z"))) ; Two-digit year | ||
(is (nil? (re-matches iso8601-pattern "2024/12/27T12:00:00Z")))) ; Wrong separators | ||
|
||
(testing "Edge cases for months with different lengths" | ||
(is (re-matches iso8601-pattern "2024-01-31T00:00:00Z")) ; January 31 valid | ||
(is (nil? (re-matches iso8601-pattern "2024-04-31T00:00:00Z"))) ; April 31 invalid | ||
(is (re-matches iso8601-pattern "2024-04-30T00:00:00Z")) ; April 30 valid | ||
(is (nil? (re-matches iso8601-pattern "2024-02-30T00:00:00Z"))) ; February 30 invalid | ||
(is (re-matches iso8601-pattern "2024-06-30T00:00:00Z")) ; June 30 valid | ||
(is (nil? (re-matches iso8601-pattern "2024-06-31T00:00:00Z")))) ; June 31 invalid | ||
|
||
(testing "Fractional seconds variations" | ||
(is (re-matches iso8601-pattern "2024-12-27T13:25:00.1Z")) | ||
(is (re-matches iso8601-pattern "2024-12-27T13:25:00.12Z")) | ||
(is (re-matches iso8601-pattern "2024-12-27T13:25:00.123Z")) | ||
(is (re-matches iso8601-pattern "2024-12-27T13:25:00.1234567890Z")))) | ||
|
||
|
||
(comment | ||
(clojure.test/run-tests *ns*) | ||
) |