I have several servers running under centos 6.3 and I faced issue that perl module DateTime treats Europe/Moscow timezone as UTC+3
[ulan#rt-virtual ~]$ perl -MDateTime -e 'print DateTime->now()->set_time_zone("Europe/Moscow"), "\n";'
2013-12-19T11:11:38
but in fact it is UTC+4 and system tools like zdump or date work correctly
[ulan#rt-virtual ~]$ zdump Europe/Moscow
Europe/Moscow Thu Dec 19 12:11:47 2013 MSK
I updated tzdata and DateTime module but it didn't help.
How can I amend this?
Thanks.
Well, DateTime module is doing its magic by following the rules specified in the TimeZone modules specific for each timezone. For Europe/Moscow, the module's is DateTime::TimeZone::Europe::Moscow. The problem is all the files are generated automatically corresponding to the rules existing when a specific version of DateTime module is released.
In this case one very important change - Russia's stopping following DST routines in 2011 - wasn't obviously reflected in that file. So updating - either the whole module or only the relevant TimeZone part - should have fixed the issue.
You can use your systems tzfile(5), using DateTime::TimeZone::Tzfile. Not only does it perform better than DateTime::TimeZone it also removes the need to have redundant data that needs to be in sync.
$tz = DateTime::TimeZone::Tzfile->new('/etc/localtime');
$dt = DateTime->now(time_zone => $tz);
Related
One of our PostgreSQL 11.4 deployments in Congo uses the CAT timezone (Africa/Kigali +02) and one of our function chokes when trying to convert human-input timestamps to actual TIMESTAMPTZ data.
For example:
SELECT '2019-10-17 00:00:00 CAT'::TIMESTAMPTZ;
ERROR: invalid input syntax for type timestamp with time zone: "2019-10-17 00:00:00 CAT"
LINE 2: SELECT '2019-10-17 00:00:00 CAT'::TIMESTAMPTZ
^
SQL state: 22007
Character: 9
But when I try with CEST (Central European, also +02) it works.
SELECT '2019-10-17 00:00:00 CEST'::TIMESTAMPTZ;
"2019-10-17 00:00:00+02"
Incidentally, converting from epoch to CAT also works
select to_timestamp(1571263200);
"2019-10-17 00:00:00+02"
Version:
"PostgreSQL 11.4 (Ubuntu 11.4-1.pgdg18.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0, 64-bit" on Ubuntu 18.04.2 LTS
For whatever reason, 'CAT' is not valid for input by default, presumably someone felt it was ambiguous or something. You could append the line
CAT 7200 # Central Africa Time
to the file "$SHAREDIR/timezonesets/Default" to make this work.
Or you could create a file "$SHAREDIR/timezonesets/Africa" with the contents:
#INCLUDE Default
#OVERRIDE
CAT 7200 # Central Africa Time
And then set the parameter timezone_abbreviations to 'Africa'.
I am not horologist, you might want to research why CAT is missing before blindly adding it. Also, if you go either of the above routes, you should document it clearly someplace. You will need to repeat the steps you took when you upgrade PostgreSQL, or restore or move your database.
Or, you could preprocess your user input to replace 'CAT' with 'Africa/Kigali'.
Incidentally, converting from epoch to CAT also works
select to_timestamp(1571263200);
"2019-10-17 00:00:00+02"
'CAT' does not appear in your example. So it is not clear what this is an example of.
Given a Unixtime such as 1551996855 (Thu, 07 Mar 2019 22:14:15 +0000), how can convert and extract just HH:MM, (22:14)?
you could use date for the conversion and specify +%H:%M as the format:
date -d #$"1551996855" +%H:%M
note: the option to use with date will be different than -d if you are not on a Linux system (which uses date from GNU coreutils).. so YMMV
Could someone please suggest a simple and short approach to convert "Thu Sep 22 3:50 2016" to "2016-09-22" in Solaris, through a shell script?
I do not have GNU date available on Solaris as discussed in below post:
Convert date String to number on Solaris shell script gives No such file or directory
I need to query an sql server db, where date is saved in the format, "2016-09-06", hence I need to convert it
Actually, you do have GNU date available but here is anyway one way to achieve this by scripting:
#!/bin/ksh
a="Thu Sep 22 3:50 2016"
echo $a | nawk '
BEGIN {
m=1
m2m["Jan"]=m++;
m2m["Feb"]=m++;
m2m["Mar"]=m++;
m2m["Apr"]=m++;
m2m["May"]=m++;
m2m["Jun"]=m++;
m2m["Jul"]=m++;
m2m["Aug"]=m++;
m2m["Sep"]=m++;
m2m["Oct"]=m++;
m2m["Nov"]=m++;
m2m["Dec"]=m++;
}
{
printf("%s-%02d-%02d\n",$5,m2m[$2],$3)
}'
output:
2016-09-22
Why not use Oracle's sysdate?
select * from your_table where saved_date >= to_char(sysdate,'yyyy-MM-dd')
I have some files that use the autoproperty $Date of SVN.
When some colleagues in France do a checkout of the repository, the date is in French. When they do the verification of checksum, these files are KO because of this difference of format for the date.
Note: we are using Windows and our client of choice is TortoiseSVN but are open to use command line clients.
Question 1: Is there any way to force the format for the date during the checkout?
We tried the following:
Setting "English" in Tortoise SVN
Setting environment variable LANG to EN_US and doing a checkout with both TortoiseSVN and svn commandline
None of these solutions is working.
Question 2: Would the time zone impact the date in the header as well?
Thanks
NB: This is the header of our source code, for what it matters.
/*==============================================================================================
* FILENAME : Source.h
* VERSION : $Revision: 85911 $
* MODIFICATION DATE : $Date: 2015-06-12 18:26:22 +0800 (Fri, 12 Jun 2015) $
*============================================================================================*/
A1: I don't know, how to manipulate locale-setting in Windows in easy and automated style - inspired by this old answer in Subversion maillist - (better to ask it SU) and can suggest now only dirty hack: import reg-files for FR and EN locales before and after checkout (how to prepare: switch to FR in Control Panel, save Current Control Set part of registry, return to EN, save CCS again, leave in .reg only mutable part), checkout in bat-file only (change locale around checkout)
A2: Sad, but yes
$Date: 2015-06-19 19:45:22 +0500 (Пт, 19 июн 2015) $
inserts not only language-specific date (trailing part), but also TZ of client
1.8.*-specific solution: you can create and use replacement for $Date keyword, which use UTC-time instead of local (as $Id do for time-part now) with %d variable it it
>svn pl -v file.txt
Properties on 'file.txt':
svn:keywords
Author Date Id Revision URL Header IntDate=%d
and IntDate will expand location-independent
$IntDate: 2015-06-19 14:45:22Z $
20110216_00
20110216_01
...
20110216_23
20110217_00
..
and so on
I have tried with
date +'%Y%m%d_%H'
but it never starts with 00-23 format but from 01-24 like format, hence I get hour part always incorrect.
Can anybody suggest, how can I get above o/p
You can do it by manupulating the hour part. Check the snip below.
#/bin/ksh
s=`date +'%Y%m%d_'`
t=` date +'%H'`
let t=$t+1
echo "Required date is " $s$t
It gives
Required date is 20110316_16
I tried it on SunOS 5.10 This works !
date +%Y%m%d_%H
-> 20130912_02
date +'%Y%m%d_%H'
-> 20130912_02
Can you tell us which Solaris are you using ?
uname -a
Cheers !
What revision of Solaris are you using? It is roughly 22:30 locally and I see:
mph#sol11express:~$ date +'%Y%m%d_%H'
20110216_22
mph#sol11express:~$ uname -a
SunOS sol11express 5.11 snv_151a i86pc i386 i86pc Solaris
mph#sol11express:~$ echo $SHELL
/bin/bash
which looks to me like it is using 0-23 for hours.
you can use date -u +'%Y-%m-%d-%H'