-
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 1 commit
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 |
---|---|---|
|
@@ -86,4 +86,19 @@ Fact type: Color has Green Component | |
Fact type: Color has Blue Component | ||
Necessity: Each Color has exactly one Blue Component | ||
Fact type: Color has Alpha Component | ||
Necessity: Each Color has exactly one Alpha Component | ||
Necessity: Each Color has exactly one Alpha Component | ||
|
||
Term: Begin | ||
Concept Type: Date Time | ||
Term: End | ||
Concept Type: Date Time | ||
Term: Bounds | ||
Concept Type: Short Text | ||
Term: Date Time Range | ||
Concept Type: Short Text | ||
Fact type: Date Time Range has Begin | ||
Necessity: Each Date Time Range has exactly one Begin | ||
Fact Type: Date Time Range has End | ||
Necessity: Each Date Time Range has at most one End | ||
Fact Type: Date Time Range has 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. What is "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. Defines the lower and upper bound. Can be: 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. Yeah, this should be in an English form, eg 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. 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 commentThe reason will be displayed to describe this comment to others. Learn more. Yeah it should be an additional fact type |
||
Necessity: Each Date Time Range has exactly one Bounds |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{ | ||
types: | ||
postgres: 'TSTZRANGE' | ||
mysql: 'VARCHAR(255)' | ||
websql: 'VARCHAR(255)' | ||
odata: | ||
name: 'Self.DateTimeRange' | ||
complexType: ''' | ||
<ComplexType Name="DateTimeRange"> | ||
<Property Name="Begin" Nullable="false" Type="Edm.DateTime"/>\ | ||
<Property Name="End" Nullable="true" Type="Edm.DateTime"/>\ | ||
<Property Name="Bounds" Nullable="false" Type="Edm.String"/>\ | ||
</ComplexType>''' | ||
|
||
nativeProperties: | ||
has: | ||
Begin: (from) -> ['RangeBegin', from] | ||
End: (from) -> ['RangeEng', from] | ||
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. I'm guessing |
||
Bounds: (from) -> ['RangeBounds', from] | ||
|
||
fetchProcessing: (data, callback) -> | ||
if data? | ||
res = | ||
Begin: data.split(',')[0].slice(1) | ||
End: data.split(',')[1].trim().slice(0, -1) | ||
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('Begin') and value.hasOwnProperty('End') and value.hasOwnProperty('Bounds') | ||
processedValue = '' | ||
begin = undefined | ||
end = undefined | ||
bounds = undefined | ||
for own component, componentValue of value | ||
switch component.toLowerCase() | ||
when 'begin' | ||
begin = componentValue | ||
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] + begin + ', ' + end + bounds[1] | ||
callback(null, processedValue) | ||
else | ||
callback('has unknown components: ' + 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 would be more accurate as |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
helpers = require './helpers' | ||
|
||
helpers.describe 'Date Time Range', (test) -> | ||
begin = new Date() | ||
end = 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. Why not write this as |
||
bounds = '[)' | ||
describe 'fetchProcessing', -> | ||
test.fetch(bounds[0] + begin + ', ' + end + bounds[1], { | ||
Begin: begin.toString() | ||
End: end | ||
Bounds: bounds | ||
}) | ||
|
||
describe 'validate', -> | ||
begin = new Date() | ||
end = null | ||
bounds = '[)' | ||
test.validate({ | ||
Begin: begin | ||
End: end | ||
Bounds: bounds | ||
}, true, bounds[0] + begin + ', ' + 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.
I think this should be
Beginning
,has begin
sounds very weirdThere 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.
Or maybe
Start
is better actually, cc @alexandrosmThere 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.
Start
sounds good