1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283(**************************************************************************)(* *)(* This file is part of Calendar. *)(* *)(* Copyright (C) 2003-2011 Julien Signoles *)(* *)(* you can redistribute it and/or modify it under the terms of the GNU *)(* Lesser General Public License version 2.1 as published by the *)(* Free Software Foundation, with a special linking exception (usual *)(* for Objective Caml libraries). *)(* *)(* It is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR *)(* *)(* See the GNU Lesser General Public Licence version 2.1 for more *)(* details (enclosed in the file LGPL). *)(* *)(* The special linking exception is detailled in the enclosed file *)(* LICENSE. *)(**************************************************************************)typet=|UTC|Local|UTC_Plusofintlettz=refUTCletout_of_boundsx=x<-12||x>11letin_boundsx=not(out_of_boundsx)letmake_in_boundsx=lety=xmod24inify<-12theny+24elseify>11theny-24elseyletgap_gmt_local=lett=Unix.time()in(Unix.localtimet).Unix.tm_hour-(Unix.gmtimet).Unix.tm_hourletcurrent()=!tzletchange=function|_ast->tz:=tletgapt1t2=letauxt1t2=assert(t1<t2);matcht1,t2with|UTC,Local->gap_gmt_local|UTC,UTC_Plusx->x|Local,UTC_Plusx->x-gap_gmt_local|UTC_Plusx,UTC_Plusy->y-x|_->assertfalseinletres=ift1=t2then0elseift1<t2thenauxt1t2else-auxt2t1inmake_in_boundsresletfrom_gmt()=gapUTC(current())letto_gmt()=gap(current())UTCletis_dst()=current()=Local&&(Unix.localtime(Unix.time())).Unix.tm_isdstlethour_of_dst()=ifis_dst()then1else0letonftzx=letold=current()inchangetz;tryletres=fxinchangeold;reswithexn->changeold;raiseexn