DateTime Parsing with MagicalRecord & Date Formats - magicalrecord

My server provides dates as UTC in the format "yyyy-MM-dd'T'HH:mm:ss'Z'" e.g. midnight of November 15 for MST is "2013-11-15T07:00:00Z". This format is the documented default for MagicalRecord but my imported NSManagedObjects are getting ANOTHER 7 hours added to them (NSLog shows "2013-11-15 14:00:00 +0000"), which I can only assume is MR's assumption that the timezone was actually a local one and then offset it to my device's local date to UTC during the import. How can I stop this? Is my server not returning the date in the proper format?

https://github.com/magicalpanda/MagicalRecord/issues/484
MagicalRecord have a bug with Z handling, but it seems that pull request for with bug is approved.

Related

Moment.js toISOString result is different?

Is something wrong with code.
var mom = moment("23-11-2016 00:00", "DD-MM-YYYY HH:mm");
alert(mom.toISOString());
//result 2016-11-22T17:00:00.000Z
Why the result is not 2016-11-23T00:00:00.000Z? How I can get 2016-11-23T00:00:00.000Z result?
As the doc says:
By default, moment parses and displays in local time.
while .toISOString() always returns a timestamp in UTC:
Note that .toISOString() always returns a timestamp in UTC, even if the moment in question is in local mode. This is done to provide consistency with the specification for native JavaScript Date .toISOString(), as outlined in the ES2015 specification.
You probably have -7 hours offset from UTC.
Use format() if you want to display date in local time.
If your input string represents a UTC time, then use moment.utc(String, String);

how to get default timezone time in moment timezone

I am using moment timezone to set default time
$moment.tz.setDefault('Europe/London');
$moment().toString();
is providing me the time in the defined timezone. but I need the timestamp. so I am using
$moment().now();
but it's returning the timestamp in local timezone. how can I get the timestamp of the default timezone(Europe/London)?
Moment.now is not really a public api. It is intended to be used for testing purposes only. All that you want to do is format a moment, so your code would be as follows:
moment.tz.setDefault('Europe/London');
moment().format(); //"2016-10-18T21:57:39+01:00"

ServiceStack DateTime Local not UTC

I am having a problem with the Servicestack I am getting a datetime from an external system and if I am using the DateTimeOffset I can se that the time is
15:00:00 +0200 I know that this is utc time stamp but Servicestack set is as local time this results in the time moving the wrong way.
I have read that you can tell the servicestack to allways use UTC but I cant find any where how to set it up and I don't know it this will help me.
from
Kenneth Foli Jørgensen
You can tell ServiceStack.Text's JSON/JSV/CSV text serializers to use UTC with:
JsConfig.AlwaysUseUtc = true;

MS JSON date serialization and daylight saving time

We have an Ajax web service hosted in an ASP.NET application. This service accepts a DateTime parameter which, for the purposes of this question, should receive the DateTime equivalent of /Date(1359727200000-0200)/, which is a MS-JSON literal for Feb 1, 2013 9:00 AM in Brazil time. This literal is what the browser sends within the Ajax request.
But instead of receiving that date and time, the argument passed to the service method is Feb 1, 2013 12:00 PM. To make matters worse, the argument's DateTimeKind is Local. It would be understandable if it were Utc, but even that would be incorrect since February 1st is daylight saving time in Eastern Brazil, so that 9:00 AM (local) sould be 11:00 AM (UTC). It really is a mess. By the way, the web server runs under Eastern Brazilian time zone.
Is there any ASP.NET configuration, service method annotation, specific client instructions, or any framework resource to work around this problem?
After much debugging I found the problem: I was ignorant of the way the JSON serializer works regarding the System.DateTime kind and the Date literal when (de)serializing dates back and forth between the server and the browser.
In detail, here's what happens. Suppose a service has to return a DateTime value to a client in JSON format. The DataContractJsonSerializer will produce a string in the (infamous) /Date(UTC ticks)/ format, which the client can parse into a JavaScript Date value. This serialization is sensitive to the DateTime's Kind property:
When the Kind is DateTimeKind.Utc, the string literal will contain "/Date(UTC ticks)/" and no time zone.
When the Kind is DateTimeKind.Local, the string literal will contain "/Date(UTC ticks-time zone)/".
If the Kind is DateTimeKind.Unspecified, it is assumed Local.
Conversely, if the client sends a date value to the service, the serialization process is also sensitive to the "kind" of the JSON literal:
When the literal is in the format "/Date(UTC ticks)/" with no time zone, the produced
DateTime will be of DateTimeKind.Utc kind.
When the literal is in the format "/Date(UTC ticks-time zone)/", the produced DateTime will be of DateTimeKind.Local kind.
All I had to do is make sure the client sends only UTC-formatted Date literals to the service. All is great now.

Documentum DQL: How can I get UTC time zone for Date columns to parse to .NET?

Documentum (DQL via DFC) always returns Date result columns as a string formatted like this:
Wed Oct 19 16:01:59 PDT 2011
...and the .NET DateTime.Parse function chokes on this — especially the PDT time zone (TZ henceforth) part of the strings — as far as I can tell, there is no concept of these TZ abbreviations in the DateTime parsing. Sure, it'll understand +8:00 but not PDT.
The TZ is based on the TZ of the content server, which may not always be the same TZ as the consumer of the web service (we're feeding out the DQL results via web service).
SO... if I can get Documentum to ALWAYS give me the UTC time in those strings, I can do the conversion quite easily on the client and always have their correct time zone.
Can this be done? Is there a Documentum setting for the content server to always return GMT times?
Alternative solutions?
For date format see dfc.date_format = setting which you can define in your dfc.properties file.
An excerpt from dfcfull.properties for details:
date format can be specied using the syntax of the Java SimpleDateFormat class
What version of Content Server do you have? In D6.x dates are stored in UTC and transformed to local TZ of client by Documentum client apps. For more details see:
https://community.emc.com/message/545879#545879
For DQL there is a datetostring function and it is possible to use it like this
select datetostring(r_creation_date, 'dd/mm/yyyy') from dm_document
it will return 28/12/2014
or with time like this
select datetostring(r_creation_date, 'dd/mm/yyyy hh:mi:ss') from dm_document
it will return 28/10/2014 23:58:35
for DFC it is not recommended to use getString for dates. It is recommended to use getTime method. It will return IDfTime object that can be converted to standard Date object.

Resources