suiteCRM API dates are incorrect - suitecrm

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.

Related

Angular - Use of i18n and l10n for date time and timezone management

On server side DateTime is saved as per UTC (2016-03-24 17:45:12) and to client it is always returned DateTime as UTC. There are different users from world.
What is the best way to do date-time display management with i18n and l10n in angular?
Also i want that it should display date-time as per timezone of the user.
There are lots of feeds shown from all over the world like StackOverflow Posts. From server side always DateTime are passed in UTC time zone. On client side, date time can be displayed in two formats like below.
Showing date time of post as per time zone
Showing time-ago facility like (Just Now, Minute Ago, Hour Ago, Day Ago, Month Ago, Year Ago, 2 Years ago, 3 Years ago, etc)
This type of date times displayed across system multiple times for posts. So what is best way to use angular to have very less code for managing this.
How/When/Why to use Filters, Directives, Expressions for this?
(P.S. I am new to angular.)
Update:
More explanation:
Post object can be single page or array of objects.
And post date time will be like UTC: (2016-03-24 17:45:12)
So there are two cases which can be displayed like:
5 Months Ago
2016-03-24 11:15 PM (IST time)
You can trust the users' browsers. To display a date, you can use myDate.toLocaleString(). It will display the date using user's locale settings.
For "time-ago" format, you can use AngularJS version of moment.js: https://github.com/urish/angular-moment#am-time-ago-directive

Working with UTC and current time zone

I'm working on a project that was used only in one country but now is in using in several countries.
So I'm working in some DateTime issues, as you can image.
I'm using angular js for my frontend, python for my backend and Postgres as my database in this project.
To avoid any problem with DateTime and try to make more easy to work with the timezones I'm saving the DateTime in the database as UTC.
from DateTime import DateTime
# inside a class of my entity
self.start_date = datetime.utcnow()
This is working fine, the problem is when I try to convert the date back.
For example.
If my application is running in a country with GMT -1, when the user
asks to save the entity and it's 2016-07-13 15:00:00, in the database
(using the UTC now()) the DateTime will become 2016-07-13 16:00:00.
But when I try to get back the value I have two scenarios:
If I don't do anything, I'll receive the DateTime like it's on the database, "2016-07-13 14:00:00"
If I try to convert to the local timezone, I'm getting like 2016-07-13 17:00:00. The time was increased by 1 and not decrease was I expected.
I'm trying to use the momentjs library to work with dates, but nothing seems to work.
I'm wondering if what I supposed to do is get the GMT, like (-01:00) then do some math with the DateTime that comes from the database, like sub or sum the GMT hours difference.
Solution:
My solution for this was, store everything as UTC in my database.
Retrieve the datetime as UTC and covert to browsers timezone using momentjs library.
Doing like this.
moment.tz(moment.utc(datetime), moment.tz.guess());

Date from angular(timezone) to server (utc) then utc to Timezone

