-
Notifications
You must be signed in to change notification settings - Fork 67
Added :format option to the datetime column type #121
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
base: master
Are you sure you want to change the base?
Added :format option to the datetime column type #121
Conversation
*User can specify a parsing format to be used when type casting a date string into a NSDate object
Within the pull request an optional As Submitted class Task
include MotionModel::Model
include MotionModel::ArrayModelAdapter
columns :due_date => {:type => :date, :format => "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"}
endAs Proposed? class Task
include MotionModel::Model
include MotionModel::ArrayModelAdapter
columns :due_date => {:type => :date, :parser => ->{ ... } } # Block must return NSDate
endRight now there's no way to specify an alternate format (well, aside from defining a setter for that attribute), so I'm really just asking for suggestions on how to best add that capability to class Task
include MotionModel::Model
include MotionModel::ArrayModelAdapter
parse_dates_with_format "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
columns :name => :string,
:long_name => :string,
:due_date => :date
endOpen to ideas! |
|
I'm not crazy about a macro because it would be global. What if you had two remote sources that supplied (gasp!) two different formats? I think your initial as-submitted is good so long as the user knows to use the Apple formatters. If they don't cross-reference the Apple documentation, the Thoughts? |
|
I know that that Apple currently conforms to UTS#35, I'm just not familiar with how much the Date Field Symbols vary (e.g. when does 'yyyy' mean something else?). So on that note, I completely agree that it's difficult to know what others will expect or need, so having both makes sense. The parser approach also allows someone to use external libraries for much more complex parsing, which is nice! I don't have an issue dropping the From a performance concern, in the case of the I'll have to see what's available within |
|
Good point about the singleton. If people don't understand the implications of date parsing using My experience with users of MotionModel is that they love-love-love convenience, so whatever gets thrown in there is great by them. That said, I've had enough date handling issues that I feel there is not a right answer in the data management layer. Shall we go with |
|
As much as I like the convenience option, when it comes to I can include an example in the documentation for doing what this original pull request submitted using the new Would you prefer me to create a new pull request with the |
|
Same branch is fine. |
*User can specify a parsing format to be used when type casting a date string into an NSDate object