Skip to content

Commit

Permalink
added test for fixing +0000 timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
saumier committed Sep 4, 2024
1 parent 65f6a00 commit 9390839
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
10 changes: 7 additions & 3 deletions sparql/fix_date_timezone.sparql
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ WHERE {
FILTER (datatype(?old_date) = schema:Date || datatype(?old_date) = schema:DateTime)
BIND(datatype(?old_date) as ?old_date_type)
BIND(strbefore(str(?old_date),"T") as ?date_str)
BIND(strbefore(strafter(str(?old_date), "T"), "-") AS ?time_str)
BIND(strafter(strafter(str(?old_date), "T"), "-") AS ?zone_str)
BIND(strafter(str(?old_date), "T") as ?old_time_str)
BIND(IF(CONTAINS(str(?old_time_str),"+"),"+", "-") AS ?zone_operator)

BIND(strbefore(str(?old_time_str), ?zone_operator) AS ?time_str)
BIND(strafter(str(?old_time_str), ?zone_operator) AS ?zone_str)

FILTER (?date_str != "" && ?time_str != "" && ?zone_str != "")
FILTER (SUBSTR(str(?zone_str), 3, 1) != ':')
BIND(CONCAT(SUBSTR(str(?zone_str), 1, 2), ":", SUBSTR(str(?zone_str), 3, 2)) as ?zone_fix)
BIND(strdt(concat(?date_str, "T", ?time_str, "-", ?zone_fix), ?old_date_type) as ?fixed_date)
BIND(strdt(concat(?date_str, "T", ?time_str, ?zone_operator, ?zone_fix), ?old_date_type) as ?fixed_date)
}
5 changes: 5 additions & 0 deletions tests/fix_date_timezone_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ def test_fix_timezone
expected = RDF::Literal.new('2024-02-03T20:00:00-07:00', datatype: RDF::URI("http://schema.org/Date"))
actual = graph.query([RDF::URI('http://example.com/event4'), RDF::Vocab::SCHEMA.endDate, nil]).first.object
assert_equal expected, actual, "event4 failed"

# Test event5
expected = RDF::Literal.new('2024-02-03T20:00:00+00:00', datatype: RDF::URI("http://schema.org/Date"))
actual = graph.query([RDF::URI('http://example.com/event5'), RDF::Vocab::SCHEMA.startDate, nil]).first.object
assert_equal expected, actual, "event5 failed"
end

def test_skip_dates_without_timezone
Expand Down
9 changes: 9 additions & 0 deletions tests/fixtures/test_date_timezone_fix.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@
"@id": "http://example.com/event4",
"name": "endDate with badly formated timezone ",
"endDate": "2024-02-03T20:00:00-0700"
},
{
"@type": "Event",
"@id": "http://example.com/event5",
"name": "startDate^^schema:Date with badly formated +0000 timezone ",
"startDate": {
"@value": "2024-02-03T20:00:00+0000",
"@type": "Date"
}
}
]
}

0 comments on commit 9390839

Please sign in to comment.