ember-cli and Rails 5 api date handling - ember-cli

I am trying out rails 5 api and ember-cli (2.11) for the first time. I am having trouble with date handling.
I have a date attribute in rails outputting json like
"2017-03-15"
The date (in ember inspector) becomes
Tue Mar 14 2017 20:00:00 GMT-0400 (EDT)
I use a seed file to create records like:
Planting.create(planting_type: 'seed', planting_date_begin: Date.new(2017,8,1))
I only care about date (not time). How do I get date to display correctly in Ember as well as determine if other dates are within date range (date math)?
Do I need to change my rails attribute to DateTime? If I do change to DateTime will Ember still need adjustment for timezone? What about my seed file...will I need save like a timestamp with no timezone but with time info?

Ember was converting my date into a time with wrong time zone. using the add-on https://github.com/thoughtbot/ember-utc-transform changes zone to utc resolved my issue

Related

How to fix dates lagging one day behind in calendar

I'm developing a Clio integration with access to the calendar, but there's been an issue with dates. While the documentation says they expect an ISO-8601 timestamp date, it seems like there's something adding offset to the timezone value in dates being sent to the system.
For example, if I send a date 2018-05-17T23:59:59.999999-04:00 on both start_at and end_at properties when creating a calendar entry for an all day event, the value returned when fetching this entry through the API is 2018-05-17T17:00:00-07:00, which is clearly wrong. Am I missing something here?
The expected result should be something like either 2018-05-17T23:59:59-04:00 or 2018-05-18T03:59:59Z if milliseconds are ignored.
All dates are based on UTC timezone. Could it be that your site/server/script is set to a local timezone and so the dates are off for part of the day?
Try setting your scripting environment to UTC time before making any date/time-based queries.

Ext.Date.format wrong format

I am facing an issue in ExtJS with the Date format.
I'm using Ext.Date.format(value, 'm/d/Y h:i:s a') where the value is a date from the database.
While saving a Date 06/29/2018 12:15:00 am to DB it's storing as 2018-06-26 07:30:00
I am getting the Date from Database as 2018-06-28T18:45:00.000Z when converting to Ext.Date.format it changes to 06/29/2018 12:15:00 am.
I need store the date to be same as UI(06/29/2018 12:15:00 am) in db. Is there anyway?
Thanks
The reason might not be ExtJS itself nor your database, but the fact that your server and browser are on different timezones (i.e. Server in USA and browsing in Europe). I can think of two solutions:
1) Store the timezones in the database along with the dates. The record would look something like this: 2018-06-28T18:45:00.000Z+10:00. Use .NET's DateTimeOffset type in your C# code for this alternative.
2) What you can do instead is to convert all dates to UTC in the server side. Probably calling DateTime.ToUniversalTime() will suffice, but you can see this answer for more details.
Then you can use a library like moment.js which helps a lot with date and time manipulation/formatting to display the dates in the user's local timezone.

ApI blueprint Date format

I have problem understanding the following date formate from apiblueprint tutorial
2016-02-05T08:40:51.620Z
I now 2016 is the year 02 is the month 05 is the date and 08:40:51 is the time but I dont understand the last part .620Z.
Can some one explain it for me. I wanted to find out AM or PM of the time using javascript from the date using javascript and not sure whether the formate is 12 or 24 hours.
Thanks
First of all, API Blueprint doesn't require you to use any particular Date format; you are free to use whatever you want to.
The format used in the tutorial is the standard ISO 8601 format: .620 is the number of miliseconds, and Z designates a Zulu timezone, meaning UTC.

ASP.NET MVC Handle Timezones Entity Framework

I like to save the current DateTime.Now for the current user as UTC. For any user the time is than relative to each other ? I used this code snippet to realize UTC for the Entity Framework:
Entity Framework DateTime and UTC
After a look into the database the column for the date has not changed.
09.05.2014 20:21:24
I need to show on the client side the date relative to each user. So when the user created his account in America 14:00 I like to see in Europe 20:00.
First of all you need to use DateTime.UtcNow instead of DateTime.Now. EF will save date as it is, it will not do anything.
For database, it is just a date, whether it is UTC or specific time zone, database has no idea. It is only when we retrieve date from database, before displaying it to local user, we should call ToLocalTime or similar method in client UI library to convert UTC into localtime. ToLocalTime assumes that input is actually UTC.
If you are saving date from client side, for example with AJAX post in JavaScript, JavaScript dates should be serialized as UTC.
Remember that server has no idea from where you are sending date, server cannot convert any date to UTC, client on other hand has complete idea of which country and which timezone it is set at and it can easily convert local time into UTC.
Calling .ToLocalTime() on a DateTime object will convert it to the local time. You should always Save the date as UTC then convert upon display.

Mongodb date is off by 1 hour

I am running mongodb on ubuntu server. The server time is
root# date
Thu Sep 13 21:15:58 BST 2012
But when I run the following command I get a different result
root# mongo
MongoDB shell version: 2.2.0
connecting to: test
> new Date()
ISODate("2012-09-13T20:15:58.670Z")
There is exactly one hour difference. When I update a documents updated_on field with php using MongoDate(), the value of the field is still 1 hour off.
[EDIT]
Actually I just checked my php error log and the time in the log file is 1 hour off as well
[13-Sep-2012 20:11:14 UTC] Log Message (Time should be 21:11:14)
Mongo tells you
2012-09-13T20:15:58.670Z
Z = Zulu time / Zero offset / UTC. You can also express the time in that TZ as 2012-09-13T20:15:58.670+00:00, as defined in the ISO8601 standard by the way.
BST is UTC+1. So, they are the same time but in different time zones.
You can resolve this issue by displaying the DateTime with ToLocalTime method.
MVC C# Example: #Model.StartDate.ToLocalTime()
This is due to the way MongoDB store datetime in BST format. So the daylight savings time or the time zone of the server will have an effect on the actual date time returned to the application. This simple code will be able to format as usual with ToString("dd MMMM yyyy hh:mm tt") or any other format based on your requirements.
Here you need to understand a concept in time setting in clocks called daylight saving time. In some countries around the world the clock is advanced by 1 or more hours to experience day light by one more hour. The difference between IST and GST is 5.30 hrs but the actual time difference is between New Delhi and London time is 6.30 hrs. See this article from 4GuysFromRolla for setting and using server time.
On windows change your timezone.
Controll Panel -> Date and Time -> Change on timezone -> (UTC) Coordinated universal time.
And then just change your time