caldav::calendars proc timezone (public)

 caldav::calendars[i] timezone

Defined in packages/xotcl-core/tcl/01-debug-procs.tcl

Return the timezone

Testcases:
No testcase defined.
Source code:
#
# Return the timezone
#

# GN TODO: don't hardcode timezone

set timezone [lang::system::timezone]
set date_info [exec [util::which date] "+%Z %z"]
set TZNAME [linex $date_info 0]
set default_offset [linex $date_info 1]

# TZOFFSETFROM: local time offset from GMT when daylight saving time is in operation,
# TZOFFSETTO is the local time offset from GMT when standard time is in operation.
# set TZOFFSETFROM "+0100"
# set TZOFFSETTO "+0200"

set TZOFFSETFROM $default_offset
set TZOFFSETTO $default_offset

#
# Compute offsets. It is not so easy to come up with a variant
# that works under linux and macOS, since the results of zdump
# is different (no gmtoff= under macOS) and date has well
# different arguments.
#
try {
    set year [clock format [clock seconds] -format %Y ]
    set lines [exec [::util::which zdump] -v [lang::system::timezone] | fgrep $year]
    foreach l [split $lines \n] {
        #
        # Compute date difference in seconds
        #
        set diff [expr {([clock scan [lindex $l 11]]-[clock scan [lindex $l 4]]) / 60}]
        #
        # Format diff in seconds in a form like "+0200"
        #
        set sign [expr {$diff>0 ? "+" : "-"}]
        set H [format %02d [expr {$diff/60}]]
        set M [format %02d [expr {$diff%60}]]
        dict set time [lindex $l 14] $sign$H$M
    }

    if {[dict exists $time isdst=1]} {
        set TZOFFSETFROM [dict get $time isdst=1]
    }
    if {[dict exists $time isdst=0]} {
        set TZOFFSETTO [dict get $time isdst=0]
    }
}

return "BEGIN:VTIMEZONE
TZID:$timezone
TZURL:http://tzurl.org/zoneinfo-outlook/timezone
X-LIC-LOCATION:[lang::system::timezone]
BEGIN:DAYLIGHT
TZOFFSETFROM:$TZOFFSETFROM
TZOFFSETTO:$TZOFFSETTO
TZNAME:$TZNAME
DTSTART:19700329T020000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
TZNAME:CET
DTSTART:19701025T030000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
END:STANDARD
END:VTIMEZONE"
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: