Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
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.
Expand Down
17 changes: 16 additions & 1 deletion Type.sbvr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

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 weird

Copy link
Collaborator

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 @alexandrosm

Copy link
Contributor Author

@izavits izavits Sep 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Start sounds good

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is "Bounds"?

Copy link
Contributor Author

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: [], [), (), (]

Copy link
Collaborator

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 that

Copy link
Contributor Author

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.

Copy link
Collaborator

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

Necessity: Each Date Time Range has exactly one Bounds
55 changes: 55 additions & 0 deletions src/types/Date Time Range.coffee
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]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing RangeEng should be RangeEnd?

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do some validation of this?

when 'bounds'
bounds = componentValue
Copy link
Collaborator

Choose a reason for hiding this comment

The 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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be more accurate as is missing components

}
22 changes: 22 additions & 0 deletions test/Date Time Range.coffee
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 + ''
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not write this as 'null'?

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])