>> If I want to do:
>>
>>   d = datetime.now()
>>   cursor.execute("INSERT INTO mytable VALUES", somefunc(d))
>>
>> what is `somefunc()`
>
> Well, I think you're looking for to_utimestamp:
>
> http://www.edgewall.org/docs/branches-1.0-stable/html/api/trac_util_datefmt.html#trac.util.datefmt.to_utimestamp

I can't make that work.  I have:

        self.env.log.debug('utimestamp tests')
        ds = '2012-02-01'
        try:
            self.env.log.debug('a. ds:%s' % ds)
            d = datetime(*time.strptime(ds, '%Y-%m-%d')[0:7])
            self.env.log.debug('b. d:%s' % d)
            d = d.replace(hour=0, minute=0, second=0, microsecond=0)
            self.env.log.debug('c. d:%s' % d)
            d = to_datetime(d)
            self.env.log.debug('d. d:%s' % d)
            uts = to_utimestamp(d)
            self.env.log.debug('1. ds:%s -> uts:%s' % (ds, uts))
        except:
            self.env.log.debug('My way failed')

        d = parse_date(ds)
        uts = to_utimestamp(d)
        self.env.log.debug('2. ds:%s -> uts:%s' % (ds, uts))

and I see:

  2012-09-18 13:48:00,442 Trac[tracpm] DEBUG: utimestamp tests
  2012-09-18 13:48:00,442 Trac[tracpm] DEBUG: a. ds:2012-02-01
  2012-09-18 13:48:00,445 Trac[tracpm] DEBUG: b. d:2012-02-01 00:00:00.000002
  2012-09-18 13:48:00,445 Trac[tracpm] DEBUG: c. d:2012-02-01 00:00:00
  2012-09-18 13:48:00,445 Trac[tracpm] DEBUG: d. d:2012-02-01 00:00:00
  2012-09-18 13:48:00,446 Trac[tracpm] DEBUG: My way failed
  2012-09-18 13:48:00,447 Trac[tracpm] DEBUG: 2. ds:2012-02-01 ->
uts:1328072400000000

In 0.11 parse_date() seems to assume ISO format which isn't really an
option for me.  users can configure their own format to match their
data.  So, how can I parse a date string into something that
to_utimestamp() will accept?  (I'm more than willing to accept that my
parsing is awkward.  It's evolved painfully and may be Just Wrong.
Any wisdom on cleaning it up is appreciated.)

                                                   Chris

-- 
You received this message because you are subscribed to the Google Groups "Trac 
Development" group.
To post to this group, send email to trac-dev@googlegroups.com.
To unsubscribe from this group, send email to 
trac-dev+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/trac-dev?hl=en.

Reply via email to