Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the DateTime CPAN distribution.

Report information
The Basics
Id: 105187
Status: rejected
Priority: 0/
Queue: DateTime

People
Owner: Nobody in particular
Requestors: NJFRANCK [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: method from_epoch reloads time_zone
The method from_epoch creates a DateTime::TimeZone object of type 'UTC' my $self = $class->_new( %p, %args, time_zone => 'UTC' ); and then sets the new time_zone provided if needed: $self->set_time_zone( $p{time_zone} ) if exists $p{time_zone}; In case you provide a time_zone, this leads to the creation of two objects, while there is no need. Could this be better? my $self = $class->_new( %p, %args, time_zone => exists($p{time_zone}) ? $p{time_zone} : 'UTC' ); And then delete the line that sets the time_zone? Or has this a special reason? Thanks in advance! greetings
On Fri Jun 12 05:55:55 2015, NJFRANCK wrote: Show quoted text
> The method from_epoch creates a DateTime::TimeZone object > of type 'UTC' > > my $self = $class->_new( %p, %args, time_zone => 'UTC' ); > > and then sets the new time_zone provided > if needed: > > $self->set_time_zone( $p{time_zone} ) if exists $p{time_zone}; > > In case you provide a time_zone, this leads to the creation of two > objects, while there is no need. > > Could this be better? > > my $self = $class->_new( %p, %args, time_zone => exists($p{time_zone}) > ? $p{time_zone} : 'UTC' ); > > And then delete the line that sets the time_zone? > > Or has this a special reason?
This wouldn't work. The epoch is a count of seconds since 1970-01-01T00:00:00 _in UTC_, so we need to create the new object in UTC, then set the time zone. Also, avoiding loading the UTC zone is probably a pointless micro-optimization, since the UTC zone code is very small.