[wp-hackers] Re: Sqlite

Martin Geisler mgeisler at mgeisler.net
Fri Jun 24 22:06:33 GMT 2005


Robert Deaton <false.hopes at gmail.com> writes:

> Storing just a unix timestamp and the offset means more parsing
> every time dates need to be seen, instead of just once and throwing
> it into the database.

No since the code already has to do something along the following when
displaying a date in the blog:

1) Fetch the timestamp from the database, returned as a string.

2) Parse the string to obtain a proper Unix timestamp. This is done by
   mysql2date() in function.php --- note how this is used twice by
   setup_postdata() in the same file, and by get_post_time() in
   template-functions-general.php.

   The mysql2date() function breaks the MySQL timestamp up into parts,
   uses mktime() to generate an Unix timestamp, then does
   internationalization (which involves four preg_replace() calls plus
   some more), and finally it uses date() to convert the Unix
   timestamp back to a string.

The default way to get the time seems to be a call to the_time(). This
will trigger a chain of function calls:

  the_time() -> get_the_time() -> get_post_time() -> mysql2date()

If the_time() is called without a format parameter, then the
bottommost call to mysql2date() will be given a format string of 'U'
asking for a --- surprise, surprise! --- Unix timestamp. This is then
converted into a string in get_the_time(), before being passed on to
the_time().

The more I look at this, the more I think it could be done more
cleanly by just sticking to Unix timestamps all the way through.

I have the feeling that I find such things every time I look at the
code. I think it would be nice with an release which focuses on the
design and code quality. And it would also be a good opportunity to
put some comments into it.

-- 
Martin Geisler                                     GnuPG Key: 0x7E45DD38

PHP EXIF Library      |  PHP Weather             |  PHP Shell
http://pel.sf.net/    |  http://phpweather.net/  |  http://mgeisler.net/
Read/write EXIF data  |  Show current weather    |  A shell in a browser
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 188 bytes
Desc: not available
Url : http://comox.textdrive.com/pipermail/wp-hackers/attachments/20050624/b8ef2e3b/attachment.bin


More information about the wp-hackers mailing list