Joomla Wrong Time Zone on insert / update DB - joomla3.0

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.

Related

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());

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

angular-strap timepicker saves different time

I am using angular-strap to save date and time for a project, but the time being displayed is not the same time being saved. I can not find any information anywhere on fixing this issue. Has anyone else had this problem?!
Screen shot of data
The value 2015-04-21T09:00:00.000Z means we are talking about the specific point in time described as "The 21. of April in the year 2015, at 9 o'clock UTC". That is, it includes a time zone denoted by the trailing Z. The timepicker you use automatically presents that value to the user, the exact same point in time, but takes the time zone his system is set to into account.
TL;DR The value is correct. Use this value for calculations and store this value in your database. Whenever you present this value to a user, convert it to his time zone.

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();

Changing ADUC Account expiration date via command saves wrong date

I am trying to make a simple batch file to change a user's ADUC expiration to a specified date.
Using the below command the date always appears in ADUC as one day prior to what I set:
net user myname /expires:09/17/13 /domain
In ADUC, the date will be: 09/16/2013. No matter what, the date that appears in ADUC is one day before the day I set.
The documentation I found for this indicates
Note that the account expires at the beginning of the specified date.
So does this mean, If i wanted the account to be expired today, I would send the command for today and ADUC would interpret that as yesterday?
Thanks in advance, I just want to get this right.
As a wild guess, since you're UTC-savvy - is the date UTC date, so 130917T0000Z=130916T1900 local?

Resources