




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
-----------
#
#AssignBaseWeek--
#
# DeterminesthebaseyearandweekintheISO8601fiscalcalendar.
#
#Parameters:
# date-Dictionarycontainingthefieldsofthedatethat
# istobeaugmentedwiththebaseyearandweek.
# baseTime-BasetimeexpressedinsecondsfromthePosixepoch.
# changeover-JulianDayonwhichtheGregoriancalendarwasadopted
# inthetargetlocale.
#
#Results:
# Returnsthegivendatewith"iso8601Year"settothe
# baseyearand"iso8601Week"totheweeknumber.
#
#Sideeffects:
# None.
#
#----------------------------------------------------------------------
proc::tcl::clock::AssignBaseWeek{datebaseTimetimeZonechangeover}{
variableTZData
#FindtheJulianDayNumbercorrespondingtothebasetime
setdate2[GetDateFields$baseTime$TZData($timeZone)$changeover]
#CalculatetheISO8601dateandtransfertheyear
dictsetdateeraCE
dictsetdateiso8601Year[dictget$date2iso8601Year]
dictsetdateiso8601Week[dictget$date2iso8601Week]
return$date
}
#----------------------------------------------------------------------
#
#AssignBaseJulianDay--
#
# Determinesthebasedayforatime-of-dayconversion.
#
#Parameters:
# date-Dictionarythatistogetthebaseday
# baseTime-BasetimeexpressedinsecondsfromthePosixepoch
# changeover-JuliandayonwhichtheGregoriancalendarwas
# adpotedinthetargetlocale.
#
#Results:
# Returnsthegivendictionaryaugmentedwitha'julianDay'field
# thatcontainsthebaseday.
#
#Sideeffects:
# None.
#
#----------------------------------------------------------------------
proc::tcl::clock::AssignBaseJulianDay{datebaseTimetimeZonechangeover}{
variableTZData
#FindtheJulianDayNumbercorrespondingtothebasetime
setdate2[GetDateFields$baseTime$TZData($timeZone)$changeover]
dictsetdatejulianDay[dictget$date2julianDay]
return$date
}
#----------------------------------------------------------------------
#
#InterpretHMSP--
#
# Interpretsatimeintheform"hh:mm:ssam".
#
#Parameters:
# date--Dictionarycontaining"hourAMPM","minute","second"
# and"amPmIndicator"fields.
#
#Results:
# Returnsthenumberofsecondsfromlocalmidnight.
#
#Sideeffects:
# None.
#
#----------------------------------------------------------------------
proc::tcl::clock::InterpretHMSP{date}{
sethr[dictget$datehourAMPM]
if{$hr==12}{
sethr0
}
if{[dictget$dateamPmIndicator]}{
incrhr12
}
dictsetdatehour$hr
return[InterpretHMS$date[setdate{}]]
}
#----------------------------------------------------------------------
#
#InterpretHMS--
#
# Interpretsa24-hourtime"hh:mm:ss"
#
#Parameters:
# date--Dictionarycontainingthe"hour","minute"and"second"
# fields.
#
#Results:
# Returnsthegivendictionaryaugmentedwitha"secondOfDay"
# fieldcontainingthenumberofsecondsfromlocalmidnight.
#
#Sideeffects:
# None.
#
#----------------------------------------------------------------------
proc::tcl::clock::InterpretHMS{date}{
return[expr{
([dictget$datehour]*60
+[dictget$dateminute])*60
+[dictget$datesecond]
}]
}
#----------------------------------------------------------------------
#
#GetSystemTimeZone--
#
# Determinesthesystemtimezone,whichisthedefaultforthe
# 'clock'commandifnootherzoneissupplied.
#
#Parameters:
# None.
#
#Results:
# Returnsthesystemtimezone.
#
#Sideeffects:
# Storesthesustemtimezoneinthe'CachedSystemTimeZone'
# variable,sincedeterminingitmaybeanexpensiveprocess.
#
#----------------------------------------------------------------------
proc::tcl::clock::GetSystemTimeZone{}{
variableCachedSystemTimeZone
variableTimeZoneBad
if{[setresult[getenvTCL_TZ]]ne{}}{
settimezone$result
}elseif{[setresult[getenvTZ]]ne{}}{
settimezone$result
}
if{![infoexiststimezone]}{
#Cachethetimezoneonlyifitwasdetectedbyoneofthe
#expensivemethods.
if{[infoexistsCachedSystemTimeZone]}{
settimezone$CachedSystemTimeZone
}elseif{$::tcl_platform(platform)eq{windows}}{
settimezone[GuessWindowsTimeZone]
}elseif{[fileexists/etc/localtime]
&&![catch{ReadZoneinfoFile\
Tcl/Localtime/etc/localtime}]}{
settimezone:Tcl/Localtime
}else{
settimezone:localtime
}
setCachedSystemTimeZone$timezone
}
if{![dictexists$TimeZoneBad$timezone]}{
dictsetTimeZoneBad$timezone[catch{SetupTimeZone$timezone}]
}
if{[dictget$TimeZoneBad$timezone]}{
return:localtime
}else{
return$timezone
}
}
#----------------------------------------------------------------------
#
#ConvertLegacyTimeZone--
#
# Givenanalphanumerictimezoneidentifierandthesystemtimezone,
# convertthealphanumericidentifiertoanunambiguoustimezone.
#
#Parameters:
# tzname-Nameofthetimezonetoconvert
#
#Results:
# Returnsatimezonenamecorrespondingtotzname,butinan
# unambiguousform,generally+hhmm.
#
#ThisprocedureisimplementedprimarilytoallowtheparsingofRFC822
#date/timestrings.Processingatimezonenameoninputisnotrecommended
#practice,becausethereisconsiderableroomforambiguity;forinstance,is
#BSTBrazilianStandardTime,orBritishSummerTime?
#
#----------------------------------------------------------------------
proc::tcl::clock::ConvertLegacyTimeZone{tzname}{
variableLegacyTimeZone
settzname[stringtolower$tzname]
if{![dictexists$LegacyTimeZone$tzname]}{
return-codeerror-errorcode[listCLOCKbadTZName$tzname]\
"timezone\"$tzname\"notfound"
}
return[dictget$LegacyTimeZone$tzname]
}
#----------------------------------------------------------------------
#
#SetupTimeZone--
#
# Giventhenameorspecificationofatimezone,setsupitsin-memory
# data.
#
#Parameters:
# tzname-Nameofatimezone
#
#Results:
# Unlessthetimezoneis':localtime',setstheTZDataarraytocontain
# thelookuptableforlocal<->UTCconversion.Returnsanerrorifthe
# timezonecannotbeparsed.
#
#----------------------------------------------------------------------
proc::tcl::clock::SetupTimeZone{timezone}{
variableTZData
if{![infoexistsTZData($timezone)]}{
variableMINWIDE
if{$timezoneeq{:localtime}}{
#Nothingtodo,we'llconvertusingthelocaltimefunction
}elseif{
[regexp{^([-+])(\d\d)(?::?(\d\d)(?::?(\d\d))?)?}$timezone\
->shhmmss]
}then{
#Makeafixedoffset
::scan$hh%dhh
if{$mmeq{}}{
setmm0
}else{
::scan$mm%dmm
}
if{$sseq{}}{
setss0
}else{
::scan$ss%dss
}
setoffset[expr{($hh*60+$mm)*60+$ss}]
if{$seq{-}}{
setoffset[expr{-$offset}]
}
setTZData($timezone)[list[list$MINWIDE$offset-1$timezone]]
}elseif{[stringindex$timezone0]eq{:}}{
#Convertusingatimezonefile
if{
[catch{
LoadTimeZoneFile[stringrange$timezone1end]
}]&&[catch{
LoadZoneinfoFile[stringrange$timezone1end]
}]
}then{
return-codeerror\
-errorcode[listCLOCKbadTimeZone$timezone]\
"timezone\"$timezone\"notfound"
}
}elseif{![catch{ParsePosixTimeZone$timezone}tzfields]}{
#ThislookslikeaPOSIXtimezone-trytoprocessit
if{[catch{ProcessPosixTimeZone$tzfields}dataopts]}{
if{[lindex[dictget$opts-errorcode]0]eq{CLOCK}}{
dictunsetopts-errorinfo
}
return-options$opts$data
}else{
setTZData($timezone)$data
}
}else{
#Wecouldn'tparsethisasaPOSIXtimezone.Tryagainwitha
#timezonefile-thistimewithoutacolon
if{[catch{LoadTimeZoneFile$timezone}]
&&[catch{LoadZoneinfoFile$timezone}-opts]}{
dictunsetopts-errorinfo
return-options$opts"timezone$timezonenotfound"
}
setTZData($timezone)$TZData(:$timezone)
}
}
return
}
#----------------------------------------------------------------------
#
#GuessWindowsTimeZone--
#
# Determinesthesystemtimezoneonwindows.
#
#Parameters:
# None.
#
#Results:
# Returnsatimezonespecifierthatcorrespondstothesystemtimezone
# informationfoundintheRegistry.
#
#Bugs:
# FixeddatesforDSTchangeareunimplementedatpresent,becauseno
# timezoneinformationsuppliedwithWindowsactuallyusesthem!
#
#OnaWindowssystemwhereneither$env(TCL_TZ)nor$env(TZ)isspecified,
#GuessWindowsTimeZonelooksintheRegistryforthesystemtimezone
#information.ItthenattemptstofindanentryinWinZoneInfoforatime
#zonethatusesthesamerules.Ifitfindsone,itreturnsit;otherwise,
#itconstructsaPosix-styletimezonestringandreturnsthat.
#
#----------------------------------------------------------------------
proc::tcl::clock::GuessWindowsTimeZone{}{
variableWinZoneInfo
variableNoRegistry
variableTimeZoneBad
if{[infoexistsNoRegistry]}{
return:localtime
}
#Dredgetimezoneinformationoutoftheregistry
if{[catch{
setrpathHKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Control\\TimeZoneInformation
setdata[list\
[expr{-60
*[registryget$rpathBias]}]\
[expr{-60
*[registryget$rpathStandardBias]}]\
[expr{-60\
*[registryget$rpathDaylightBias]}]]
setstdtzi[registryget$rpathStandardStart]
foreachind{02144681012}{
binaryscan$stdtzi@${ind}sval
lappenddata$val
}
setdaytzi[registryget$rpathDaylightStart]
foreachind{02144681012}{
binaryscan$daytzi@${ind}sval
lappenddata$val
}
}]}{
#MissingvaluesintheRegistry-bailout
return:localtime
}
#MakeupaPosixtimezonespecifierifwecan'tfindone.Checkhere
#thatthetzdatafileexists,incasewe'rerunninginanenvironment
#(e.g.starpack)wheretzdataisincomplete.(Bug1237907)
if{[dictexists$WinZoneInfo$data]}{
settzname[dictget$WinZoneInfo$data]
if{![dictexists$TimeZoneBad$tzname]}{
dictsetTimeZoneBad$tzname[catch{SetupTimeZone$tzname}]
}
}else{
settzname{}
}
if{$tznameeq{}||[dictget$TimeZoneBad$tzname]}{
lassign$data\
biasstdBiasdstBias\
stdYearstdMonthstdDayOfWeekstdDayOfMonth\
stdHourstdMinutestdSecondstdMillisec\
dstYeardstMonthdstDayOfWeekdstDayOfMonth\
dstHourdstMinutedstSeconddstMillisec
setstdDelta[expr{$bias+$stdBias}]
setdstDelta[expr{$bias+$dstBias}]
if{$stdDelta<=0}{
setstdSignum+
setstdDelta[expr{-$stdDelta}]
setdispStdSignum-
}else{
setstdSignum-
setdispStdSignum+
}
sethh[::format%02d[expr{$stdDelta/3600}]]
setmm[::format%02d[expr{($stdDelta/60)%60}]]
setss[::format%02d[expr{$stdDelta%60}]]
settzname{}
appendtzname<$dispStdSignum$hh$mm>$stdSignum$hh:$mm:$ss
if{$stdMonth>=0}{
if{$dstDelta<=0}{
setdstSignum+
setdstDelta[expr{-$dstDelta}]
setdispDstSignum-
}else{
setdstSignum-
setdispDstSignum+
}
sethh[::format%02d[expr{$dstDelta/3600}]]
setmm[::format%02d[expr{($dstDelta/60)%60}]]
setss[::format%02d[expr{$dstDelta%60}]]
appendtzname<$dispDstSignum$hh$mm>$dstSignum$hh:$mm:$ss
if{$dstYear==0}{
appendtzname,M$dstMonth.$dstDayOfMonth.$dstDayOfWeek
}else{
#IhavenotbeenabletofindanylocaleonwhichWindows
#convertstimezoneonafixeddayoftheyear,hencedon't
#knowhowtointerpretthefields.Ifsomeonecaninformme,
#I'dbegladtocodeitup.Forrightnow,webailoutin
#suchacase.
return:localtime
}
appendtzname/[::format%02d$dstHour]\
:[::format%02d$dstMinute]\
:[::format%02d$dstSecond]
if{$stdYear==0}{
appendtzname,M$stdMonth.$stdDayOfMonth.$stdDayOfWeek
}else{
#IhavenotbeenabletofindanylocaleonwhichWindows
#convertstimezoneonafixeddayoftheyear,hencedon't
#knowhowtointerpretthefields.Ifsomeonecaninformme,
#I'dbegladtocodeitup.Forrightnow,webailoutin
#suchacase.
return:localtime
}
appendtzname/[::format%02d$stdHour]\
:[::format%02d$stdMinute]\
:[::format%02d$stdSecond]
}
dictsetWinZoneInfo$data$tzname
}
return[dictget$WinZoneInfo$data]
}
#----------------------------------------------------------------------
#
#LoadTimeZoneFile--
#
# Loadthedatafilethatspecifiestheconversionbetweena
# giventimezoneandGreenwich.
#
#Parameters:
# fileName--Nameofthefiletoload
#
#Results:
# None.
#
#Sideeffects:
# TZData(:fileName)containsthetimezonedata
#
#----------------------------------------------------------------------
proc::tcl::clock::LoadTimeZoneFile{fileName}{
variableDataDir
variableTZData
if{[infoexistsTZData($fileName)]}{
return
}
#Sinceanunsafeinterpusesthe[clock]commandinthemaster,thiscode
#issecuritysensitive.Makesurethatthepathnamecannotescapethe
#givendirectory.
if{![regexp{^[[.-.][:alpha:]_]+(?:/[[.-.][:alpha:]_]+)*$}$fileName]}{
return-codeerror\
-errorcode[listCLOCKbadTimeZone$:fileName]\
"timezone\":$fileName\"notvalid"
}
try{
source-encodingutf-8[filejoin$DataDir$fileName]
}onerror{}{
return-codeerror\
-errorcode[listCLOCKbadTimeZone:$fileName]\
"timezone\":$fileName\"notfound"
}
return
}
#----------------------------------------------------------------------
#
#LoadZoneinfoFile--
#
# LoadsabinarytimezoneinformationfileinOlsonformat.
#
#Parameters:
# fileName-Relativepathnameofthefiletoload.
#
#Results:
# Returnsanemptyresultnormally;returnsanerrorifnoOlsonfile
# wasfoundorthefilewasmalf
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 運(yùn)動(dòng)員動(dòng)作捕捉行業(yè)深度調(diào)研及發(fā)展戰(zhàn)略咨詢報(bào)告
- 自信演講大賽行業(yè)深度調(diào)研及發(fā)展戰(zhàn)略咨詢報(bào)告
- 企業(yè)上市擔(dān)保服務(wù)行業(yè)跨境出海戰(zhàn)略研究報(bào)告
- 創(chuàng)業(yè)投資AI應(yīng)用企業(yè)制定與實(shí)施新質(zhì)生產(chǎn)力戰(zhàn)略研究報(bào)告
- 西部證券股份有限公司招聘筆試真題2024
- 輪滑速滑賽行業(yè)深度調(diào)研及發(fā)展戰(zhàn)略咨詢報(bào)告
- 足球教育助學(xué)行業(yè)深度調(diào)研及發(fā)展戰(zhàn)略咨詢報(bào)告
- 金融科技產(chǎn)品廣告行業(yè)跨境出海戰(zhàn)略研究報(bào)告
- 藝術(shù)民宿與度假村行業(yè)跨境出海戰(zhàn)略研究報(bào)告
- 開放式銀行接口(API)與集成行業(yè)跨境出海戰(zhàn)略研究報(bào)告
- 2024年電子商務(wù)師真題試題及答案
- 撬裝式承壓設(shè)備系統(tǒng)安全技術(shù)規(guī)范
- 園藝植物遺傳育種 課件全套 第1-10章 緒論-新品種的審定與推廣繁育+實(shí)訓(xùn)
- 2025-2030中國免洗護(hù)發(fā)素行業(yè)市場(chǎng)發(fā)展趨勢(shì)與前景展望戰(zhàn)略研究報(bào)告
- 《智能優(yōu)化算法解析》 課件 第6章-基于群智能的智能優(yōu)化算法
- 《紅巖》中考試題(截至2024年)
- 幕墻UHPC施工專項(xiàng)方案 (評(píng)審版)
- 華為IAD132E(T)開局指導(dǎo)書
- 2024年415全民國家安全教育日知識(shí)競(jìng)賽測(cè)試題庫
- (2025)二十大知識(shí)競(jìng)賽題庫(含答案)
- 2025年華北電力大學(xué)輔導(dǎo)員及其他崗位招考聘用54人高頻重點(diǎn)提升(共500題)附帶答案詳解
評(píng)論
0/150
提交評(píng)論