-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDATE_LEAP_LIBR.bas
executable file
·75 lines (60 loc) · 2.32 KB
/
DATE_LEAP_LIBR.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
Attribute VB_Name = "DATE_LEAP_LIBR"
Option Explicit 'Requires that all variables to be declared explicitly.
Option Base 1 'The "Option Base" statement allows to specify 0 or 1 as the
'default first index of arrays.
'**********************************************************************************
'**********************************************************************************
'FUNCTION : IS_DATE_LEAP_YEAR_FUNC
'DESCRIPTION : Check if the specified Date is a leap year
'LIBRARY : DATE
'GROUP : LEAP
'ID : 001
'LAST UPDATE : 11 / 02 / 2004
'AUTHOR : RAFAEL NICOLAS FERMIN COTA
'**********************************************************************************
'**********************************************************************************
Function IS_DATE_LEAP_YEAR_FUNC(ByVal DATE_VAL As Date)
On Error GoTo ERROR_LABEL
IS_DATE_LEAP_YEAR_FUNC = Month(DateSerial(Year(DATE_VAL), 2, 29)) = 2
Exit Function
ERROR_LABEL:
IS_DATE_LEAP_YEAR_FUNC = Err.number
End Function
'**********************************************************************************
'**********************************************************************************
'FUNCTION : LEAP_YEARS_PERIOD_FUNC
'DESCRIPTION : Leap Years Period Function
'LIBRARY : DATE
'GROUP : LEAP
'ID : 003
'LAST UPDATE : 11 / 02 / 2004
'AUTHOR : RAFAEL NICOLAS FERMIN COTA
'**********************************************************************************
'**********************************************************************************
Function LEAP_YEARS_PERIOD_FUNC(ByVal FIRST_DATE As Date, _
ByVal SECOND_DATE As Date)
Dim i As Integer
Dim j As Integer
On Error GoTo ERROR_LABEL
If FIRST_DATE > SECOND_DATE Then
LEAP_YEARS_PERIOD_FUNC = -1
Exit Function
End If
For j = Year(FIRST_DATE) To Year(SECOND_DATE)
If IS_DATE_LEAP_YEAR_FUNC(j) = True Then
i = i + 1
End If
Next j
If FIRST_DATE > DateSerial(Year(FIRST_DATE), 2, 29) And _
IS_DATE_LEAP_YEAR_FUNC(Year(FIRST_DATE)) = True Then
i = i - 1
End If
If SECOND_DATE < DateSerial(Year(SECOND_DATE), 2, 29) And _
IS_DATE_LEAP_YEAR_FUNC(Year(SECOND_DATE)) = True Then
i = i - 1
End If
LEAP_YEARS_PERIOD_FUNC = i
Exit Function
ERROR_LABEL:
LEAP_YEARS_PERIOD_FUNC = Err.number
End Function