I have an issue with getting dates back in the right timezone.
Firs at all in the local machine, everything works fine but not in the server: the server is hosted in USA and the clients mostly are in Australia.
So a date is sent from angular app("12/23/2015 11:00:00 AM") to the server, the server store a date as utc in the database, until this point everything is working(I checked and the date is stored in the right utc)
book.StartDateTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.SpecifyKind(book.StartDateTime.Value, DateTimeKind.Unspecified), ToolsHelper.OlsonTimeZoneToTimeZoneInfo(locationDetails.TimeZone)); // book.CreatedDate.Value.ToUniversalTime();
The issue is:
When a client request some dates stored in the database. The date stored in the database is return back to the client like this:
bookview.StartDateTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.SpecifyKind(bookli.StartDateTime.Value, DateTimeKind.Utc), ToolsHelper.OlsonTimeZoneToTimeZoneInfo(deCompany.TimeZone));
I checked and at this point the date is "12/23/2015 11:00:00 AM" -> the conversion is right in the server(in the server side I put a log),
But in the angular is shown as "12/23/2015 10:00:00 PM"
So apparently the issue is when the date is transferred by the api to the client, maybe when is converted to JSON
I have tried different ways nothing work, I have removed "DateTime.SpecifyKind", I convert the date to string then back to datetime format and nothing seems to work.
What could I do?
A few things:
Your example is not complete, so I can only speculate on some areas. It would be better to show both sides, including how you load and parse the data in Angular, and what the data looks like over the wire.
You shouldn't be sending dates back and forth in a locale-specific format like "12/23/2015 11:00:00 AM". You might use those in your UI, but they're not appropriate over the wire (in your JSON). Instead, you should be using ISO8601/RFC3339, such as "2015-12-23T11:00:00Z". (You probably are already doing this if you're using WebAPI.)
A DateTime object when serialized to ISO8601 format is coupled with the associated DateTimeKind in the Kind property.
If the Kind is Utc, then the ISO8601 string will end with a Z.
If the Kind is Local, then the ISO8601 string will end with the machine-local offset for that timestamp, such as -08:00.
If the Kind is Unspecified, then the ISO8601 string will not have either Z or offset - which means that it cannot unambiguously represent a specific moment in time.
This is ultimately the cause of the error. You're converting the DateTime to another time zone, which leaves it with Unspecified kind, which then gets serialized without an offset - so on the client side that gets interpreted (probably) in the local time zone of the browser.
A better approach is to use DateTimeOffset instead of DateTime. Then you don't have to worry about Kind, and the offset is always present. If you change your bookview.StartDateTime to a DateTimeOffset type, you can do something like this to fix the problem:
DateTimeOffset dto = new DateTimeOffset(bookli.StartDateTime.Value, TimeSpan.Zero);
bookView.StartDTO = TimeZoneInfo.ConvertTime(dto, ToolsHelper.OlsonTimeZoneToTimeZoneInfo(deCompany.TimeZone));
That will ensure that the offset gets persisted in the data.
On the client side, pay careful attention to how the ISO string gets parsed. if it's loaded into a Date object, then it will indeed be converted to the client's time zone. Instead, you might take a look at moment.js for client-side time formatting. In particular, use moment.parseZone to keep the value in the same offset that it was presented. For example:
var s = moment.parseZone("2015-12-31T11:00:00+00:00").format("L LT"); // "12/31/2015 11:00 AM"
In commented code, you also showed a call to DateTime.ToUniversalTime - be very careful with that. If the source kind is Unspecified, it is treated as Local. Therefore, the local time zone of the computer is reflected in the converted value. It's better to avoid ToUniversalTime and ToLocalTime entirely. Use only the conversion methods on TimeZoneInfo.
ToolsHelper.OlsonTimeZoneToTimeZoneInfo isn't something we know about either. But I'll assume it does a CLDR mapping similar to this one. However, if you're working with Olson time zones anyway, the better approach would be to not use TimeZoneInfo at all. Instead, use Noda Time, with it's native support for tzdb time zones.

Excel Power Query - convert date time from UTC to Local

I'm connecting to an MS SQL database via Power Query (Version: 2.10.3598.81) in Excel 2010.
My dates are stored in UTC in the database, however I would like to show them as local in the spreadsheet.
DateTimeZone.From() - converts to a DateTimeZone type but assumes the input date is in the Local timezone. This is the exact opposite of what I want.
DateTimeZone.ToLocal() - gives an error, I think because there's no timezone information in the source date.
Local in my case is Australian EST, however it would be great if Excel just picked up the local timezone. (It appears to do this already)
I think I've discovered the answer.
The function DateTime.AddZone() which I thought was used to convert between timezones is actually used to add timezone information to an existing date. If your date is UTC you would use DateTime.AddZone([date_created],0) and if your date was already in AEST then you would use DateTime.AddZone([date_created],10).
So I can now use:
DateTimeZone.ToLocal(DateTime.AddZone([date_created_UTC],0))
and Power Query will correctly convert my date created from UTC to AEST (or whatever is local).

Convert like America/New_York in MySQL server 2008 R2 server

13:30:00 Friday April 19, 2013 in America/New_York converts to
09:30:00 Friday April 19, 2013 in America/Anchorage
Convert like this in SQL Server 2008 R2.
using select query.
Please help me on this.
Thanks,
we will convert in java wright from "America/New_York" to America/Anchorage like way i need a select query to convert EST time to other time zones..please not the time zone cannot be given like MET,GMT and all...
PLEASE NOTE:- All time zones will only be like plain text America/Anchorage
You are looking for this function:
CONVERT_TZ(dt,from_tz,to_tz)
CONVERT_TZ() converts a datetime value dt from the time zone given by from_tz to the time zone given by to_tz and returns the resulting value. Time zones are specified as described in Section 10.6, “MySQL Server Time Zone Support”. This function returns NULL if the arguments are invalid.
https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_convert-tz

Resources