The new year always brings with it a few small things that go bump in the morning. 2008 was no different. Intervals started behaving oddly on New Year’s Eve morning — the default timesheet was a year behind schedule. What happened?
In our PHP code, we are using the ISO-8601 week number of year, as specified on the PHP date function page, but we weren’t using ISO-8601 for the year. The ISO-8601 week number specifies the last monday of a year as the first week of the new year, if that new year begins before thursday. Intervals thought it was the first year of 2007!
In PHP, the fix was as easy as converting all instances of date(’Y') to date(’o'), according to php.net:
ISO-8601 year number. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead. (added in PHP 5.1.0)
That fixed everything on the PHP side of things. But next we had to dig into the SQL queries and get them to use the ISO Year.
Snag.
PostgreSQL 8.2.5 doesn’t support ISO Year in the Extract function. EXTRACT(ISOYEAR, timestamp) is being included in PostgreSQL 8.3, as specified here in the RC1 documentation. But PostgreSQL 8.3 hasn’t been released yet, and we needed to fix things immediately.
Our final PostgreSQL fix was to instead use the TO_CHAR(timestamp, ‘IYYY’) function. It’s not ideal to be using a string formatting function for data comparisons, because it slows down some of the queries. But we had to trade some performance to get things working properly again in the new year. As soon as the PostgreSQL developers release a stable version of 8.3, we’ll change our queries back to using EXTRACT(ISOYEAR, timestamp).
January 10th, 2008 |
by John |
1 Comment
Tags: iso-8601, php, postgresql, sql
Bookmark:
Residental customers of Southern California Edison can exchange one strand of old holiday lights for a box of new, energy efficient LED lights. LEDs use up to 98% less energy and last ten times longer, making them better for the environment and your electricity bills.
The exchange program starts today and runs through December 21st.
LOCATIONS:
- Carpinteria City Hall: 5775 Carpinteria Ave. (805) 684-5405. Mon - Fri, 9am - 5pm
- Goleta City Hall: 130 Cremona, Ste. B. (805) 961-7500. Mon - Thur, 7:30am - 5:30pm Fri, 8am - 1pm
- Santa Barbara: Westside Community Center: 423 W. Victoria St. (805) 963-7567. Mon - Fri, 9am - 5pm
- Franklin Neighborhood Center: 1136 E. Montecito St. (805) 963-7605. Mon - Fri, 9am - 5pm
- Central Library: 40 E. Anapamu St. (805) 564-5601. Mon - Thurs, 10am - 9pm; Fri, Sat, 10am - 5:30pm; Sun, 1 - 5pm
- Community Environmental Council: 26 W. Anapamu St, 2nd Floor. (805) 963-0583 x105. Mon - Fri, 9am - 6pm
December 3rd, 2007 |
by John |
0 Comments
Tags: energy efficient, holidays, LED
Bookmark:
November 24, Funky Bike Ride and Ginger Ninjas Concert, sponsored by Santa Barbara Bici Centro. The free bike ride is at 5:00 PM, starting from La Casa de la Raza, 601 East Montecito Street, Santa Barbara. Then from 6:00-11:00 PM, the “Pleasant Revolution” featuring the Ginger Ninjas, Oso, and Shake your Peace will rock out to a bicycle-powered 800 watt PA system. Intermixed will be fun bike contests, raffles, food and overall merryment. Proceeds will benefit Bici Centro.
November 20th, 2007 |
by John |
0 Comments
Tags: bicycles, santa barbara
Bookmark: