developer.jelix.org is not used any more and exists only for history. Post new tickets on the Github account.
developer.jelix.org n'est plus utilisée, et existe uniquement pour son historique. Postez les nouveaux tickets sur le compte github.

Opened 7 years ago

Closed 7 years ago

#1466 closed bug (fixed)

jDateTime initialization with an iso8601 string is wrong

Reported by: lionelt Owned by:
Priority: normal Milestone: Jelix 1.2.8
Component: jelix:utils Version: 1.3.1
Severity: normal Keywords:
Cc: Blocked By:
Blocking: Documentation needed: no
Hosting Provider: Php version:

Description

When initialized with an iso8601 string including a timezone indicator, jDateTime does not handle correctly this timezone indicator.

Let's talk about april 15th 2012 noon in Paris (summer time +0200 offset) : 2012-04-15T12:00:00+0200

This date is equivalent to the UTC one : 2012-04-15T10:00:00+0000 = 2012-04-15T10:00:00Z

When initializing jDateTime with such a date, the timezone offset is added to the date when positive, substracted when negative. The contrary should be done.

2012-04-15T12:00:00+0200 is saved as :

year => 2012
month => 4
day => 15
hour => 14
minute => 0
minute => 0

If this jDateTime is exported as an iso8601 string (with the current implementation of jDateTime) it would display : 2012-04-15T14:00:00Z (jDateTime always output iso8601 dates with the Z timezone indicator, which means UTC)

This date is not equal to the date we entered which was (with the Z indicator) : 2012-04-15T10:00:00Z

Therefore I think the timezone should be substracted when positive and added when negative. This inversion is here in the code :

--- before	2012-04-22 12:40:33.000000000 +0200
+++ after	2012-04-22 12:41:13.000000000 +0200
@@ -317,9 +317,9 @@
                     if($match[8] != 'Z'){
                         $d = new jDuration(array('hour'=>$match[10],'minute'=>$match[11]));
                         if($match[9] == '+')
-                            $this->add($d);
-                        else
                             $this->sub($d);
+                        else
+                            $this->add($d);
                     }
                }
                break;

Change History (4)

comment:1 Changed 7 years ago by foxmask

Can you attach the patch , or even better, make a pull request of your patch on github ?

comment:2 Changed 7 years ago by laurentj

  • Milestone set to Jelix 1.2.8
  • Status changed from new to confirmed

We MUST add tests to verify such bugs.

comment:3 Changed 7 years ago by laurentj

  • Component changed from jelix to jelix:utils

comment:4 Changed 7 years ago by laurentj

  • Resolution set to fixed
  • Status changed from confirmed to closed
Note: See TracTickets for help on using tickets.