How episerver CMS stores local datetime values to UTC - episerver

When we publish page in episerver (version 11) in CMS edit mode, page's "Published date time value" shows (in CMS edit mode) in user's local timezone ( i.e. specific to user's browser culture)
But I'm aware EPiServer stores datetime values in UTC format in database.
Can you please advise how it is converted to UTC from local time value while saving in database ? Please suggest how can i explore it ?
Thanks

Tried the DateTime.ToLocalTime? Should give you what you want.
univDateTime = DateTime.Parse(strDateTime);
localDateTime = univDateTime.ToLocalTime();

Related

Joomla Wrong Time Zone on insert / update DB

I am developing a plugin and at some point I submit a time value to mariadbb 10.1 in a time field. Maria DB timezone is set to 'Europe/Athens' both for the global and the session time_zone varialbe.
Although in my global configuration I have set the website Time Zone to "Europe/Athens" my value is inserted as UTC time, 3 hours earlier.
The output of the date_default_timezone_get() is 'UTC' so the above faulty behavior is expected.
I have not change somewhere else the timezone so I am stuck.
I don't want to execute date_default_timezone_set() everywhere. I would prefer to use Joomla global set variable.
Any help is appreciated.
I got the same problem already, let set timezone of server with same timezone of Joomla then everything is will be fine.
In case someone has the same problem that 's how I solved it.
I was filling values with date('Y-m-d H:i:s'). By changing to
$d = new DateTime('now', $timeZone)
solved my problem. Where $timeZone is a DateTimeZone. Thus my dates had datetime zone information.
Another point was at calendar fields where I had to set filter="none" instead of the "utc" which is the default.

Date is saving one day less in react

I'm using react widget date picker. (https://jquense.github.io/react-widgets/docs/#/datetime-picker?_k=c0gioy)
I'm passing date in this format : Sat Jul 15 2017 00:00:00 GMT+0530 (IST)
I'm using laravel in server side.
But date is saving one day less. It's saving as 2017-07-14 in database.
Can anyone please tell me the reason ?
Thank you.
In your config file, set an env variable called APP_TIMEZONE with whatever timezone you want it to use
if you are dealing with database timezone, add DB_TIMEZONE in .env file and set its value to the timezone you want
EDIT
the backup solution (if none was found), would be to create a custom function that calculates the offset between the client timezone and the server timezone. then use it to save the appropriate date to the database.
an example:
function date_default_timezone_offset_get()
{
$offset = timezone_offset_get(new \DateTimeZone(date_default_timezone_get()), new \DateTime());
return sprintf("%s%02d:%02d", ($offset >= 0) ? '+' : '-', abs($offset / 3600), abs($offset % 3600));
}

What is a valid string value for time(7)

Working on a ASP.NET MVC web application project that uses Entity Framework 6.0 and SQL Server 2014 database.
START_TIME column is defined as time(7). When the View posts back a value like 08:00 am the Controller sends back this error.
"The value '08:00 am' is not valid for START_TIME."
Isn't the hh:mm tt format supported as described in the Supported String Literal formats for time section?
Omitting tt in the format works. But I need to have that. I don't want to use military time if at all possible.
EDIT (adding model's properties screenshot):

Is it possible to specify time zone for DB data source in PHPStorm?

I have UTC time zone set in my PostgreSQL and SELECT NOW() shows me the right date in psql console.
I use PHPStorm for development and its database console for accessing my database, but it uses different time zone (Europe/Moscow, which is the time zone of my Mac), and SELECT NOW() shows me the time in this time zone (and by the way, the date is wrong, because the Europe/Moscow time zone recently changed its offset to +3 from +4).
I have not found any information on how to tell PHPStorm to use the time zone configured in postgresql.conf instead of system's time zone. Is it possible?
verify your timezone with query
SELECT * FROM pg_timezone_names
now add phpstorm.vmoptions the config off timezone
-Duser.timezone=posix/America/Sao_Paulo
Apply changes, disconect, synchronize and verify whithselect now()
Well, I've found a solution, but it will affect every time-specific behavior in IDE, e.g. console logs will show datetime in UTC.
The idea is to pass a timezone to VM options. For that we need to modify a file and restart IDE.
For Mac OS X for the latest version of PHPStorm:
cp /Applications/PhpStorm.app/Contents/bin/phpstorm.vmoptions ~/Library/Preferences/PhpStorm2016.1/
Then add -Duser.timezone=UTC to the file, so that it looks something like that:
-Xms128m
-Xmx750m
-XX:MaxPermSize=350m
-XX:ReservedCodeCacheSize=240m
-XX:+UseCompressedOops
-Duser.timezone=UTC
After phpstorm.vmoptions file modification with -Duser.timezone=UTC line I've seen correct return only from NOW() function but incorrect from the queries to a table like SELECT timestamp FROM ...
Only adding a variable timezoneAsRegion with false value to Advanced tab of connection without any phpstorm.vmoptions changes helped me to return correct timezone from the table.
Documentation link: https://www.jetbrains.com/help/phpstorm/2016.1/data-sources-and-drivers-dialog.html#advancedTab

Why doesn't appengine auto-convert datetime to UTC when calling put()

Here's what I'm trying to do: the user submits a time in pacific, once submitted I use .replace to set the timezone to Pacific.
Pacific = time.USTimeZone(-8, "Pacific", "PST", "PDT")
addEvent.date = addEvent.date.replace(tzinfo=Pacific)
Once i've set the tzinfo, I'm doing a put. According to the python documentation of google appengine it says:
"If the datetime value has a tzinfo attribute, it will be converted to the UTC time zone for storage. Values come back from the datastore as UTC, with a tzinfo of None. An application that needs date and time values to be in a particular time zone must set tzinfo correctly when updating the value, and convert values to the timezone when accessing the value."
However, when I do a put(), i get the following error:
WARNING 2012-10-06 21:10:14,579 tasklets.py:399] initial generator _put_tasklet(context.py:264) raised NotImplementedError(DatetimeProperty date can only support UTC. Please derive a new Property to support alternative timezones.)
WARNING 2012-10-06 21:10:14,579 tasklets.py:399] suspended generator put(context.py:703) raised NotImplementedError(DatetimeProperty date can only support UTC. Please derive a new Property to support alternative timezones.)
Please note I am using NDB
Ok, so after doing that I assumed that maybe NDB doesn't automatically convert it into UTC. So then I tried to convert it to UTC using the following code:
class UTC(tzinfo):
def utcoffset(self, dt):
return timedelta(0)
def tzname(self, dt):
return str("UTC")
def dst(self, dt):
return timedelta(0)
and now I still get the same error even after I convert the pacific time to UTC and set the tzinfo name as "UTC".
Could really use a ton of help here...
thanks!
The solution is to remove the tzinfo completely from the time after converting to UTC.
timestamp = timestamp.replace(tzinfo=None)
Here my working example:
if my_date.utcoffset():
my_date = (my_date - my_date.utcoffset()).replace(tzinfo=None)
I ran into this using http://hnrss.org/. This was my solution.
import datetime
from dateutil import parser
your_date_string = 'Mon, 24 Oct 2016 16:49:47 +0000'
your_date = parser.parse(your_date_string)
# your_date is now a datetime.datetime object
your_date_minus_tz = your_date.replace(tzinfo=None)
Now try your put() and you should see 2016-10-24 16:49:47 in the Cloud datastore.

Resources