From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18323 invoked by alias); 14 Dec 2007 21:26:12 -0000 Received: (qmail 18314 invoked by uid 22791); 14 Dec 2007 21:26:11 -0000 X-Spam-Check-By: sourceware.org Received: from mxh.seznam.cz (HELO mxl.seznam.cz) (77.75.72.26) by sourceware.org (qpsmtpd/0.31) with SMTP; Fri, 14 Dec 2007 21:26:03 +0000 Received: (qmail 22026 invoked by uid 0); 14 Dec 2007 21:26:00 -0000 To: cygwin@cygwin.com Date: Fri, 14 Dec 2007 21:26:00 -0000 From: roman.vasicek@email.cz Received: from [165.72.200.11] by email.seznam.cz with HTTP for roman.vasicek@email.cz; Fri, 14 Dec 2007 22:07:56 +0100 (CET) Subject: =?us-ascii?Q?Timezone=20manipulation=20within=20Perl=20script?= Mime-Version: 1.0 Message-Id: <9761.12995-16991-2031106093-1197667559@email.cz> Content-Type: multipart/mixed; boundary="MessagePart:1597453076.0-16991-731278637-1197667559" X-Abuse: helpdesk@seznam.cz X-Seznam-User: roman.vasicek@email.cz X-IsSubscribed: yes Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com X-SW-Source: 2007-12/txt/msg00359.txt.bz2 --MessagePart:1597453076.0-16991-731278637-1197667559 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii" Content-length: 1363 Hi all, I want to ask you how convert time between different timezones in perl script running under cygwin. I have an application which store datetime information in Zulu/GMT. I need to provide date in user timezone. How to do the correct conversion? I want to be able to offer Timezone info like 'Europe/Prague'. Following code snippet will provide correct output when running under Active state Perl (time will differ 1 or 2 hours depending on input date), but when running under cygwin perl no conversion will be done. Can anyone help me? $ENV{TZ} = 'Zulu'; POSIX::tzset(); $time = timegm($second, $minute, $hour, $day, $month, $year); $ENV{TZ} = 'Europe/Prague'; POSIX::tzset(); ($second, $minute, $hour, $day, $month, $year) = POSIX::localtime($time); Attached program will produce under ActiveState PERL Winter (delta should be +1 h) ZULU : 2007-12-13 11:47:02 Zulu LOCAL: 2007-12-13 12:47:02 Europe/Prague Summer (delta should be +2 h) ZULU : 2007-06-13 11:47:02 Zulu LOCAL: 2007-06-13 13:47:02 Europe/Prague and under CygWin PERL output will be Winter (delta should be +1 h) ZULU : 2007-12-13 11:47:02 Zulu LOCAL: 2007-12-13 11:47:02 Europe/Prague Summer (delta should be +2 h) ZULU : 2007-06-13 11:47:02 Zulu LOCAL: 2007-06-13 11:47:02 Europe/Prague Best Regards, Roman --MessagePart:1597453076.0-16991-731278637-1197667559 Content-Transfer-Encoding: base64 Content-Type: application/x-perl; name="=?us-ascii?Q?test=2D1=2Epl?="; charset="us-ascii" Content-Disposition: attachment; filename="=?us-ascii?Q?test=2D1=2Epl?=" Content-length: 4218 IyEvdXNyL2Jpbi9wZXJsIC13CiMKCnVzZSBzdHJpY3Q7CnVzZSBQT1NJWCAg IHF3KCk7CnVzZSBUaW1lOjpMb2NhbDsKCm15ICR6dWx1OwpteSAkbG9jYWw7 Cm15ICR6b25lOwoKc3ViIGZvcm1hdF9kYXRldGltZSB7CiAgICBteSAkZGF0 ZXRpbWUgICAgPSBzaGlmdDsgICAgICAgICAgICAjIFlZWVlNTUREaGg6bW06 c3MgLSBEYXRlOjpNYW5pcCBjb21wYXRpYmxlIGZvcm1hdAogICAgbXkgJHRp bWV6b25lICAgID0gc2hpZnQgfHwgJ0dNVCc7ICAgIyBleHBlY3QgR01UIGJ5 IGRlZmF1bHQKICAgIG15ICRodG1sX3JlcSAgICA9IHNoaWZ0IHx8IDA7ICAg ICAgICMgb3V0cHV0IGZvciBIVE1MIHBhZ2U/ICcgJyA9PiAnJm5ic3A7Jwog ICAgbXkgJHJlc3VsdCAgICAgID0gJyc7CgogICAgaWYgKCRkYXRldGltZSA9 fiAvXihcZHs0fSkoXGR7Mn0pKFxkezJ9KShcZHsyfSk6KFxkezJ9KTooXGR7 Mn0pJC8pIHsKICAgICAgICBteSAkeWVhciAgICA9ICQxOwogICAgICAgIG15 ICRtb250aCAgID0gJDI7CiAgICAgICAgbXkgJGRheSAgICAgPSAkMzsKICAg ICAgICBteSAkaG91ciAgICA9ICQ0OwogICAgICAgIG15ICRtaW51dGUgID0g JDU7CiAgICAgICAgbXkgJHNlY29uZCAgPSAkNjsKCiAgICAgICAgJHJlc3Vs dCA9IHNwcmludGYoIiVkLSUwMmQtJTAyZCAlMDJkOiUwMmQ6JTAyZCAlcyIs ICQxLCAkMiwgJDMsICQ0LCAkNSwgJDYsICR0aW1lem9uZSk7CiAgICAgICAg JHJlc3VsdCA9fiBzLyAvJm5ic3A7L2cgaWYgKCRodG1sX3JlcSk7CiAgICB9 CgogICAgcmV0dXJuICRyZXN1bHQ7Cn0KCnN1YiBpc196dWx1IHsKICAgIG15 ICR6dWx1ICAgID0gc2hpZnQ7CiAgICBteSAkcmVzdWx0ICA9IDA7CgogICAg aWYgKCR6dWx1ID1+IC9eKFxkezE0fSlaJC8pIHsKICAgICAgICAkcmVzdWx0 ID0gMQogICAgfQoKICAgIHJldHVybiAkcmVzdWx0Owp9CgpzdWIgenVsdV90 b19kYXRldGltZSB7CiAgICBteSAkenVsdSAgICA9IHNoaWZ0OwogICAgbXkg JHJlc3VsdCAgPSAnJzsKCiAgICBpZiAoaXNfenVsdSgkenVsdSkpIHsKICAg ICAgICAkcmVzdWx0ID0gam9pbignOicsICR6dWx1ID1+IC9eKFxkezEwfSko XGR7Mn0pKFxkezJ9KS8pOwogICAgfQoKICAgIHJldHVybiAkcmVzdWx0Owp9 CgpzdWIgenVsdV90b19sb2NhbF9kYXRldGltZSB7CiAgICBteSAkenVsdSAg ICAgICAgPSBzaGlmdDsKICAgIG15ICR0aW1lX3pvbmUgICA9IHNoaWZ0IHx8 ICdFdXJvcGUvUHJhZ3VlJzsKICAgIG15ICRyZXN1bHQgICAgICA9ICcnOwog ICAgbXkgJHRpbWU7CiAgICBteSAkeWVhcjsKICAgIG15ICRtb250aDsKICAg IG15ICRkYXk7CiAgICBteSAkaG91cjsKICAgIG15ICRtaW51dGU7CiAgICBt eSAkc2Vjb25kOwoKICAgIGlmIChpc196dWx1KCR6dWx1KSkgewogICAgICAg ICgkeWVhciwgJG1vbnRoLCAkZGF5LCAkaG91ciwgJG1pbnV0ZSwgJHNlY29u ZCkgID0gJHp1bHUgPX4gL14oXGQrKShcZHsyfSkoXGR7Mn0pKFxkezJ9KShc ZHsyfSkoXGR7Mn0pLzsKCiAgICAgICAgIyBmaXggb2Zmc2V0CiAgICAgICAg JG1vbnRoLS07CiAgICAgICAgJHllYXIgICAtPSAxOTAwOwoKICAgICAgICBt eSAkYWxyZWFkeSA9IDA7CiAgICAgICAgbXkgJG9yaWdpbmFsX3RpbWVfem9u ZTsKCiAgICAgICAgIyBzYXZlIGVudmlyb25tZW50IHNldHRpbmdzCiAgICAg ICAgaWYgKGV4aXN0cyAkRU5We1RafSkgewogICAgICAgICAgICAkYWxyZWFk eSAgICAgICAgICAgID0gMTsKICAgICAgICAgICAgJG9yaWdpbmFsX3RpbWVf em9uZSA9ICRFTlZ7VFp9OwogICAgICAgIH0KCiAgICAgICAgIyBkbyBkYXRl dGltZSBjb252ZXJzaW9uIGRlcGVuZGludCB0byB0YXJnZXQgdGltZXpvbmUK ICAgICAgICAkRU5We1RafSAgICA9ICdadWx1JzsKICAgICAgICBQT1NJWDo6 dHpzZXQoKTsKICAgICAgICAkdGltZSAgICAgICA9IHRpbWVnbSgkc2Vjb25k LCAkbWludXRlLCAkaG91ciwgJGRheSwgJG1vbnRoLCAkeWVhcik7CiAgICAg ICAgJEVOVntUWn0gICAgPSAkdGltZV96b25lOwogICAgICAgIFBPU0lYOjp0 enNldCgpOwogICAgICAgICgkc2Vjb25kLCAkbWludXRlLCAkaG91ciwgJGRh eSwgJG1vbnRoLCAkeWVhcikgICA9IFBPU0lYOjpsb2NhbHRpbWUoJHRpbWUp OwoKICAgICAgICAjIGZpeCBvZmZzZX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VsZCBiZSArMiBo KSIsICJcbiI7CnByaW50ICJaVUxVIDogIiwgZm9ybWF0X2RhdGV0aW1lKHp1 bHVfdG9fZGF0ZXRpbWUoJHp1bHUpLCAnWnVsdScpLCAiXG4iOwpwcmludCAi TE9DQUw6ICIsIGZvcm1hdF9kYXRldGltZSgkbG9jYWwsICR6b25lKSwgIlxu IjsKCg== --MessagePart:1597453076.0-16991-731278637-1197667559 Content-Type: text/plain; charset=us-ascii Content-length: 218 -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/ --MessagePart:1597453076.0-16991-731278637-1197667559--