-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Date Time Range type #2
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
* Add Date Time Range type | ||
|
||
v1.2.0 | ||
|
||
* Return null for null dates rather than the unix epoch. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
{ | ||
types: | ||
postgres: 'TSTZRANGE' | ||
mysql: 'VARCHAR(255)' | ||
websql: 'VARCHAR(255)' | ||
odata: | ||
name: 'Self.DateTimeRange' | ||
complexType: ''' | ||
<ComplexType Name="DateTimeRange"> | ||
<Property Name="Start" Nullable="false" Type="Edm.DateTime"/>\ | ||
<Property Name="End" Nullable="true" Type="Edm.DateTime"/>\ | ||
<Property Name="Bounds" Nullable="false" Type="Edm.String"/>\ | ||
</ComplexType>''' | ||
|
||
nativeProperties: | ||
has: | ||
Start: (from) -> ['RangeStart', from] | ||
End: (from) -> ['RangeEnd', from] | ||
Bounds: (from) -> ['RangeBounds', from] | ||
|
||
fetchProcessing: (data, callback) -> | ||
if data? | ||
[start, end] = data.slice(1, -1).split(',') | ||
res = | ||
Start: start | ||
End: end.trim() | ||
Bounds: data[0] + data[data.length - 1] | ||
callback(null, res) | ||
else | ||
callback(null, data) | ||
|
||
validate: (value, required, callback) -> | ||
if !_.isObject(value) | ||
callback('is not a date time range object: ' + value) | ||
else | ||
# Check with hasOwnProperty since null values are allowed | ||
if value.hasOwnProperty('Start') and value.hasOwnProperty('End') and value.hasOwnProperty('Bounds') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This forces the properties into a specific case where otherwise we would allow any case (with the |
||
processedValue = '' | ||
start = undefined | ||
end = undefined | ||
bounds = undefined | ||
for own component, componentValue of value | ||
switch component.toLowerCase() | ||
when 'start' | ||
start = componentValue | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we do some validation of this? |
||
when 'end' | ||
end = componentValue | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we do some validation of this? |
||
when 'bounds' | ||
bounds = componentValue | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to validate bounds here, because we access it using index properties below but if it's actually a number for instance then that will fail (and in general only certain values make sense) |
||
else | ||
callback('has an unknown component: ' + component) | ||
processedValue = bounds[0] + start + ', ' + end + bounds[1] | ||
callback(null, processedValue) | ||
else | ||
callback('is missing components: ' + value) | ||
|
||
dataTypeGen: (engine, dataType, necessity, index = '', defaultValue) -> | ||
if defaultValue | ||
@validate defaultValue, true, (err, value) -> | ||
if !err | ||
defaultValue = value | ||
else | ||
defaultValue = null | ||
dbType = @types?[engine] | ||
TypeUtils.dataTypeGen dbType, engine, dataType, necessity, index, defaultValue | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,14 @@ | |
callback(err) | ||
return | ||
callback(null, value.toLocaleTimeString()) | ||
|
||
dataTypeGen: (engine, dataType, necessity, index = '', defaultValue) -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From what I can see all of the default value checking in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could have a default value equal to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, if I move everything to |
||
if defaultValue | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would remove the option of having a default value of |
||
@validate defaultValue, true, (err, value) -> | ||
if !err | ||
defaultValue = value | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This only works because our "async" callback is actually synchronous, if you try to do a default value in the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What exactly should be turned into an async function? The |
||
else | ||
defaultValue = null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the |
||
dbType = @types?[engine] | ||
TypeUtils.dataTypeGen dbType, engine, dataType, necessity, index, defaultValue | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
helpers = require './helpers' | ||
|
||
helpers.describe 'Date Time Range', (test) -> | ||
start = new Date() | ||
end = 'null' | ||
bounds = '[)' | ||
describe 'fetchProcessing', -> | ||
test.fetch(bounds[0] + start + ', ' + end + bounds[1], { | ||
Start: start.toString() | ||
End: end | ||
Bounds: bounds | ||
}) | ||
|
||
describe 'validate', -> | ||
start = new Date() | ||
end = null | ||
bounds = '[)' | ||
test.validate({ | ||
Start: start | ||
End: end | ||
Bounds: bounds | ||
}, true, bounds[0] + start + ', ' + end + bounds[1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is "Bounds"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Defines the lower and upper bound. Can be:
[]
,[)
,()
,(]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this should be in an English form, eg
Date Time Range is inclusive of beginning
,Date Time Range includes beginning
, something like thatThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be an additional Fact Type? I am currently looking at the SBVR Date Time Vocabulary but I can't find anything similar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it should be an additional fact type