Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Timezone aware version - use this instead' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Timezone aware version - use this instead
Authored by: tancurl on Mar 15, '07 01:35:04PM
Here is a timezone aware version of the script you should use instead.

It shifts all the timezones of birthdays to your current timezone, meaning the day displays the same no matter what timezone you are in.

This means that if you enter a birthday as 1st Jan, then no matter what timezone you move to you can ensure it will still display at 1st Jan buy running the script

Also, if you entered peoples birthdays while you were in different timezones you can find that certain timezone changes will move only some birthdays. Luckly this script will fix that problem too.


#!/usr/bin/env python2.3

import AddressBook
import sys
import Foundation

book = AddressBook.ABAddressBook.sharedAddressBook()
addressBookPeople = book.people()

birthdaysChanged = 0;

currentTimeZone = Foundation.NSTimeZone.systemTimeZone()

for person in addressBookPeople:
	birthday = person.valueForProperty_('Birthday')
	if (type(birthday) == AddressBook.NSCalendarDate):
		"""They have a birthday"""
		
		newBirthday = Foundation.NSCalendarDate.alloc().initWithYear_month_day_hour_minute_second_timeZone_(
			birthday.yearOfCommonEra(), 
			birthday.monthOfYear(), 
			birthday.dayOfMonth(), 
			birthday.hourOfDay(), 
			birthday.minuteOfHour(), 
			birthday.secondOfMinute(), 
			currentTimeZone)

		person.setValue_forProperty_(newBirthday,"Birthday")
		birthdaysChanged = birthdaysChanged + 1;

if (birthdaysChanged > 0):
	AddressBook.ABAddressBook.sharedAddressBook().save()
	print str(birthdaysChanged) + " birthdays changed and saved."
else:
	print "No birthdays changed!"


[ Reply to This | # ]
Timezone aware version - use this instead
Authored by: bex on Apr 20, '10 06:07:30PM

Running this under the most current Snow Leopard is not seeming to change the TimeZone of any of my birthday entries. I still have a mish-mash of entries in either -0500 or -0400. This is causing the birthdays to misread by a day when DST is in effect.

Any advice?

regards

bex



[ Reply to This | # ]