[Quantproject-developers] QuantDownloader/Downloader/OpenTickDownloader/TimeZoneManaging TimeZoneM
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2009-01-03 18:42:01
|
Update of /cvsroot/quantproject/QuantDownloader/Downloader/OpenTickDownloader/TimeZoneManaging In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv29990/Downloader/OpenTickDownloader/TimeZoneManaging Modified Files: TimeZoneManager.cs Log Message: - an exception is now thrown if daylight saving time information are requested for years that are too old and are not managed by the class - the code has been refactored and it is more readable, now Index: TimeZoneManager.cs =================================================================== RCS file: /cvsroot/quantproject/QuantDownloader/Downloader/OpenTickDownloader/TimeZoneManaging/TimeZoneManager.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TimeZoneManager.cs 9 Jul 2008 22:22:23 -0000 1.1 --- TimeZoneManager.cs 3 Jan 2009 18:41:53 -0000 1.2 *************** *** 3,7 **** TimeZoneManager.cs ! Copyright (C) 2008 Glauco Siliprandi --- 3,7 ---- TimeZoneManager.cs ! Copyright (C) 2008 Glauco Siliprandi *************** *** 19,23 **** along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; --- 19,23 ---- along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; *************** *** 40,43 **** --- 40,47 ---- #region IsDaylightSavingTime + #region getDstPeriod + + #region initialize_dstPeriods_ifTheCase + #region initialize_dstPeriods *************** *** 76,79 **** --- 80,121 ---- #endregion initialize_dstPeriods + private static void initialize_dstPeriods_ifTheCase() + { + if ( dSTPeriods == null ) + initialize_dstPeriods(); + } + #endregion initialize_dstPeriods_ifTheCase + + #region getDstPeriod_withInitialized_dstPeriods + private static void getDstPeriod_withInitialized_dstPeriods_checkParameters( + DateTime dateTimeInNewYorkTimeZone ) + { + if ( !TimeZoneManager.dSTPeriods.ContainsKey( dateTimeInNewYorkTimeZone.Year ) ) + throw new Exception( + "We don't have DaylightSavingTime information for the year " + + dateTimeInNewYorkTimeZone.Year + ". Please check the method " + + "initialize_dstPeriods() and possibly complete it with more years" ); + } + private static DSTPeriod getDstPeriod_withInitialized_dstPeriods( + DateTime dateTimeInNewYorkTimeZone ) + { + TimeZoneManager.getDstPeriod_withInitialized_dstPeriods_checkParameters( + dateTimeInNewYorkTimeZone ); + DSTPeriod dSTPeriod = + (DSTPeriod)dSTPeriods[ dateTimeInNewYorkTimeZone.Year ]; + return dSTPeriod; + } + #endregion getDstPeriod_withInitialized_dstPeriods + + private static DSTPeriod getDstPeriod( DateTime dateTimeInNewYorkTimeZone ) + { + TimeZoneManager.initialize_dstPeriods_ifTheCase(); + DSTPeriod dSTPeriod = + TimeZoneManager.getDstPeriod_withInitialized_dstPeriods( + dateTimeInNewYorkTimeZone ); + return dSTPeriod; + } + #endregion getDstPeriod + /// <summary> /// True iif the given DateTime is a daylightSavingTime *************** *** 84,95 **** DateTime dateTimeInNewYorkTimeZone ) { - if ( dSTPeriods == null ) - initialize_dstPeriods(); DSTPeriod dSTPeriod = ! (DSTPeriod)dSTPeriods[ dateTimeInNewYorkTimeZone.Year ]; bool isDaylightSavingTime = ( dSTPeriod.Begin.CompareTo( dateTimeInNewYorkTimeZone ) < 0 ) && ( dSTPeriod.End.CompareTo( dateTimeInNewYorkTimeZone ) > 0 ); ! return isDaylightSavingTime; } #endregion IsDaylightSavingTime --- 126,135 ---- DateTime dateTimeInNewYorkTimeZone ) { DSTPeriod dSTPeriod = ! TimeZoneManager.getDstPeriod( dateTimeInNewYorkTimeZone ); bool isDaylightSavingTime = ( dSTPeriod.Begin.CompareTo( dateTimeInNewYorkTimeZone ) < 0 ) && ( dSTPeriod.End.CompareTo( dateTimeInNewYorkTimeZone ) > 0 ); ! return isDaylightSavingTime; } #endregion IsDaylightSavingTime *************** *** 121,124 **** return dateTimeInEST; } ! } } --- 161,164 ---- return dateTimeInEST; } ! } } |