Re: Guessing the date style from the timezone for postgresql postinst
Carey Evans wrote:
>"Oliver Elphick" <olly@lfix.co.uk> writes:
>
>> If you have a recent potato system, with timezone files in
>> /usr/share/zoneinfo, could you please run the script and let me know if
>> it gives WRONG results for you. If it does, please tell me your timezone
>> and offset (date '+%Z %z') and what the date style ought to be. If you
>> can suggest a change to the script that will get it right without breaking
>
>> results for other countries, that will be even better!
>
>Given my normal environment, the script doesn't work out which country
>I'm in:
>
Here's a revised version of the script taking into account all comments
so far.
Raul Miller wrote:
>On Fri, Sep 17, 1999 at 11:20:13PM -0400, Joe Drew wrote:
>> It's my personal preference that ISO standard be used unless otherwise
>> told - but that's me.
>
>I tend to agree. It would just be so simple to have the default be ISO.
>
>As ISO is very unambiguous, I don't think it would cause problems, either.
>Then again, maybe someone else knows of problems it would create...
I agree that it would make things simpler, but I doubt that most people
would actually prefer it, because it isn't the way we naturally think of
dates.
Joe Drew wrote:
>Canada is a very multicultural country, and it really is every
>person for him- or herself.
That being so, it definitely makes sense to use ISO for Canada.
Of course, the installer can override the guess, but I like to guess as
close as possible.
#! /bin/sh
# Guess the postgresql datestyle to use for a given timezone (from glibc)
# make sure we can find the timezone database
ZONEDIR=`ls -l /etc/localtime | awk '{print $NF}' | cut -d/ -f1-4`
if [ ! -d "$ZONEDIR" ]
then
echo "Sorry, I don't know where to find the timezone files; this
script expected to find them in $ZONEDIR"
exit 1
fi
# make sure TZ is set and exported
if [ -z "$TZ" ]
then
TZ=`ls -l /etc/localtime | awk '{print $NF}' | cut -d/ -f5-10`
fi
export TZ
# find the timezone offset from UTC
tzno=`date '+%z'`
# Find the name of the zone - strip off unwanted header directories
x=`echo $TZ | cut -d/ -f1`
case $x in ( SystemV | posix | right )
x=`echo $TZ | cut -d/ -f2-4`
;;
* )
x=$TZ
;;
esac
# What country does this zone belong to (if undefined, set it to __)
tzcountry=`grep $x $ZONEDIR/zone.tab | head -1 | cut -c1-2`
if [ -z "$tzcountry" ]
then
tzcountry=__
fi
# Guess the timezone
case $tzcountry in ( US )
# US date format
GuessDateStyle=US
;;
AR )
# Argentina
GuessDateStyle=SQL
;;
CA )
# Canada has no standard
GuessDateStyle=ISO
;;
DE )
# Germany has a style to itself
GuessDateStyle=GERMAN
;;
__ )
# No country, so see if the zone is a region or country name
x=$TZ
while echo $x | grep -q /
do
y=`dirname $x`
case $y in ( SystemV | posix | right )
y=`basename $x`
;;
esac
x=$y
done
case $x in ( Africa | Canada | Indian | Mexico | America | Chile | GB | Iran | Mideast | Antarctica | Cuba | Israel | NZ | Singapore | Arctic | Jamaica | Asia | Japan | Navajo | Turkey | Atlantic | Kwajalein | Australia | Egypt | Libya | US | Brazil | Eire | Pacific | Hongkong | Poland | Europe | Iceland | Portugal)
# try to guess the zone from the UTC offset and the
# zone abbreviation
if [ -z "$GuessDateStyle" ]
then
GuessDateStyle=EURO
if [ "$LANG" = de_DE ]
then
GuessDateStyle=GERMAN
elif [ $tzno -le -200 -a $tzno -gt -1200 ]
then
tzn=`date '+%Z'`
case $tzn in ( ADT | AST | AKDT | AKST | CDT | CST | EDT | EST | HADT | HAST | HST | MDT | MST | NDT | PDT | PST)
GuessDateStyle=US
;;
esac
fi
fi
;;
* )
# Not a country or region so use ISO
GuessDateStyle=ISO
;;
esac
;;
* )
# The rest of the world uses normal European format
GuessDateStyle=EURO
;;
esac
echo $tzcountry $GuessDateStyle
Vote against SPAM: http://www.politik-digital.de/spam/
========================================
Oliver Elphick Oliver.Elphick@lfix.co.uk
Isle of Wight http://www.lfix.co.uk/oliver
PGP key from public servers; key ID 32B8FAA1
========================================
"Give, and it shall be given unto you; good measure,
pressed down, and shaken together, and running over,
shall men pour into your lap. For by your standard of
measure it will be measured to in return."
Luke 6:38
Reply to: