Skip to content

Commit 80e76c8

Browse files
author
Marcin Przepiorowski
committed
Merge branch 'timezonefix' into develop
2 parents 78900e4 + b5afd21 commit 80e76c8

File tree

2 files changed

+39
-27
lines changed

2 files changed

+39
-27
lines changed

lib/Snapshot_obj.pm

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -329,27 +329,58 @@ sub getSnapshotTime {
329329
# if timezone defined as GMT+/-offset return undef
330330
# parameters:
331331
# - timezone
332-
# Return 0 if OK
332+
# Return timezone of OK or N/A if timezone is not recognized by perl
333333

334334
sub checkTZ {
335335
my $self = shift;
336336
my $timezone = shift;
337337
logger($self->{_debug}, "Entering Snapshot_obj::checkTZ",1);
338338

339+
# fixes for timezones supported by Delphix but not recognized by Perl
340+
if ($timezone eq 'Etc/Zulu') {
341+
$timezone = 'UTC';
342+
}
343+
if ($timezone eq 'Zulu') {
344+
$timezone = 'UTC';
345+
}
346+
if ($timezone eq 'Etc/Universal') {
347+
$timezone = 'UTC';
348+
}
349+
if ($timezone eq 'Universal') {
350+
$timezone = 'UTC';
351+
}
352+
if ($timezone eq 'Etc/Greenwich') {
353+
$timezone = 'GMT';
354+
}
355+
if ($timezone eq 'Greenwich') {
356+
$timezone = 'GMT';
357+
}
358+
if ($timezone eq 'GMT0') {
359+
$timezone = 'GMT';
360+
}
361+
if ($timezone eq 'Etc/GMT0') {
362+
$timezone = 'GMT';
363+
}
364+
if ($timezone eq 'Etc/GMT-0') {
365+
$timezone = 'GMT';
366+
}
367+
if ($timezone eq 'Etc/GMT+0') {
368+
$timezone = 'GMT';
369+
}
339370

340371
my $checktime = time();
341372
my $dt = ParseDate($checktime);
342373
my $tz = new Date::Manip::TZ;
343374
my ($err,$date,$offset,$isdst,$abbrev) = $tz->convert_from_gmt($dt, $timezone);
344375

345-
if (defined($abbrev)) {
376+
if (!$err) {
346377
logger($self->{_debug}, "checkTZ abbrev-" . $abbrev ,1);
347378
} else {
348379
logger($self->{_debug}, "checkTZ abbrev-undefined" ,1);
380+
$timezone = 'N/A';
349381
}
350382

351-
return $err;
352-
383+
return $timezone;
353384
}
354385

355386
# Procedure getSnapshotTimeZone
@@ -366,30 +397,11 @@ sub getSnapshotTimeZone {
366397
chomp($ts);
367398
my @temp = split(',',$ts);
368399
my $ret = $temp[0];
369-
if ($ret eq 'Etc/Zulu') {
370-
$ret = 'Etc/GMT';
371-
}
372-
373-
if ($ret eq 'Greenwich') {
374-
$ret = 'GMT+00:00';
375-
}
376-
377-
my $tz = new Date::Manip::TZ;
378-
379-
my @zone = ('Etc/GMT');
380-
my ($err,$val) = $tz->define_offset('+0000', @zone);
381-
382-
logger($self->{debug}, "Setting GMT timezone err-" . $err );
383-
384-
@zone = ('Asia/Singapore');
385-
($err,$val) = $tz->define_offset('+0800', @zone);
386-
387-
logger($self->{debug}, "Setting SGT timezone err-" . $err );
388400

389401
if (! ($ret =~ /[a-zA-Z]{3}.\d\d:\d\d/ )) {
390-
if ($self->checkTZ($ret)) {
391-
$ret = 'N/A';
392-
}
402+
# if timezone is not GMT+-00:00 format
403+
# check if this format can be recognized and amended by checkTZ function
404+
$ret = $self->checkTZ($ret);
393405
}
394406

395407
return $ret;

test/test_snapshot/snapshot.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ local,Sources,Oracle dsource,\@2017-06-06T12:00:04.096Z,2017-06-06 07:59:59 EDT,
4646
local,Sources,Oracle dsource,\@2017-06-06T12:18:28.754Z,2017-06-06 08:18:29 EDT,2017-06-06 08:54:00 EDT
4747
local,Sources,Oracle dsource,\@2017-06-06T12:54:00.857Z,2017-06-06 08:54:00 EDT,2017-06-06 08:58:12 EDT
4848
local,Sources,PDB,\@2017-05-22T15:17:45.106Z,2017-05-22 11:17:44 EDT,2017-05-22 11:17:44 EDT
49-
local,Sources,racdba,\@2016-12-23T13:24:08.203Z,2016-12-23 13:23:44 GMT,2016-12-23 13:23:56 GMT
49+
local,Sources,racdba,\@2016-12-23T13:24:08.203Z,2016-12-23 13:23:44 UTC,2016-12-23 13:23:56 UTC
5050
local,Sources,singpdb,\@2017-03-17T12:23:34.209Z,2017-03-17 08:23:25 EDT,2017-03-17 08:24:01 EDT
5151
local,Sources,singpdb,\@2017-04-04T14:11:13.784Z,2017-04-04 10:11:12 EDT,2017-05-22 11:14:24 EDT
5252
local,Sources,singpdb,\@2017-05-22T15:14:25.413Z,2017-05-22 11:14:24 EDT,2017-05-22 11:17:44 EDT

0 commit comments

Comments
 (0)