JSON.deserialize adding time - salesforce

CalEvent calEvent = (CalEvent) JSON.deserialize(calEventJson, Technician_Dispatch_Util.CalEvent.class);
System.debug('OGDEBUG TDU calEventJson '+calEventJson);
System.debug('OGDEBUG TDU updateTechnicianCalEvent calEvent.startTime '+ calEvent.startTime + ' calEvent.endTime '+calEvent.endTime);
15:13:56.110 (110381617)|USER_DEBUG|[185]|DEBUG|OGDEBUG TDU calEventJson {"id":zzzzzzzzzzz","title":"zzzzz New College of zzz","allDay":false,"startTime":"2015-07-27T00:00:00.000","endTime":"2015-07-27T01:00:00.000","ownerId":"zzzzzzzzzz","description":"Perform PM visit as detailed on supplied spreadsheet. Check service office's documentation for equipment list. Contact dispatcher at Help Desk with any questions. For damaged equipment please specify the following:\n\n* Room Name:\n* Manufacturer:\n* Model:\n* Serial No.:\n* Problem: \n\nROOMS TO COVER:\n\nNew College of zz- Sarasota Fl - Carriage House\n\nNew College of zz- Sarasota zz- CHL 0\n\nNew College of zz- Fl - CHL 2z1"}
15:13:56.110 (110791126)|USER_DEBUG|[186]|DEBUG|OGDEBUG TDU
updateTechnicianCalEvent calEvent.startTime 2015-07-27 04:00:00
calEvent.endTime 2015-07-27 05:00:00
You can see from the above log output that the json being passed in are correct:
"startTime":"2015-07-27T00:00:00.000"
"endTime":"2015-07-27T01:00:00.000"
However after calling JSON.deserialize time is added onto them (4 hours)
calEvent.startTime 2015-07-27 04:00:00
calEvent.endTime 2015-07-27 05:00:00
Why is this and how can I prevent against it?

DateTime supports the presentation of the Date/Time in both GMT and in
the time zone of the User. Is the User you are testing under in a time
zone that is 4 hours different from GMT? Your debug output is I think
being presented in the timezone of your User rather than in the GMT
timezone.
If you change your debug output to use calEvent.startTime.timeGmt()
and calEvent.endTime.timeGmt() I think you will see that the values
from the JSON are preserved.
Quoted from the salesforce stackexchange
https://salesforce.stackexchange.com/a/88739/24064

Related

suiteCRM API dates are incorrect

We recently did an upgrade on our CRM to version 7.12.5 (I'm not sure what version we upgraded from). Previously, on the API, the dates I'd be looking at were always in +00:00 (GMT). I.e., 01-01-2023T13:00:00Z-00:00. This is a correctly formated ISO8601 datetime representing Jan 1st 2023, 1PM, in GMT.
Now they are like 01-01-2023T13:00:00-05:00. Except that the 13:00:00 part is actually the GMT time stored in the MYSQL database. So it's like a GMT time, with a -05:00 timezone slapped onto it. This makes no sense to me.
An example- I create a record at 13:00:00 EST. In MariaDB, it displays correctly as 18:00, but when I look at the record in an API call, it displays as ...T18:00:00-05:00.
EDIT: There's also situations where the date_entered and date_modified fields are in two different timezones(?!). I.E.:
"attributes": {
...,
"date_entered": "2018-09-17T13:38:00-04:00",
"date_modified": "2020-02-27T16:12:00-05:00",
...
}
Previously, these were ALL in -00:00.
Any idea on why this could be? I don't have full admin access on this server but I may be able to provide more information if needed.

Can anyone help me identify this timestamp format?

I am importing information from an Oracle database on an AIX machine into SQL Server 2008r2. I inherited this process from the previous DBA. The timestamp comes in the following format: 4170180534, which, based on the conversion function in the executable, converts to the following:
417 = year (2017)
018 = days since beginning of year (018 converts to Jan 18)
0534 = time HH:mm
I need to provide maintenance on the conversion function (the previous DBA retired in 2016, so the date conversion function only works through the end of 2016).
Can anyone tell me exactly what this timestamp format is? I assume the '4' stands for the century, but it would be nice to know for sure what the first digit of the value actually is.
4should stand for weeks since start of year
format for that would be
(weeks since 1st jan, 2last digits of year, days since 1st jan, hours, minutes)
WW IY DDD HH MI

Find out client time zone in UTC format in Angularjs

Is there some way to find out what is the time zone of a user, in UTC format(like UTC+1, UTC+2,...etc)
What I am trying to accomplish is that after user selects UTC time zone from drop down and selects time and date, I want to show date and time values in his time zone (time zone from browser or system).
So if for example user selects: UTC+2 and 13:00 11-03-2016 and his system time zone is UTC than I want to show in some label: In your time that is: 11:00 11-03-2016 (since the UTC is minus 2 hours comparing to UTC+2)
Does somebody has suggestions on how to accomplish something like this?
Just create new Date object without specifying the time zone - JavaScript will use the browser's time zone and when getting a date, without specifying the time zone, the result is converted to the browser's time zone.
Please review examples on http://www.w3schools.com/js/js_dates.asp
Hope it will help. Handling dates in js and angular is a bit tricky;)

Check if DST is on according to UTC time in sql

I am working in MVC4 project where i am facing problem with time.Actually my project requirement is to show all time used in application according to Brazil time.So i have used GETUTCDATE() for saving time in application.
Now i want to check if DST is on according to time i saved..i mean central time. How do i check this.
I have search on net and found one solution
DECLARE #IsDST BIT;
SET #IsDST = CASE WHEN DateDiff(hour, GetDate(), GetUTCDate()) = 4 THEN 'True'
ELSE 'False' END;
SELECT GETDATE() AS GETDATE,
GETUTCDATE() AS GETUTCDATE,
#IsDST;
But when i try to run this script,it return false ??
But as per DST calculation,it always starts from 2nd Sunday of March and ends on 1st Sunday of November.
Then it should return true ,that DST is on.
Am i doing right or is there another better approach to check if DST is on central time,so that i can show brazil time according to DST
Well, this particular code doesn't work for detecting DST in Brazil, because it just measures the difference right now between local time and UTC, checking for 4 hours difference or not.
Most of Brazil is 3 hours behind UTC in the standard time, and 2 hours behind UTC in the daylight time. So this code probably won't work for you. You can read more in this Wikipedia article.
Daylight Saving Time is very different all over the world, so if you intend to use this approach then you will have to modify your code to match the time zone of the server that it's running on.
Personally, I would recommend not doing this in SQL at all. Time zone conversions aren't really the realm of the database. They work much better in application code. You should work with UTC in your database, and convert it to Brazil or whatever time zone you require in your application.
Since you said this was an ASP.Net MVC4 application, I recommend you either use the .net TimeZoneInfo class, or use the excellent Noda Time library to do your conversions in your .Net code.
Using TimeZoneInfo:
DateTime utcDT = // ... your UTC value returned from the database
TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById(
"E. South America Standard Time"); // Brazil
DateTime brazilDT = TimeZoneInfo.ConvertTimeFromUtc(utcDT, tz);
Using Noda Time:
DateTime utcDT = // ... your UTC value returned from the database
Instant instant = Instant.FromDateTimeUtc(utcDT);
DateTimeZone tz = DateTimeZoneProviders.Tzdb["America/Sao_Paulo"]; // Brazil
ZonedDateTime brazilZDT = instant.InZone(tz);
DateTime brazilDT = brazilZDT.ToDateTimeUnspecified();

Storing and searching opening/closing times for stores

I'm writing an application that indexes data for our stores, some of which are open late (8 am - 2 am). We need to be able to search this database quickly -- basically, to run a query to find which stores are open at a given point in time (now, Sunday at 1 am, whatever).
In addition, the open/close times can vary day-by-day -- some stores are closed on Sundays, for example.
The obvious solution to me would be to make a table where I have a row with the store ID, day, open time, and close time. For something like Monday, 8 am - 2 am, that would actually be two rows, one for Monday 0800 - 2400, and one for Tuesday 0000 - 0200.
We have a lot of stores, so the search has to perform well (basically, the data has to be index-friendly), but I'll also have to display this data back out in a human-readable format. With my current solution, that'd look something like this:
Monday: 8:00 - Midnight
Tuesday: Midnight - 2:00 am; 8:00 am - Midnight
I'm just wondering if anybody else has alternative solutions before I jump right to an implementation. Thanks!
When PBS (the US Public Broadcasting System) faced this same problem a couple of years ago, they invented the idea of the "30 hour day" -- Where 00:00 is midnight at the start of the day, 24:00 is midnight at the end of the day, 25:00 is 1am the next day, 30:00 is 6am the next day. That way Mon closing time of 26:00 is 2am Tues morning.
Rather than two records representing a single store's times for a day, it may be more object oriented to think of the "store day" as the object. That way 1 record = 1 store's times for a day. If you want to store the two sets of open/close times, just use four fields in the record instead of two--and adjust your queries appropriately.
Remember that your queries should use a library/api that you write and publish. The library will then deal with the data store and its data layout. No one but your library should be looking at the db directly.
Time zones are very important in this sort of app too. (Hopefully) at some point, the store chain will expand to cover more than one time zone. You'll then need to determine the local time of the query. -- May not the same as the time zone of your server which is handling the queries.
Further thoughts--
I now see that you're standardizing to GMT. Good. You could also use datetime values (vs time values) and standardize to a given week in time. Eg open time is Sun Jan 1, 1995 10am - Mon Jan 2, 1995 2am (using Jan 1, 1995 as a base since it was a Sunday).
Then rationalize your "current time and date" to match the same point in the week of Jan 1, 1995. Then query to find open store days.
HTH,
Larry

Resources