-
Notifications
You must be signed in to change notification settings - Fork 405
Support unix time instead of plain JS Date object #190
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
Comments
I can provide a PR for this if you'll accept it. If you want me to do it in a specific way, please say so. @dalelotts |
@dalelotts Ping |
Unix time does not have timezone info. Do you have a suggestion about how to handle the lack of timezone info in this case? |
@dalelotts You don't. If developer want's to use unix time, he/she (most probably) will be aware of that and will know how to handle himself/herself this situation. |
Possibly. It's hard to know all of the use cases. I have avoided this type of change because it is often connected to a sub-optimal implementation where time zone handling is not well thought out, which is the opposite of what you are suggesting. Can you give me some more detail on your use case? |
@dalelotts MongoDB's DateTime() is actually unixtime. A simple REST with Angular on the client side will pull unix time from the database. Now, I could intercept the unix time and convert it to what this library expects, but then I'd have to add yet another callback for when this library modifies the date (convert back to unix time). The entire thing feels a little bit dirty, as this could be a lot easier if I could just pass the model as-is to this library. |
@dalelotts Any news on this one? What do you think? Could this be implemented? |
…g data in the model Accepts any string value, but the following values have special meaning (these values are case sensitive) : * ```'Date'``` stores a Date instance in the model. Will accept Date, moment, milliseconds, and ISO 8601 strings as initial input from the model * ```'moment'``` stores a moment instance in the model. Accepts the same initial values as ```Date``` * ```'milliseconds'``` store the epoch milliseconds (since 1-1-1970) in the model. Accepts the same initial values as ```Date``` -Any other value is considered a format string. -When accepting values from, and saving values to the model, this directive tries to be as flexible as possible. Dates, moments, and milliseconds are all accepted as input no matter what you specify for ```modelType```. However, strings are problematic and often lose timezone information, so use caution when storing strings. -If you must use a string, be aware that the format stored in the model must exactly match the format specified in ```modelType```. For example, the value in the model is ```'2015-12-31'``` then using ```modelType: 'MM-DD-YYYY'``` will cause an exception. -I predict that I will regret adding this feature. closes #241, closes #190, closes #39
…g data in the model Accepts any string value, but the following values have special meaning (these values are case sensitive) : * ```'Date'``` stores a Date instance in the model. Will accept Date, moment, milliseconds, and ISO 8601 strings as initial input from the model * ```'moment'``` stores a moment instance in the model. Accepts the same initial values as ```Date``` * ```'milliseconds'``` store the epoch milliseconds (since 1-1-1970) in the model. Accepts the same initial values as ```Date``` -Any other value is considered a format string. -When accepting values from, and saving values to the model, this directive tries to be as flexible as possible. Dates, moments, and milliseconds are all accepted as input no matter what you specify for ```modelType```. However, strings are problematic and often lose timezone information, so use caution when storing strings. -If you must use a string, be aware that the format stored in the model must exactly match the format specified in ```modelType```. For example, the value in the model is ```'2015-12-31'``` then using ```modelType: 'MM-DD-YYYY'``` will cause an exception. -I predict that I will regret adding this feature. closes #241, closes #190, closes #39
Here is how i solved something similar I just added this to the directive
I also had to change all var ActiveDate (or format) to use ngModelController.$viewValue instead of ngModelController.$modelValue for active to work |
@jhammersholt - Do you have a commit or fork which I could use? |
@dalelotts - Hi, do you know when you can get this done ? Many Thanks! |
@arunthilak Have a look at the code in the develop branch - it adds modelType allowing you to store milliseconds (utc) - unix time is seconds but that would be easy enough to add as a modelType. I have not released this code to production yet due to the fact that I have not had anyone volunteer to test all of the new modelTypes. Check them out and let me know how it works for you. |
@dalelotts - Thank you for your develop branch. I tested it out and I am able to get epoch values directly in the ngmodel value. Well, it's kind of what I want. I think i misunderstood this feature request. I need to display the user friendly string date in the view after selection, but have the epoch in the model value, behind the scenes; you know when submitting the json to a server. Or vice versa - i.e. when server sends epoch, display the User Friendly date in the text box. Many Thanks, |
Maybe you can setup a fiddle, plunder, or jsbin example that I can look at. On Tuesday, January 26, 2016, arunthilak [email protected] wrote:
Sent from Gmail Mobile |
Here is a plnkr link: http://plnkr.co/edit/nNpfhewxc3BH5NVoFSes?p=preview |
My other directive, angular-datetime-input gets you mostly to where you want to be. See http://plnkr.co/edit/Nv7rpxPAJ2ud3O0ySHCm?p=preview The only remaining issue is that the stored data is in milliseconds UTC and has no timezone information, so when it is formatted by the angular-datetime-input directive it is UTC. (this is by design for this directive) Do you want to store the time values as UTC or local time? |
Oh, and one added benefit of the datetime-input directive is that the user can type in the date if they like, and it can accept multiple format, thus allowing the user to enter the date in the format they like best...but it will display is the format you specify |
@dalelotts - Ohh.. awesome thank you so much !!! I am building some apps using elasticsearch and opentsdb. The timestamps I need to send to the servers are always in GMT, so this works for me. Many Thanks, |
@dalelotts : While using this we realized how we could deal with the timezone, which of course is not stored with the epoch. You can have the option to either display the time in Local Time (of browser) or UTC. |
Great! Is there an example you can share about how you did it? |
Hi Dale, If you notice Example 2 - If we pass millisecond data type, it correctly On other hand in Example 1 - if we select a particular date, say 11 AM, it Am sorry, if I messed it up, but can you please help me figure out how I Many Thanks, On Mon, Feb 1, 2016 at 11:41 AM, Dale Lotts [email protected]
Arun Thilak |
@arunthilak, your example makes sense. That's the issue I was mentioning earlie. I'm not sure what the most common use case is for milliseconds - UTC all the time, or UTC in the model and local time in the UI. I suspect the later. |
@dalelotts - Yes, totally agree .. UTC in the model and Local time in the UI is the most useful case. So the problem that I am having now is that, I am unable to figure out how to pass Local time to the dropdown calendar (Or how to toggle between UTC and LOCAL for dropdown). How can we synchronize the dropdown calendar Time Zone with View Time Zone, rather than the model Time Zone. Many Thanks, |
Good question. I think this will require a change to have the model and the UI in different time zones. As a work around, you can use the set-time callback to set the "real" UTC value in the model, but drive the UI off of a an ignored property in the model that stores the local time. |
Thanks again. As you suggested I was able to fix the issue in set-time http://plnkr.co/edit/kWBklqTmTgBlbaXgOgcV (Example 2) Lines 492-496 that I changed are in set-time function:
Many Thanks On Fri, Feb 5, 2016 at 4:43 PM, Dale Lotts [email protected] wrote:
Arun Thilak |
No description provided.
The text was updated successfully, but these errors were encountered: