Index: openacs-4/packages/acs-lang/www/admin/set-system-timezone.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/set-system-timezone.tcl,v diff -u -r1.9 -r1.10 --- openacs-4/packages/acs-lang/www/admin/set-system-timezone.tcl 14 May 2007 20:30:23 -0000 1.9 +++ openacs-4/packages/acs-lang/www/admin/set-system-timezone.tcl 27 Jul 2012 21:57:13 -0000 1.10 @@ -43,29 +43,49 @@ } # Try to get the correct UTC time from www.timeanddate.com - if { [catch { - set time_and_date_page [util_httpget "http://www.timeanddate.com/worldclock/"] - - regexp {Current UTC \(or GMT/Zulu\)-time used: ]*>([^<]*)} $time_and_date_page match utc_from_page - - # UTC in format: - # Wednesday, November 20, 2002, at 2:49:07 PM - # Wednesday, August 6, 2003, at 12:11:48 - regexp {^([^,]*), *([^ ]*) *([0-9]*), *([0-9]*) at (.*)$} $utc_from_page match weekday month day year time - - set utc_epoch [clock scan "${month} ${day}, ${year} ${time}"] - - set utc_ansi [clock format $utc_epoch -format "%Y-%m-%d %T"] - } errmsg] } { global errorInfo - ns_log Error "Problem getting UTC time from timeanddate.com, they may have changed their design so our regexp stopped working.\n$errorInfo" - + ns_log Error "set-system-timezone.tcl: Error trying to get timeanddate.com/worldclock/" set utc_ansi {Couldn't get time from timeanddate.com, sorry.} } +# example input: +# ss=m3>Current UTC \(or GMT/Zulu\)-time used: Friday, July 27, 2012 at 19:20:27 + +if { [regexp {Current[ ]+UTC[^:]+[:][ ]*]*>([^<]+)} $time_and_date_page match utc_from_page] } { + # UTC in format (including some historical ones to help keep a robust regexp: + # Friday, July 27, 2012 at 19:20:27 + # Wednesday, 20 November 2002, at 2:49:07 PM + # Wednesday, 6 August 2003, at 12:11:48 + # this regexp is a little more flexible and accepting of data types to help with parsing + set reg_p [regexp -nocase -- {^([^,]+)[,][ ]+([a-z0-9]+)[ ]+([a-z0-9]+)[,]?[ ]+([a-z0-9]+)[at, ]+[ ]+(.*)$} $utc_from_page match weekday day month year time] + + if { $reg_p && [info exists month] && [info exists day] && [info exists year] && [info exists time] } { + # did timeanddate swap day/month? + if { [ad_var_type_check_number_p $month] } { + set temp $day + set day $month + set month $temp + if { $year < 32 } { + # do you think they swapped day and year? + set temp $day + set day $year + set year $temp + } + } + set utc_epoch [clock scan "${month} ${day}, ${year} ${time}"] + set utc_ansi [clock format $utc_epoch -format "%Y-%m-%d %T"] + } else { + set utc_ansi "Couldn't extract useful time from timeanddate.com, sorry. Got: utc_from_page='${utc_from_page}'" + ns_log Error "acs-lang/www/admin/set-system-timezone.tcl: Problem extracting UTC time from timeanddate.com, they may have changed their design so our regexp stopped working." + } +} else { + set utc_ansi "Couldn't extract time from timeanddate.com, sorry. Got: time_and_date_page='${time_and_date_page}'" + ns_log Error "acs-lang/www/admin/set-system-timezone.tcl: Problem getting UTC time from timeanddate.com, they may have changed their design so our regexp stopped working." +} + set correct_p {} if { [info exists utc_epoch] } {