![]() |
![]() |
|
![]() |
Paradox® Date, Time, and DateTime Data Types More B.C. Date Tips and Tricks © 2001 Rick Kelly www.crooit.com Download the library containing the routines used in this series. Preface A library of all OPAL methods presented is available here. In previous sections, we explored some limitations of Paradox in dealing with B.C. dates. There are other problems to address regarding B.C. dates. The OPAL dow() function generates a GPV with Paradox versions 7, 8, 9, and 10 for BCE (Before Common Era) dates with years 2 or higher. (A return of blank() is returned when using BDE 4.51). Interestingly, it works for year = -1. The following shows how to generate the GPV. var daAny Date endVar daAny = date(3,1,-2001) msgInfo(daAny,dow(daAny))Additionally, the dowOrd() function always generates a GPV under the same circumstances with an overflow exception. We will develop replacement methods for dow() and dowOrd() that correctly handle B.C. dates. emDowOrd The OPAL dowOrd() function returns a SmallInt type integer with 1=Sun, 2=Mon, 3=Tue, 4=Wed, 5=Thu, 6=Fri, and 7=Sat when presented with a Date type. We have a previously defined method cmDayOfWeekFromFixed that returns a SmallInt type integer with 0=Sun, 1=Mon, 2=Tue, 3=Wed, 4=Thu, 5=Fri, and 6=Sat when presented with a fixed date that also correctly handles B.C. dates. Our approach will take any valid Date type, convert it to a fixed date with emFixedFromGregorian and add one to the result from cmDayOfWeekFromFixed. method emDowOrd(daAny Date) SmallInt ; ; Return the day of the week number ; ; 1=Sun,2=Mon....6=Sat ; return cmDayOfWeekFromFixed(emFixedFromGregorian(daAny)) + 1 endMethodemDow The OPAL dow() function returns a String type representing the day of week (Sun, Mon, Tue, Wed, Thu, Fri, and Sat) when presented with a Date type and we will continue to use it after we alter the date presented. From our previous discussions of fixed dates, recall that January 1, 1 is day 1 and is a Monday. Our approach will take any valid Date type, convert it to a fixed date with emFixedFromGregorian and take the result from cmDayOfWeekFromFixed and treat it as a fixed date number. We add in seven to avoid the OPAL dow() overflow exception. In summary, our approach will map any valid date type to one of the days from January 7, 1 - January 13, 1 inclusive and let the normal OPAL dow() function return the correct result for us. method emDow(daAny Date) String ; ; Return the correct day of the week for B.C. dates ; return dow(date(1, cmDayOfWeekFromFixed(emFixedFromGregorian(daAny)) + 7, 1)) endMethodThe approach of using sources other than normal Date types as fixed dates can be used in other, interesting ways. Assume we are given a day of the year 1-365 (366 in leap years) and want to know the month and day it represents. Year 1 for fixed dates is represented by the values 1-365 and is perfect for non-leap years. Year 4 (values 1096-1461) for fixed dates is the first leap year after Year 1. If we map our day of the year to either Year 1 or Year 4, the normal OPAL date() function can take of the rest. method emMonthDayFromDOY(siDayOfYear SmallInt, loLeapYear Logical, var siMonth SmallInt, var siDay SmallInt) Logical var daAny Date loReturn Logical endvar ; ; Treat day as a fixed date, Year 1 for non-leap years ; and Year 4 for leap years by adding Dec 31, 3 ; (fixed date 1095) to it. ; ; Check for valid siDayOfYear (1-365 or 366 for leap years) ; ; loReturn = True siMonth = 0 siDay = 0 switch case siDayOfYear < 1 : otherwise : daAny = date(siDayOfYear) switch case loLeapYear = False : ; ; Non-Leap Years ; switch case siDayOfYear > 365 : loReturn = False endSwitch otherwise : ; ; Leap Years ; switch case siDayOfYear > 366 : loReturn = False otherwise : daAny = daAny + 1095 endSwitch endSwitch endSwitch ; ; If loReturn is True, extract the month and day ; switch case loReturn = True : siMonth = month(daAny) siDay = day(daAny) endSwitch return loReturn endMethod Conclusion We now have methods that support basic weekday calculations with a corrective provision for B.C. dates and avoid the problems with OPAL dowOrd() and dow() functions. Next: Odds and Ends - Fiscal Periods References Common / Shared ObjectPALŽ Routines Discussion of this article |
![]() Feedback | Paradox Day | Who Uses Paradox | I Use Paradox | Downloads ![]() |
|
![]() The information provided on this Web site is not in any way sponsored or endorsed by Corel Corporation. Paradox is a registered trademark of Corel Corporation. ![]() |
|
![]() Modified: 15 May 2003 Terms of Use / Legal Disclaimer ![]() |
![]() Copyright © 2001- 2003 Paradox Community. All rights reserved. Company and product names are trademarks or registered trademarks of their respective companies. Authors hold the copyrights to their own works. Please contact the author of any article for details. ![]() |
![]() |
|