
|
INFO - FAQ - CC2-Forum - CCPro-Forum |
|
Anbei der genannte Basic Code zur Ermittlung der Sommer/Winterzeit anhand des Datums: '---------------------------------------------------------------------------- ' Variables words / bytes / bits (assigned manually, adjust as needed) '---------------------------------------------------------------------------- DEFINE IsSummerTime bit [180] ' Global Summertime bit DEFINE TempBIT bit [181] ' Temporary general purpose bit DEFINE DWH byte [19] ' Temporary general purpose byte variable '---------------------------------------------------------------------------- ' Function: GetSummerTimeBit ' Description: Calculate the IsSummerTime bit ' Parameter: - ' Result: IsSummerTime ' Caution: The time variables MINUTE/HOUR/DAY/MONTH/DOW must contain ' valid data, that means, system time must be set. '---------------------------------------------------------------------------- #GetSummerTimeBit ' Make sure the variables HOUR/DAY/DOW/MONTH do not change during this code ' execution by storing the least significant bit of the time and check ' again at function exit. ' You may omit this, if the function is called at appropriate times only. TempBIT = -(MINUTE AND 1) ' Note: bits are 0 or -1 on this machine 'Initialize the result bit to wintertime as default IsSummerTime = OFF 'Now check MONTH ranges IF ((MONTH > 3) AND (MONTH < 10)) THEN IsSummerTime = ON 'If any month except march or october, we're done. IF (MONTH <> 3) AND (MONTH <> 10) THEN GOTO localGetSummerTimeBitExit 'Actually it is march or october. 'If march assume SummerTime, if october assume wintertime 'So assume for now, last sunday of the month has been reached. IF (MONTH = 3) THEN IsSummerTime = ON ' else the MONTH is 10 'Get the day of the last sunday of that month 'Algorithm does work with "31 day" months only, however 'march and october have 31 days. 'Note about DOW bug: Here DOW may by 0 or 7 in case of 'Sunday, that doesn't matter due to the MOD operator. DWH = ((DAY + 10 - DOW) MOD 7) + 25 'If that sunday has not been reached yet, then invert the 'assumption above, that means invert the result bit. IF (DAY < DWH) THEN IsSummerTime = NOT IsSummerTime 'It is not the last sunday in march/october? Then we're done. IF (DAY <> DWH) THEN GOTO localGetSummerTimeBitExit 'It is the Sunday in question. Now check the time. 'Algorithm is not 100% perfect for october between 02:00 'and 03:00, because that time period exits twice, but 'that should not be a real problem in most applications. IF (HOUR < 2) THEN IsSummerTime = NOT IsSummerTime #localGetSummerTimeBitExit 'Finally check if during the calculation done, the time 'has changed, which might affect variables HOUR/DAY/... 'This can be done by checking a single bit in the MINUTE 'variable. In the worst case, the MINUTE just changed, 'but that happens not again when the code is executed 'once more. IF (-(MINUTE AND 1) <> TempBIT) THEN GOTO GetSummerTimeBit RETURN |
| Antwort schreiben |