Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#10001 closed defect (worksforme)

DateTime problem when change timezone

Reported by: marianoso@… Owned by: osimons
Priority: normal Component: XmlRpcPlugin
Severity: normal Keywords:
Cc: Olemis Lang Trac Release: 0.11


We have the problem, that when change the timezone of the server, the change do not affect the ticket creation time (it is 3 hors later), but works fine in the ticket.update function. so I had put this line in the

change: add this line after the if # custom create timestamp?:

when = when or to_datetime(None, utc)

So the funcion nos looks like this:

    def create(self, req, summary, description, attributes={}, notify=False, when=None):
        """ Create a new ticket, returning the ticket ID.
        Overriding 'when' requires admin permission. """
        t = model.Ticket(self.env)
        t['summary'] = summary
        t['description'] = description
        t['reporter'] = req.authname
        for k, v in attributes.iteritems():
            t[k] = v
        t['status'] = 'new'
        t['resolution'] = ''
        # custom create timestamp?
        if when and not 'TICKET_ADMIN' in req.perm:
            self.log.warn("RPC ticket.create: %r not allowed to create with "
                    "non-current timestamp (%r)", req.authname, when)
            when = None

        when = when or to_datetime(None, utc)

        if notify:
                tn = TicketNotifyEmail(self.env)
                tn.notify(t, newticket=True)
            except Exception, e:
                self.log.exception("Failure sending notification on creation "
                                   "of ticket #%s: %s" % (, e))

The code is here: /usr/local/lib/python2.6/dist-packages/TracXMLRPC-1.1.2_r10706-py2.6.egg/tracrpc

Attachments (0)

Change History (6)

comment:1 Changed 6 years ago by osimons

I'm not sure I understand your problem. Both for Trac 0.11 and 0.12, trac.ticket.model.insert() contains this code:

# Add a timestamp
if when is None:
    when =

... which should set when to the same current UTC timestamp as your code if when is None.

Are you perhaps passing a wrong empty value? Note that None != 0 for instance, so what does the log say about the incoming values received by RPC through your code? Turn on debug logging to see all the data.

comment:2 Changed 6 years ago by anonymous

Hi, Thanks! Well...

Im using this version of tracxmlrpc:TracXMLRPC-1.1.2_r10706-py2.6.egg

The code for using the function is like this:

#!/usr/bin/env python
import xmlrpclib
import sys
import datetime
import time
import struct

server = xmlrpclib.ServerProxy("https://user:pass@server/login/rpc") 
#int ticket.create(string summary, string description, struct attributes={}, boolean notify=False, dateTime.iso8601 when=None)

print server.ticket.create(resumen,descripcion,atributos,True,

Using as appear in the code gives me a difference of 3 hours with the current timestamp.

If i call the "server.ticket.create" in this way:


The time of the creation is 42 years in the past.

Note: When i added comments to the recent create tickets, the timestams of the "added comments" is OK. But when i create the ticket the time is NOT OK.

comment:3 Changed 6 years ago by osimons

You are aware that will use the client time settings for current time, but all timestamp communication must use UTC timestamps to avoid ambiguity.

The correct code would be for you to call it like this instead:


Obviously, if 'now' is the timestamp you want you may as well leave it out and have the server make it correctly instead.

On my CET w/summer time client this is what I get:

>>> from datetime import datetime
>>>,, datetime.utcnow()
datetime.datetime(2012, 5, 2, 22, 5, 18, 575794),
datetime.datetime(2012, 5, 2, 22, 5, 18, 575806),
datetime.datetime(2012, 5, 2, 20, 5, 18, 575807)

comment:4 Changed 6 years ago by osimon

Oh, and obviously seeing you are using XML-RPC protocol, you must remember to use the correct XML format. The correct calling code is then actually:

import xmlrpclib
import datetime
when = xmlrpclib.DateTime(datetime.datetime.utcnow())

Have a look at the functional unittests if you need pointers to how tickets are created and updated, how attachments are handled and so on. There is even a separate test called test_create_at_time()for you to look at... :-)

See source:/xmlrpcplugin/trunk/tracrpc/tests/

comment:5 Changed 6 years ago by osimons

Resolution: worksforme
Status: newclosed

Let's close this. I'm quite sure it works correctly when used correctly.

comment:6 Changed 6 years ago by anonymous

Dear osimons: I changed my code with your suggestions and now the code works! :) . The problem was in my code.

Thank you !! Mariano

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain osimons.
The resolution will be deleted.

Add Comment

E-mail address and name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.