Author: eur.van.andel
Date: Fri Oct 31 06:09:14 2008
New Revision: 505

Added:
    trunk/unvalidated/include/jal/calendar.jal

Log:
put calendar routine in separate lib to keep sample simple


Added: trunk/unvalidated/include/jal/calendar.jal
==============================================================================
--- (empty file)
+++ trunk/unvalidated/include/jal/calendar.jal  Fri Oct 31 06:09:14 2008
@@ -0,0 +1,66 @@
+-- Title: Calendar, takes care of ranges for seconds, minutes, date,  
month, year
+-- Author: Eur van Andel, Copyright (c) 2008, all rights reserved.
+-- Adapted-by:
+-- Compiler: >=2.4h
+--
+-- This file is part of jallib (http://jallib.googlecode.com)
+-- Released under the BSD license  
(http://www.opensource.org/licenses/bsd-license.php)
+--
+-- Description: This library has only one fuction: calendar(). It assumes  
the following variables:
+-- var volatile byte seconds (typically updated by an ISR)
+-- var byte hours, minutes, date, month
+-- var word year
+-- It knows the leap years until 2099.
+
+
+procedure calendar() is      -- should be called at least once a minute
+   var byte max_date = 31
+                              -- and only if seconds > 59
+   while seconds > 59 loop    -- if seconds < 60, nor harm is done
+      seconds = seconds - 60
+      minutes = minutes + 1
+   end loop
+
+   if minutes > 59 then
+      minutes = minutes - 60  -- we assume calendar is called at least  
every 3 min
+      hours = hours + 1
+   end if
+
+   if hours > 23 then
+      hours = 0
+      date = date + 1
+      if date > 26 then
+         if month < 8 then
+            if month % 2 == 1 then
+               max_date = 31     -- jan, mar, may, july
+            else
+               if month == 2 then
+                  if year % 4 == 0 then
+                     max_date = 29  -- feb, leap year, good thru 2099 AD
+                  else
+                     max_date = 28  -- feb, no leap year
+                  end if
+               else
+                   max_date = 30    -- apr, june
+               end if
+            end if
+         else
+            if month % 2 == 0 then
+               max_date = 31     -- aug, oct, dec
+            else
+               max_date = 30     -- sept, nov
+            end if
+         end if
+      end if
+
+      if date > max_date then
+         date = 1
+         month = month + 1
+         if month == 13 then
+            month = 1
+            year = year + 1
+         end if
+      end if
+   end if
+end procedure
+

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jallib" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/jallib?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to