Date/Time values  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Date/Time values

Postby pricerc » Fri May 06, 2022 11:14 am

Just out of curiousity....

So I have a new developer I'm bringing up to speed, doing some API/webhook stuff for me, and the question was asked: "Does the DB use UTC for its DateTime fields?"

Now, having been looking at the webhooks tables recently, I know this is a trick question, because the answer is 'it depends'.

I was wondering if you'd ever considered moving to using DateTimeOffset for storing date/time values, seeing as it is the only date/time datatype that is "unambiguous"?

(it's been my preference in any new development for some years now)
/Ryan

ERP Consultant,
Advanced ERP Limited, NZ
https://aerp.co.nz
User avatar
pricerc
Senpai
Senpai
 
Posts: 504
Joined: Mon Aug 10, 2009 12:22 pm
Location: Auckland, NZ
Topics Solved: 20

Re: Date/Time values

Postby SBarnes » Fri May 06, 2022 11:50 am

Hi Ryan

I’d also be interested in Scott and Mike’s opinion on this one particularly after having moved a legacy Jiwa system to Azure SQL which uses UTC and the previous JSP had custom stored procedures all over the place with calls to getdate, in the end we had to write an SQL function and work our way through and replace them all.

In addition to this systems like Salesforce keep everything in UTC so integration to them can be an issue also when trying to work out which side was the last to update.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Date/Time values  Topic is solved

Postby Mike.Sheen » Fri May 06, 2022 12:20 pm

It's come up a couple of times but we never got past considering it.

It's now logged as DEV-9298 - we need to solve a few problems such as how do we represent the date to the user - is it ok to just convert to their local or should we provide an indication of the timezone as well? (perhaps display as local, tooltip the actual date including timezone?)... things like that.

We'd probably also need to be careful about accounting periods - make sure the user can specify the date time with offset for the start of each accounting period - and likely a bunch of other things I've not thought of yet.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2445
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Date/Time values

Postby pricerc » Fri May 06, 2022 3:41 pm

Mike.Sheen wrote:We'd probably also need to be careful about accounting periods - make sure the user can specify the date time with offset for the start of each accounting period - and likely a bunch of other things I've not thought of yet.


I hadn't really thought about the accounting dates, just all the "last saved" timestamps.

But I can see handling accounting dates being 'tricky'. I suppose only the date part really matters, but as you suggest, whose date?

While you could configure a 'system time zone', if you had a company trading across the width of Australia, you probably don't want transactions happening at 8pm in Perth reflecting as being the following day because the 'system' time zone is Sydney.
/Ryan

ERP Consultant,
Advanced ERP Limited, NZ
https://aerp.co.nz
User avatar
pricerc
Senpai
Senpai
 
Posts: 504
Joined: Mon Aug 10, 2009 12:22 pm
Location: Auckland, NZ
Topics Solved: 20

Re: Date/Time values

Postby Mike.Sheen » Fri May 06, 2022 3:47 pm

pricerc wrote:you probably don't want transactions happening at 8pm in Perth reflecting as being the following day because the 'system' time zone is Sydney.


Exactly.

Imagine if we did that - people running a P&L in Sydney would get different values to someone running the same report and ranges in Perth. Or even getting a list of orders to pick for delivery the next day would be different depending on where you ran the report.

These are some of the reasons why we chose to ignore the problem.

We, much like Zaphod Beeblebrox, have peril sensitive sunglasses.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2445
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Date/Time values

Postby SBarnes » Fri May 06, 2022 4:36 pm

You would possibly either need to be able to specify the time zone against the user or pick it up off the local machine and convert them before display.

Interestingly Azure will let you specify the time zone for a web app through the app settings and adjust everything accordingly but not for Azure SQL.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Date/Time values

Postby pricerc » Fri May 06, 2022 4:54 pm

SBarnes wrote:Interestingly Azure will let you specify the time zone for a web app through the app settings and adjust everything accordingly but not for Azure SQL.

They probably figure the database server itself should be timezone-agnostic. i.e. that it's the app's problem, not the SQL Server's.
/Ryan

ERP Consultant,
Advanced ERP Limited, NZ
https://aerp.co.nz
User avatar
pricerc
Senpai
Senpai
 
Posts: 504
Joined: Mon Aug 10, 2009 12:22 pm
Location: Auckland, NZ
Topics Solved: 20

Re: Date/Time values

Postby pricerc » Fri May 06, 2022 5:02 pm

Mike.Sheen wrote:
pricerc wrote:you probably don't want transactions happening at 8pm in Perth reflecting as being the following day because the 'system' time zone is Sydney.


Exactly.

Imagine if we did that - people running a P&L in Sydney would get different values to someone running the same report and ranges in Perth. Or even getting a list of orders to pick for delivery the next day would be different depending on where you ran the report.

These are some of the reasons why we chose to ignore the problem.

We, much like Zaphod Beeblebrox, have peril sensitive sunglasses.


As previously mentioned, I was primarily interested in "non-accounting" timestamps. Which are not affected by these challenges.

But for the 'accounting' stuff, you (almost always) don't actually need the time, only the date, and so an option may be to have date-only values where only the date is interesting.
/Ryan

ERP Consultant,
Advanced ERP Limited, NZ
https://aerp.co.nz
User avatar
pricerc
Senpai
Senpai
 
Posts: 504
Joined: Mon Aug 10, 2009 12:22 pm
Location: Auckland, NZ
Topics Solved: 20

Re: Date/Time values

Postby perry » Thu May 19, 2022 6:04 pm

for non-accounting date, my thought would be having date only and datetime field, where date field is time zone independent and datetime field is always stored as UTC.

At the business logic layer, it should convert UTC based on time zone setting from
- warehouse time zone
- for records associated with a warehouse
- user time zone
- for those dont have warehouse

I guess date/time type custom fields should be split into multiple types as well...
Perry Ma
S. Programmer
Lonicera Pty Ltd
http://www.lonicera.com.au
perry
Frequent Contributor
Frequent Contributor
 
Posts: 173
Joined: Mon Oct 27, 2008 2:26 pm
Topics Solved: 15

Re: Date/Time values

Postby pricerc » Fri May 20, 2022 4:42 pm

perry wrote: datetime field, where date field is time zone independent and datetime field is always stored as UTC.
... convert UTC based on time zone setting from


Having dealt with time-based data across time zones and daylight savings changes in a past life, even using UTC is not always enough. At least not on its own - you always need some other external bit of information - as you suggest - like a timezone setting stored somewhere else.

That's why I was quite pleased to see the introduction of the "date/time offset" data type - which basically stores the UTC time, along with the time offset at the time of the transaction. As a troubleshooting tool, it can be really helpful, because you can see at a glance from the one data field if transactions have been coming from multiple time zones.

And if you have transactions happening between 2:00am and 3:00am on the day you're switching out of daylight savings - it can save a lot of head scratching if you have e.g. +6:00 and +7:00 on the timestamps.

It can also tell you if you have a system with the wrong time zone.

For new code, it's really easy to just use it instead of the traditional date/time data types, and write all the code with that in mind.

But for existing code, it is a right pain to change, because you have to assess every place where a date/time is used to make sure you have the semantics right. Mostly it's easy, but it is nonetheless a lot of tedious work.

You would also have to write some fancy SQL to update existing values to the right time zone(s).
/Ryan

ERP Consultant,
Advanced ERP Limited, NZ
https://aerp.co.nz
User avatar
pricerc
Senpai
Senpai
 
Posts: 504
Joined: Mon Aug 10, 2009 12:22 pm
Location: Auckland, NZ
Topics Solved: 20


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 9 guests