forked from DonovanChan/fmfunctions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDateBuildSearchRange.calc
81 lines (75 loc) · 2.03 KB
/
DateBuildSearchRange.calc
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
76
77
78
79
80
81
Let ( [
start = GetAsDate ( startDate ) ;
startMonth = Month ( start ) ;
startYear = Year ( start ) ;
startDay = Day ( start ) ;
end = GetAsDate ( endDate ) ;
searchString =
Case (
interval = "month" ;
Let ( [
searchEnd = Date ( startMonth + 1 ; 0 ; startYear ) ;
$searchEnd = If ( searchEnd > end ; end ; searchEnd ) ;
$searchNext = GetAsDate ( $searchEnd + 1 )
];
If (
$searchEnd = end ; start & "..." & end ;
startMonth & "/*/" & startYear
)
) ;
interval = "week" ;
Let ( [
searchEnd = Date ( startMonth ; startDay + 7 ; startYear ) ;
nextYearStart = Date ( 1 ; 1 ; startYear + 1 ) ;
$searchEnd =
Case (
searchEnd > nextYearStart ;
GetAsDate ( nextYearStart - 1 ) ;
searchEnd > end ;
end ;
searchEnd
) ;
$searchNext = GetAsDate ( $searchEnd + 1 )
];
start & "..." & $searchEnd
) ;
interval = "day" ;
Let ( [
searchEnd = start ;
$searchEnd = If ( searchEnd > end ; end ; searchEnd ) ;
$searchNext = GetAsDate ( $searchEnd + 1 )
];
$searchEnd
) ;
interval = "year" ;
Let ( [
searchEnd = Date ( startMonth ; startDay ; startYear + 1 ) ;
$searchEnd = If ( searchEnd > end ; end ; searchEnd ) ;
$searchNext = GetAsDate ( $searchEnd + 1 )
];
If (
$searchEnd = end ; start & "..." & end ;
"*/*/" & startYear
)
) ;
end
)
] ;
searchString &
Case (
$searchEnd < end ;
¶ & DateSearchRange ( $searchNext ; end ; interval )
)
)
/* —————————————————————————————— //
NAME:
DateSearchRange ( startDate; endDate; interval )
PURPOSE:
Builds return-delimited list of dates for purpose of searching
EXAMPLES:
DateSearchRange ( "1/1/10"; "3/8/10" ; month ) = "1/ * /10¶2/ * /10¶3/ * /10" (without spaces)
HISTORY:
Created: 2010-Aug-05 15h07 PST — Donovan A. Chandler
Modified: 2011-Jul-14 18h29 PST — Donovan Chandler ; Added support for interval types
NOTES:
*/