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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
//! VB6 `Weekday` Function
//!
//! The `Weekday` function returns a Variant (Integer) specifying a whole number representing the day of the week.
//!
//! ## Syntax
//! ```vb6
//! Weekday(date[, firstdayofweek])
//! ```
//!
//! ## Parameters
//! - `date`: Required. Variant, numeric expression, string expression, or any combination that can represent a date. If `date` contains Null, Null is returned.
//! - `firstdayofweek`: Optional. A constant that specifies the first day of the week. If not specified, vbSunday is assumed.
//!
//! ### `FirstDayOfWeek` Constants
//! - `vbUseSystem` (0): Use the system setting
//! - `vbSunday` (1): Sunday (default)
//! - `vbMonday` (2): Monday
//! - `vbTuesday` (3): Tuesday
//! - `vbWednesday` (4): Wednesday
//! - `vbThursday` (5): Thursday
//! - `vbFriday` (6): Friday
//! - `vbSaturday` (7): Saturday
//!
//! ## Returns
//! Returns a `Variant (Integer)` from 1 to 7 representing the day of the week:
//! - When `firstdayofweek` is `vbSunday` (default): 1=Sunday, 2=Monday, 3=Tuesday, 4=Wednesday, 5=Thursday, 6=Friday, 7=Saturday
//! - When `firstdayofweek` is `vbMonday`: 1=Monday, 2=Tuesday, 3=Wednesday, 4=Thursday, 5=Friday, 6=Saturday, 7=Sunday
//! - The numbering adjusts based on which day is specified as the first day of the week
//!
//! ## Remarks
//! The `Weekday` function determines which day of the week a date falls on:
//!
//! - **Return value range**: Always 1-7, where 1 represents the first day of the week
//! - **Default first day**: Sunday (vbSunday = 1) if not specified
//! - **Null handling**: Returns Null if date contains Null
//! - **Date parsing**: Accepts various date formats (strings, numbers, Date types)
//! - **Zero-based alternative**: Use `(Weekday(date) - 1)` for 0-6 range if needed
//! - **System setting**: vbUseSystem (0) uses Windows regional settings
//! - **International support**: firstdayofweek allows cultural calendar preferences
//! - **Combine with `DateSerial`**: Calculate specific weekdays
//!
//! ### Understanding Return Values
//! The return value changes based on `firstdayofweek`:
//! - With `vbSunday` (default): Sunday=1, Monday=2, ..., Saturday=7
//! - With `vbMonday`: Monday=1, Tuesday=2, ..., Sunday=7
//! - With `vbTuesday`: Tuesday=1, Wednesday=2, ..., Monday=7
//! - And so on for other starting days
//!
//! ### Common Usage Patterns
//! - **Weekend detection**: `Weekday(date) = vbSaturday Or Weekday(date) = vbSunday`
//! - **Weekday detection**: `Weekday(date) >= vbMonday And Weekday(date) <= vbFriday`
//! - **Specific day check**: `Weekday(date) = vbMonday`
//! - **ISO week (Monday start)**: Use `Weekday(date, vbMonday)`
//!
//! ## Typical Uses
//! 1. **Weekend Detection**: Determine if a date is Saturday or Sunday
//! 2. **Business Day Calculation**: Check if date is a weekday
//! 3. **Schedule Planning**: Plan events for specific days of the week
//! 4. **Report Grouping**: Group data by day of week
//! 5. **Calendar Display**: Format calendars with proper day alignment
//! 6. **Work Week Calculations**: Calculate working days
//! 7. **Day Name Display**: Get day name with `WeekdayName` function
//! 8. **Date Validation**: Ensure dates fall on specific days
//!
//! ## Basic Examples
//!
//! ### Example 1: Check if Date is Weekend
//! ```vb6
//! Function IsWeekend(checkDate As Date) As Boolean
//! Dim dayNum As Integer
//! dayNum = Weekday(checkDate)
//! IsWeekend = (dayNum = vbSaturday Or dayNum = vbSunday)
//! End Function
//!
//! ' Usage:
//! If IsWeekend(Date) Then
//! MsgBox "It's the weekend!"
//! End If
//! ```
//!
//! ### Example 2: Get Day Name
//! ```vb6
//! Function GetDayName(checkDate As Date) As String
//! Select Case Weekday(checkDate)
//! Case vbSunday
//! GetDayName = "Sunday"
//! Case vbMonday
//! GetDayName = "Monday"
//! Case vbTuesday
//! GetDayName = "Tuesday"
//! Case vbWednesday
//! GetDayName = "Wednesday"
//! Case vbThursday
//! GetDayName = "Thursday"
//! Case vbFriday
//! GetDayName = "Friday"
//! Case vbSaturday
//! GetDayName = "Saturday"
//! End Select
//! End Function
//! ```
//!
//! ### Example 3: Find Next Monday
//! ```vb6
//! Function GetNextMonday(fromDate As Date) As Date
//! Dim daysToAdd As Integer
//! Dim currentDay As Integer
//!
//! currentDay = Weekday(fromDate)
//!
//! If currentDay = vbMonday Then
//! daysToAdd = 7 ' Next Monday is 7 days away
//! ElseIf currentDay < vbMonday Then
//! daysToAdd = vbMonday - currentDay
//! Else
//! daysToAdd = 7 - (currentDay - vbMonday)
//! End If
//!
//! GetNextMonday = fromDate + daysToAdd
//! End Function
//! ```
//!
//! ### Example 4: Count Weekdays in Month
//! ```vb6
//! Function CountWeekdaysInMonth(year As Integer, month As Integer) As Integer
//! Dim currentDate As Date
//! Dim lastDay As Integer
//! Dim day As Integer
//! Dim count As Integer
//!
//! lastDay = Day(DateSerial(year, month + 1, 0))
//! count = 0
//!
//! For day = 1 To lastDay
//! currentDate = DateSerial(year, month, day)
//! If Weekday(currentDate) >= vbMonday And Weekday(currentDate) <= vbFriday Then
//! count = count + 1
//! End If
//! Next day
//!
//! CountWeekdaysInMonth = count
//! End Function
//! ```
//!
//! ## Common Patterns
//!
//! ### Pattern 1: Is Business Day
//! ```vb6
//! Function IsBusinessDay(checkDate As Date) As Boolean
//! Dim dayNum As Integer
//! dayNum = Weekday(checkDate)
//! IsBusinessDay = (dayNum >= vbMonday And dayNum <= vbFriday)
//! End Function
//! ```
//!
//! ### Pattern 2: Get Week Start (Monday)
//! ```vb6
//! Function GetWeekStart(anyDate As Date) As Date
//! Dim dayNum As Integer
//! dayNum = Weekday(anyDate, vbMonday)
//! GetWeekStart = anyDate - (dayNum - 1)
//! End Function
//! ```
//!
//! ### Pattern 3: Get Week End (Sunday)
//! ```vb6
//! Function GetWeekEnd(anyDate As Date) As Date
//! Dim dayNum As Integer
//! dayNum = Weekday(anyDate, vbMonday)
//! GetWeekEnd = anyDate + (7 - dayNum)
//! End Function
//! ```
//!
//! ### Pattern 4: Days Until Specific Weekday
//! ```vb6
//! Function DaysUntilWeekday(fromDate As Date, targetDay As Integer) As Integer
//! Dim currentDay As Integer
//! currentDay = Weekday(fromDate)
//!
//! If targetDay >= currentDay Then
//! DaysUntilWeekday = targetDay - currentDay
//! Else
//! DaysUntilWeekday = 7 - (currentDay - targetDay)
//! End If
//! End Function
//! ```
//!
//! ### Pattern 5: Is Specific Day
//! ```vb6
//! Function IsMonday(checkDate As Date) As Boolean
//! IsMonday = (Weekday(checkDate) = vbMonday)
//! End Function
//!
//! Function IsFriday(checkDate As Date) As Boolean
//! IsFriday = (Weekday(checkDate) = vbFriday)
//! End Function
//! ```
//!
//! ### Pattern 6: Add Business Days
//! ```vb6
//! Function AddBusinessDays(startDate As Date, daysToAdd As Integer) As Date
//! Dim currentDate As Date
//! Dim daysAdded As Integer
//!
//! currentDate = startDate
//! daysAdded = 0
//!
//! Do While daysAdded < daysToAdd
//! currentDate = currentDate + 1
//! If Weekday(currentDate) >= vbMonday And Weekday(currentDate) <= vbFriday Then
//! daysAdded = daysAdded + 1
//! End If
//! Loop
//!
//! AddBusinessDays = currentDate
//! End Function
//! ```
//!
//! ### Pattern 7: Group by Day of Week
//! ```vb6
//! Function GetDayOfWeekGroup(checkDate As Date) As String
//! Select Case Weekday(checkDate)
//! Case vbMonday, vbWednesday, vbFriday
//! GetDayOfWeekGroup = "MWF"
//! Case vbTuesday, vbThursday
//! GetDayOfWeekGroup = "TTh"
//! Case vbSaturday, vbSunday
//! GetDayOfWeekGroup = "Weekend"
//! End Select
//! End Function
//! ```
//!
//! ### Pattern 8: Calculate Days in Same Week
//! ```vb6
//! Function AreSameWeek(date1 As Date, date2 As Date) As Boolean
//! Dim week1Start As Date
//! Dim week2Start As Date
//!
//! week1Start = date1 - (Weekday(date1, vbMonday) - 1)
//! week2Start = date2 - (Weekday(date2, vbMonday) - 1)
//!
//! AreSameWeek = (week1Start = week2Start)
//! End Function
//! ```
//!
//! ### Pattern 9: Next Occurrence of Weekday
//! ```vb6
//! Function NextOccurrenceOf(targetDay As Integer, Optional fromDate As Date) As Date
//! Dim startDate As Date
//! Dim daysToAdd As Integer
//!
//! If fromDate = 0 Then startDate = Date Else startDate = fromDate
//!
//! daysToAdd = DaysUntilWeekday(startDate, targetDay)
//! If daysToAdd = 0 Then daysToAdd = 7 ' Next occurrence
//!
//! NextOccurrenceOf = startDate + daysToAdd
//! End Function
//! ```
//!
//! ### Pattern 10: Weekend Days in Range
//! ```vb6
//! Function CountWeekendDays(startDate As Date, endDate As Date) As Integer
//! Dim currentDate As Date
//! Dim count As Integer
//!
//! count = 0
//! currentDate = startDate
//!
//! Do While currentDate <= endDate
//! If Weekday(currentDate) = vbSaturday Or Weekday(currentDate) = vbSunday Then
//! count = count + 1
//! End If
//! currentDate = currentDate + 1
//! Loop
//!
//! CountWeekendDays = count
//! End Function
//! ```
//!
//! ## Advanced Usage
//!
//! ### Example 1: Business Day Calculator Class
//! ```vb6
//! ' Class: BusinessDayCalculator
//! ' Calculates business days excluding weekends and holidays
//! Option Explicit
//!
//! Private m_Holidays() As Date
//! Private m_HolidayCount As Integer
//!
//! Public Sub Initialize()
//! m_HolidayCount = 0
//! ReDim m_Holidays(0 To 9)
//! End Sub
//!
//! Public Sub AddHoliday(holidayDate As Date)
//! If m_HolidayCount > UBound(m_Holidays) Then
//! ReDim Preserve m_Holidays(0 To UBound(m_Holidays) * 2)
//! End If
//!
//! m_Holidays(m_HolidayCount) = holidayDate
//! m_HolidayCount = m_HolidayCount + 1
//! End Sub
//!
//! Public Function IsBusinessDay(checkDate As Date) As Boolean
//! Dim i As Integer
//!
//! ' Check if weekend
//! If Weekday(checkDate) = vbSaturday Or Weekday(checkDate) = vbSunday Then
//! IsBusinessDay = False
//! Exit Function
//! End If
//!
//! ' Check if holiday
//! For i = 0 To m_HolidayCount - 1
//! If Int(m_Holidays(i)) = Int(checkDate) Then
//! IsBusinessDay = False
//! Exit Function
//! End If
//! Next i
//!
//! IsBusinessDay = True
//! End Function
//!
//! Public Function CountBusinessDays(startDate As Date, endDate As Date) As Integer
//! Dim currentDate As Date
//! Dim count As Integer
//!
//! count = 0
//! currentDate = startDate
//!
//! Do While currentDate <= endDate
//! If IsBusinessDay(currentDate) Then
//! count = count + 1
//! End If
//! currentDate = currentDate + 1
//! Loop
//!
//! CountBusinessDays = count
//! End Function
//!
//! Public Function AddBusinessDays(startDate As Date, daysToAdd As Integer) As Date
//! Dim currentDate As Date
//! Dim daysAdded As Integer
//!
//! currentDate = startDate
//! daysAdded = 0
//!
//! Do While daysAdded < daysToAdd
//! currentDate = currentDate + 1
//! If IsBusinessDay(currentDate) Then
//! daysAdded = daysAdded + 1
//! End If
//! Loop
//!
//! AddBusinessDays = currentDate
//! End Function
//! ```
//!
//! ### Example 2: Week Navigator Module
//! ```vb6
//! ' Module: WeekNavigator
//! ' Navigate by weeks with different starting days
//! Option Explicit
//!
//! Public Function GetWeekStart(anyDate As Date, _
//! Optional firstDayOfWeek As VbDayOfWeek = vbMonday) As Date
//! Dim dayNum As Integer
//! dayNum = Weekday(anyDate, firstDayOfWeek)
//! GetWeekStart = anyDate - (dayNum - 1)
//! End Function
//!
//! Public Function GetWeekEnd(anyDate As Date, _
//! Optional firstDayOfWeek As VbDayOfWeek = vbMonday) As Date
//! Dim dayNum As Integer
//! dayNum = Weekday(anyDate, firstDayOfWeek)
//! GetWeekEnd = anyDate + (7 - dayNum)
//! End Function
//!
//! Public Function GetPreviousWeekStart(anyDate As Date, _
//! Optional firstDayOfWeek As VbDayOfWeek = vbMonday) As Date
//! GetPreviousWeekStart = GetWeekStart(anyDate - 7, firstDayOfWeek)
//! End Function
//!
//! Public Function GetNextWeekStart(anyDate As Date, _
//! Optional firstDayOfWeek As VbDayOfWeek = vbMonday) As Date
//! GetNextWeekStart = GetWeekStart(anyDate + 7, firstDayOfWeek)
//! End Function
//!
//! Public Function GetDaysInWeek(weekStartDate As Date, _
//! Optional firstDayOfWeek As VbDayOfWeek = vbMonday) As Date()
//! Dim days(0 To 6) As Date
//! Dim i As Integer
//! Dim startDate As Date
//!
//! startDate = GetWeekStart(weekStartDate, firstDayOfWeek)
//!
//! For i = 0 To 6
//! days(i) = startDate + i
//! Next i
//!
//! GetDaysInWeek = days
//! End Function
//! ```
//!
//! ### Example 3: Schedule Analyzer Class
//! ```vb6
//! ' Class: ScheduleAnalyzer
//! ' Analyzes date schedules and patterns
//! Option Explicit
//!
//! Public Function GetDayDistribution(dates() As Date) As Variant
//! Dim distribution(1 To 7) As Integer
//! Dim i As Long
//! Dim dayNum As Integer
//!
//! For i = LBound(dates) To UBound(dates)
//! dayNum = Weekday(dates(i))
//! distribution(dayNum) = distribution(dayNum) + 1
//! Next i
//!
//! GetDayDistribution = distribution
//! End Function
//!
//! Public Function GetMostCommonDay(dates() As Date) As Integer
//! Dim distribution As Variant
//! Dim maxCount As Integer
//! Dim mostCommonDay As Integer
//! Dim i As Integer
//!
//! distribution = GetDayDistribution(dates)
//! maxCount = 0
//! mostCommonDay = vbSunday
//!
//! For i = 1 To 7
//! If distribution(i) > maxCount Then
//! maxCount = distribution(i)
//! mostCommonDay = i
//! End If
//! Next i
//!
//! GetMostCommonDay = mostCommonDay
//! End Function
//!
//! Public Function FilterByWeekday(dates() As Date, targetDay As Integer) As Date()
//! Dim result() As Date
//! Dim count As Long
//! Dim i As Long
//!
//! count = 0
//! For i = LBound(dates) To UBound(dates)
//! If Weekday(dates(i)) = targetDay Then
//! ReDim Preserve result(0 To count)
//! result(count) = dates(i)
//! count = count + 1
//! End If
//! Next i
//!
//! FilterByWeekday = result
//! End Function
//!
//! Public Function IsRecurringPattern(dates() As Date, dayOfWeek As Integer) As Boolean
//! Dim i As Long
//!
//! IsRecurringPattern = True
//! For i = LBound(dates) To UBound(dates)
//! If Weekday(dates(i)) <> dayOfWeek Then
//! IsRecurringPattern = False
//! Exit Function
//! End If
//! Next i
//! End Function
//! ```
//!
//! ### Example 4: Calendar Generator Module
//! ```vb6
//! ' Module: CalendarGenerator
//! ' Generates calendar grids and displays
//! Option Explicit
//!
//! Public Function GenerateMonthCalendar(year As Integer, month As Integer, _
//! Optional firstDayOfWeek As VbDayOfWeek = vbSunday) As Variant
//! Dim calendar(0 To 5, 0 To 6) As Variant
//! Dim firstDay As Date
//! Dim lastDay As Date
//! Dim currentDate As Date
//! Dim row As Integer
//! Dim col As Integer
//! Dim dayNum As Integer
//!
//! firstDay = DateSerial(year, month, 1)
//! lastDay = DateSerial(year, month + 1, 0)
//!
//! ' Initialize calendar with empty values
//! For row = 0 To 5
//! For col = 0 To 6
//! calendar(row, col) = ""
//! Next col
//! Next row
//!
//! ' Fill in the days
//! currentDate = firstDay
//! Do While currentDate <= lastDay
//! dayNum = Weekday(currentDate, firstDayOfWeek) - 1
//! row = (Day(currentDate) + Weekday(firstDay, firstDayOfWeek) - 2) \ 7
//! col = dayNum
//! calendar(row, col) = Day(currentDate)
//! currentDate = currentDate + 1
//! Loop
//!
//! GenerateMonthCalendar = calendar
//! End Function
//!
//! Public Function GetWeekNumbers(year As Integer, month As Integer) As Integer()
//! Dim firstDay As Date
//! Dim lastDay As Date
//! Dim currentDate As Date
//! Dim weekNums() As Integer
//! Dim count As Integer
//!
//! firstDay = DateSerial(year, month, 1)
//! lastDay = DateSerial(year, month + 1, 0)
//!
//! count = 0
//! currentDate = firstDay
//!
//! Do While currentDate <= lastDay
//! If Weekday(currentDate, vbMonday) = 1 Then
//! ReDim Preserve weekNums(0 To count)
//! weekNums(count) = DatePart("ww", currentDate, vbMonday, vbFirstFourDays)
//! count = count + 1
//! End If
//! currentDate = currentDate + 1
//! Loop
//!
//! GetWeekNumbers = weekNums
//! End Function
//! ```
//!
//! ## Error Handling
//! The `Weekday` function can raise the following errors:
//!
//! - **Error 13 (Type mismatch)**: If date argument cannot be interpreted as a date
//! - **Error 5 (Invalid procedure call or argument)**: If firstdayofweek is not between 0 and 7
//! - **Error 6 (Overflow)**: If date value is too large or too small
//!
//! ## Performance Notes
//! - Very fast operation - direct calculation from date value
//! - No performance difference between firstdayofweek values
//! - Constant time O(1) operation
//! - Can be called repeatedly without performance concerns
//! - Consider caching result if used multiple times with same date
//!
//! ## Best Practices
//! 1. **Use named constants** (vbMonday, vbSunday, etc.) instead of numeric values for clarity
//! 2. **Specify firstdayofweek** explicitly when week start matters (especially for ISO weeks)
//! 3. **Cache results** when calling repeatedly with same date
//! 4. **Validate date input** before calling Weekday to avoid errors
//! 5. **Use `WeekdayName`** function to get localized day names
//! 6. **Document assumptions** about which day starts the week in your code
//! 7. **Consider time zones** when working with date/time values
//! 8. **Test boundary cases** (month/year boundaries, leap years)
//! 9. **Use with `DateAdd`** for complex date arithmetic
//! 10. **Handle Null values** explicitly when working with Variant dates
//!
//! ## Comparison Table
//!
//! | Function | Purpose | Returns | Notes |
//! |----------|---------|---------|-------|
//! | `Weekday` | Get day of week number | Integer (1-7) | Configurable week start |
//! | `WeekdayName` | Get day name | String | Localized, abbreviated option |
//! | `Day` | Get day of month | Integer (1-31) | Calendar day number |
//! | `DatePart` | Get date part | Variant | More general, includes "w" for weekday |
//!
//! ## Platform Notes
//! - Available in VB6, VBA, and `VBScript`
//! - Behavior consistent across platforms
//! - Returns Integer (can be stored in Integer or Long)
//! - System locale affects vbUseSystem behavior
//! - Date range: January 1, 100 to December 31, 9999
//!
//! ## Limitations
//! - Cannot directly return day name (use `WeekdayName` for that)
//! - Return value always 1-7 (no zero-based option)
//! - Cannot specify custom week numbering systems
//! - Does not account for holidays or business days
//! - No built-in ISO 8601 week numbering (use DatePart("ww", ...) for that)
//! - Cannot calculate week of year (use `DatePart` for that)
use ;
use crate;
use crate;
/// Implementation of the `Weekday` function.
///
/// VB6 behavior:
/// - a `Null` date returns `Null`
/// - the day of week is derived from the date serial, so the time portion of
/// a datetime value is ignored
/// - the result is an `Integer` from 1 to 7, where 1 is the first day of the
/// week; the default (`vbSunday`, or `vbUseSystem`) numbers Sunday = 1
/// - `firstdayofweek` accepts `vbUseSystem` (0) through `vbSaturday` (7);
/// any other value raises error 5 (invalid procedure call)
/// - a value that cannot be interpreted as a date raises error 13 (type
/// mismatch)