We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b527568 commit fc40b3aCopy full SHA for fc40b3a
src/schema/ext/time/local_converter.cr
@@ -0,0 +1,25 @@
1
+require "../../annotations"
2
+
3
+@[Schema::Definition::Scalar]
4
+struct Time
5
+ module LocalConverter
6
+ FORMAT = "%Y-%m-%dT%H:%M"
7
8
+ # Put *value* as a time timestamp into the *builder* at *key*.
9
+ def self.to_http_param(value : Time, builder : HTTP::Params::Builder, key : String)
10
+ builder.add(key, to_http_param(value))
11
+ end
12
13
+ # Return *value* as a time timestamp string.
14
+ def self.to_http_param(value : Time)
15
+ value.to_s(format)
16
17
18
+ # Parse `Time` from an HTTP param as time timestamp.
19
+ def self.from_http_param(value : String) : Time
20
+ Time.parse(time, FORMAT)
21
+ rescue ArgumentError
22
+ raise TypeCastError.new
23
24
25
+end
0 commit comments