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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
<?LassoScript
//............................................................................
//
// jina: (c) 1999-2007 http://jina.se/
//
//............................................................................
/*
{fileName= jina_weekNum.lasso }
{rsrcType= tag }
{rsrcName= jina_weekNum }
{lassoVrsnMin= 8.1.0 }
{lassoVrsnMax= 8.5.2 }
{author= Jolle Carlestam }
{authorEmail= info@jina.se }
{authorHTTP= jina.se }
{desc= returns the fiscal week number of a given date,
datevalue needs to be a valid Lasso date
first day of week is presumed to be monday
Note that there“s an error in Lassos date calculation
regarding daylight savings. }
{maintvsrn= 1.1 }
{maintrelease= 1.0.0 }
{maintdate= 2007-01-31 }
{maintauthor= Jolle Carlestam }
{maintnotes= Separated into its own file }
{maintvsrn= 1.0 }
{maintrelease= 1.0.0 }
{maintdate= 2002-01-12, 2002-04-23, 2003-03-17 }
{maintauthor= Jolle Carlestam }
{maintnotes= initial release }
............................................................................
Usage:
var:'week' = (jina_weekNum: date);
.............................................................................
*/
Define_Tag: 'weekNum',
-namespace = 'jina_',
-Required = 'date', -copy;
if:#date -> type != 'date';
#date = (date: #date, -format='%Y-%m-%d');
/if;
if:#date -> type != 'date';
Fail: 8020, 'Submitted date not of date type';
/if;
Local:'theDate' = (local:'date') + (Duration:7200);
Local:'theYear' = (#theDate->Year);
Local:'firstDateofYear' = (Date:-Month = 1, -Day = 1, -Year = #theYear, -Time = '04:00:00');
Local:'firstDayofYear' = (#firstDateofYear->DayOfWeek);
if:(#firstDayofYear <= 5) && (#firstDayofYear != 1);
Local:'startDate'= (Date_Subtract:(#firstDateofYear), -Day = (#firstDayofYear - 2));
else: (#firstDayofYear == 1);
Local:'startDate' = (Date_Add:(#firstDateofYear), -Day = (1));
else;
Local:'startDate' = (Date_Add:(#firstDateofYear), -Day = (9 - #firstDayofYear));
/if;
Local:'DayinWeek' = (#theDate->DayOfWeek);
if:(#DayinWeek != 1);
Local:'firstDateinWeek' = (Date_Subtract:(#theDate), -Day = (#DayinWeek - 2));
else;
Local:'firstDateinWeek' = (Date_Subtract:(#theDate), -Day = 6);
/if;
Local:'theWeeksBetween' = (Date_Difference:#firstDateinWeek, #startDate, -Week) + 1;
if:#theWeeksBetween == 0;
#theWeeksBetween = jina_weekNum:(Date_Subtract:(#theDate), -Day = 1);
/if;
if:(#theWeeksBetween == 53) && ((date:#firstDateinWeek) >= (Date:-Month = 12, -Day = 29, -Year = #theYear, -Time = '04:00:00'));
#theWeeksBetween = 1;
/if;
Return: #theWeeksBetween;
/Define_Tag;
?>
|