Adding UTC to timezones

David Jarvie djarvie at kde.org
Sat Sep 6 17:59:47 BST 2008


On Fri 5 September 2008 23:55:33 Aaron J. Seigo wrote:
> On Friday 05 September 2008, David Jarvie wrote:
> > UTC is always available as a time zone (KTimeZone::utc()), even if it
> > isn't necessarily included in KSystemTimeZones::zones(). It's a special
> > case, and the clock widget should ensure that it offers it as an option.
>
> we certainly aren't going to put it as a seperate checkbox when there's a
> fine list of timezones right there; so you'd suggest something like:
>
> KTimeZones *tzs = KSystemTimeZones::zones();
> tzs->add(KTimeZone::utc());
> KTimeZoneWidget *tzWidget = new KTimeZoneWidget(parent, tzs);

KSystemTimeZones encapsulates all the time zones defined in the system time 
zone database. If UTC isn't in the database, it will not appear in 
KSystemTimeZones. Because UTC is the basic time zone to which all other time 
zones refer in their definitions, it isn't necessary for the system time zone 
database to include it - it always exists regardless, which is why 
KTimeZone::utc() is able to create a version of it.

If it is convenient in an application to add it to the time zone collection 
returned by KSystemTimeZones::zones(), then by all means do so, although your 
code isn't correct (the return type is 'const KTimeZones::ZoneMap').

On Sat 6 September 2008 00:08:27 Aaron J. Seigo wrote:
> just occurred to me that we could probably do
>
> tzs->remove(KTimeZone::utc());
>
> directly thereafter if we wanted to return it back to it's original state.
> still seems oddish =)

To remove a UTC time zone from a collection, it is always safest to find it by 
name "UTC" - there is no guarantee that different collections contain the 
same UTC instance. See the KTimeZone::utc() apidox.

-- 
David Jarvie.
KAlarm author and maintainer.
http://www.astrojar.org.uk/kalarm




More information about the kde-core-devel mailing list