A timezone with a fixed offset and no daylight savings adjustment. http://docs.python.org/library/datetime.html#datetime.tzinfo
| 216 | |
| 217 | |
| 218 | class FixedOffsetTimezone(datetime.tzinfo): |
| 219 | """A timezone with a fixed offset and no daylight savings adjustment. |
| 220 | |
| 221 | http://docs.python.org/library/datetime.html#datetime.tzinfo |
| 222 | |
| 223 | """ |
| 224 | |
| 225 | def __init__(self, offset): |
| 226 | """Constructor. |
| 227 | |
| 228 | @ivar offset: The fixed offset of the timezone. |
| 229 | @type offset: B{datetime}.I{timedelta} |
| 230 | |
| 231 | """ |
| 232 | self.__offset = offset |
| 233 | |
| 234 | def utcoffset(self, dt): |
| 235 | """ |
| 236 | http://docs.python.org/library/datetime.html#datetime.tzinfo.utcoffset |
| 237 | |
| 238 | """ |
| 239 | return self.__offset |
| 240 | |
| 241 | def tzname(self, dt): |
| 242 | """ |
| 243 | http://docs.python.org/library/datetime.html#datetime.tzinfo.tzname |
| 244 | |
| 245 | """ |
| 246 | sign = '+' |
| 247 | if self.__offset < datetime.timedelta(): |
| 248 | sign = '-' |
| 249 | |
| 250 | # total_seconds was introduced in Python 2.7 |
| 251 | if hasattr(self.__offset, 'total_seconds'): |
| 252 | total_seconds = self.__offset.total_seconds() |
| 253 | else: |
| 254 | total_seconds = (self.__offset.days * 24 * 60 * 60) + \ |
| 255 | (self.__offset.seconds) + \ |
| 256 | (self.__offset.microseconds / 1000000.0) |
| 257 | |
| 258 | hours = total_seconds // (60 * 60) |
| 259 | total_seconds -= hours * 60 * 60 |
| 260 | |
| 261 | minutes = total_seconds // 60 |
| 262 | total_seconds -= minutes * 60 |
| 263 | |
| 264 | seconds = total_seconds // 1 |
| 265 | total_seconds -= seconds |
| 266 | |
| 267 | if seconds: |
| 268 | return '%s%02d:%02d:%02d' % (sign, hours, minutes, seconds) |
| 269 | else: |
| 270 | return '%s%02d:%02d' % (sign, hours, minutes) |
| 271 | |
| 272 | def dst(self, dt): |
| 273 | """ |
| 274 | http://docs.python.org/library/datetime.html#datetime.tzinfo.dst |
| 275 |