tzinfo

How do I get Rails TimeZone names from obsolete TZInfo identifiers?

倖福魔咒の 提交于 2019-12-07 04:13:31
问题 There is already a question which answers how to convert "America/Los_Angeles" to "Pacific Time (US & Canada)". However I want to convert "US/Pacific" and other obsolete time zones to Rails TimeZone. I am unable to find anything in the library which helps me accomplish this. 回答1: From the Rails ActiveSupport::TimeZone docs: The version of TZInfo bundled with Active Support only includes the definitions necessary to support the zones defined by the TimeZone class. If you need to use zones that

Printing correct time using timezones, Python

ε祈祈猫儿з 提交于 2019-12-05 02:06:25
Extends Ok, we are not having a good day today. When you attach the correct tzinfo object to a datetime instance, and then you strftime() it, it STILL comes out in UTC, seemingly ignoring the beautiful tzinfo object I attached to it. # python 2.5.4 now = datetime.now() print now.strftime( "%a %b %d %X" ) # %X is "locale's appropriate time rep" pst = now.replace( tzinfo=Pacific ) print pst.strftime( "%a %b %d %X" ) We get: Mon Jan 18 17:30:16 Mon Jan 18 17:30:16 I found if I add %z, I can add the difference its supposed to have computed: Mon Jan 18 17:32:38 Mon Jan 18 17:32:38 -0800 It just

attribute 'tzinfo' of 'datetime.datetime' objects is not writable

。_饼干妹妹 提交于 2019-12-03 10:43:04
问题 How do I set the timezone of a datetime instance that just came out of the datastore? When it first comes out it is in UTC. I want to change it to EST. I'm trying, for example: class Book( db.Model ): creationTime = db.DateTimeProperty() When a Book is retrieved, I want to set its tzinfo immediately: book.creationTime.tzinfo = EST Where I use this example for my EST object However I get: attribute 'tzinfo' of 'datetime.datetime' objects is not writable I've seen a number of answers that

attribute 'tzinfo' of 'datetime.datetime' objects is not writable

旧巷老猫 提交于 2019-12-03 01:12:41
How do I set the timezone of a datetime instance that just came out of the datastore? When it first comes out it is in UTC. I want to change it to EST. I'm trying, for example: class Book( db.Model ): creationTime = db.DateTimeProperty() When a Book is retrieved, I want to set its tzinfo immediately: book.creationTime.tzinfo = EST Where I use this example for my EST object However I get: attribute 'tzinfo' of 'datetime.datetime' objects is not writable I've seen a number of answers that recommend pytz and python-dateutil, but I really want an answer to this question. datetime 's objects are

Extract historic leap seconds from tzdata

无人久伴 提交于 2019-11-29 01:16:50
Is there a way to extract the moment of historic leap seconds from the time-zone database that is distributed on most linux distributions? I am looking for a solution in python, but anything that works on the command line would be fine too. My use case is to convert between gps-time (which is basically the number of seconds since the first GPS-satellite was switched on in 1980) and UTC or local time. UTC is adjusted for leap-seconds every now and then, while gps-time increases linearly. This is equivalent to converting between UTC and TAI . TAI also ignores leap-seconds, so TAI and gps-time

Python timezone '%z' directive for datetime.strptime() not available

两盒软妹~` 提交于 2019-11-27 13:16:21
Using '%z' pattern of datetime.strptime() I have a string text that represent a date and I'm perfectly able to parse it and transform it into a clean datetime object: date = "[24/Aug/2014:17:57:26" dt = datetime.strptime(date, "[%d/%b/%Y:%H:%M:%S") Except that I can't catch the entire date string with the timezone using the %z pattern as specified here date_tz = 24/Aug/2014:17:57:26 +0200 dt = datetime.strptime(date, "[%d/%b/%Y:%H:%M:%S %z]") >>> ValueError: 'z' is a bad directive in format '[%d/%b/%Y:%H:%M:%S %z]' Because as this bug report says strftime() is implemented per platform I

Why doesn't pytz localize() produce a datetime object with tzinfo matching the tz object that localized it?

橙三吉。 提交于 2019-11-27 06:03:50
问题 Is there anyone who can help me understand what's going on here? import pytz from datetime import datetime tz = pytz.timezone('Europe/Berlin') print repr(tz) # <DstTzInfo 'Europe/Berlin' LMT+0:53:00 STD> dt = datetime(2011, 1, 3, 18, 40) result = tz.localize(dt) print repr(result.tzinfo) # <DstTzInfo 'Europe/Berlin' CET+1:00:00 STD> assert result.tzinfo == tz, "Why aren't these the same timezone?" My understanding was that the localize() method on a pytz timezone object would take a naive

TZInfo::DataSourceNotFound error starting Rails v4.1.0 server on Windows

*爱你&永不变心* 提交于 2019-11-26 17:25:39
I have created a new application using Ruby on Rails v4.1.0. When attempting to start a server or console on Windows, I am encountering the following error: $ rails server Booting WEBrick Rails 4.1.0 application starting in development on .... Exiting c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/tzinfo-1.1.0/lib/tzinfo/data_source.rb:199: in `rescue in create_default_data_source': No timezone data source could be found. To resolve this, either install TZInfo::Data (e.g. by running `gem install tzinfo-data`) or specify a zoneinfo directory using `TZInfo::DataSource.set(:zoneinfo,

Python timezone '%z' directive for datetime.strptime() not available

五迷三道 提交于 2019-11-26 16:16:25
问题 Using '%z' pattern of datetime.strptime() I have a string text that represent a date and I'm perfectly able to parse it and transform it into a clean datetime object: date = "[24/Aug/2014:17:57:26" dt = datetime.strptime(date, "[%d/%b/%Y:%H:%M:%S") Except that I can't catch the entire date string with the timezone using the %z pattern as specified here date_tz = 24/Aug/2014:17:57:26 +0200 dt = datetime.strptime(date, "[%d/%b/%Y:%H:%M:%S %z]") >>> ValueError: 'z' is a bad directive in format '