vb6parse 1.0.1

vb6parse is a library for parsing and analyzing VB6 code, from projects, to controls, to modules, and forms.
Documentation
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
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
//! # `Hour` Function
//!
//! Returns an Integer specifying a whole number between 0 and 23, inclusive, representing the hour of the day.
//!
//! ## Syntax
//!
//! ```vb
//! Hour(time)
//! ```
//!
//! ## Parameters
//!
//! - `time` (Required): Any `Variant`, numeric expression, string expression, or any combination that can represent a time. If `time` contains `Null`, `Null` is returned.
//!
//! ## Return Value
//!
//! Returns an `Integer` from 0 to 23 representing the hour of the day. The hour is returned in 24-hour format (0 = midnight, 23 = 11 PM).
//!
//! ## Remarks
//!
//! The `Hour` function extracts the hour component from a date/time value:
//!
//! - Returns values from 0 (midnight) to 23 (11 PM)
//! - Uses 24-hour format, not 12-hour AM/PM format
//! - If `time` is `Null`, the function returns `Null`
//! - If `time` contains only a date with no time component, returns 0
//! - Works with `Date` variables, time strings, and numeric date/time values
//! - Can be used with `Now`, `Time`, `TimeValue`, and other date/time functions
//! - For 12-hour format with AM/PM, use `Format$` function instead
//! - Complements `Minute` and `Second` functions for complete time extraction
//!
//! ## Typical Uses
//!
//! 1. **Time-Based Logic**: Determine if an event occurred during business hours
//! 2. **Scheduling**: Check if current time is within a specific hour range
//! 3. **Data Analysis**: Analyze activity patterns by hour of day
//! 4. **Logging**: Extract hour from timestamp for categorization
//! 5. **User Interface**: Display hour portion of time separately
//! 6. **Time Validation**: Verify time values fall within expected ranges
//!
//! ## Basic Usage Examples
//!
//! ```vb
//! ' Example 1: Get current hour
//! Dim currentHour As Integer
//! currentHour = Hour(Now)
//! Debug.Print "Current hour: " & currentHour
//!
//! ' Example 2: Extract hour from time string
//! Dim h As Integer
//! h = Hour("14:30:00")    ' Returns 14 (2 PM)
//!
//! ' Example 3: Check for business hours
//! If Hour(Now) >= 9 And Hour(Now) < 17 Then
//!     Debug.Print "Within business hours"
//! End If
//!
//! ' Example 4: Get hour from Date variable
//! Dim myDate As Date
//! myDate = #1/15/2024 3:45:00 PM#
//! Debug.Print Hour(myDate)    ' Returns 15
//! ```
//!
//! ## Common Patterns
//!
//! ```vb
//! ' Pattern 1: Check if current time is within business hours
//! Function IsBusinessHours() As Boolean
//!     Dim h As Integer
//!     h = Hour(Now)
//!     IsBusinessHours = (h >= 9 And h < 17)
//! End Function
//!
//! ' Pattern 2: Categorize time of day
//! Function GetTimeOfDay() As String
//!     Dim h As Integer
//!     h = Hour(Now)
//!     
//!     If h >= 0 And h < 6 Then
//!         GetTimeOfDay = "Night"
//!     ElseIf h >= 6 And h < 12 Then
//!         GetTimeOfDay = "Morning"
//!     ElseIf h >= 12 And h < 18 Then
//!         GetTimeOfDay = "Afternoon"
//!     Else
//!         GetTimeOfDay = "Evening"
//!     End If
//! End Function
//!
//! ' Pattern 3: Format time in 12-hour format with AM/PM
//! Function Format12Hour(timeValue As Date) As String
//!     Dim h As Integer
//!     Dim ampm As String
//!     
//!     h = Hour(timeValue)
//!     
//!     If h >= 12 Then
//!         ampm = "PM"
//!         If h > 12 Then h = h - 12
//!     Else
//!         ampm = "AM"
//!         If h = 0 Then h = 12
//!     End If
//!     
//!     Format12Hour = h & ":" & Right$("0" & Minute(timeValue), 2) & " " & ampm
//! End Function
//!
//! ' Pattern 4: Round time to nearest hour
//! Function RoundToNearestHour(timeValue As Date) As Date
//!     If Minute(timeValue) >= 30 Then
//!         RoundToNearestHour = DateSerial(Year(timeValue), Month(timeValue), Day(timeValue)) + _
//!                              TimeSerial(Hour(timeValue) + 1, 0, 0)
//!     Else
//!         RoundToNearestHour = DateSerial(Year(timeValue), Month(timeValue), Day(timeValue)) + _
//!                              TimeSerial(Hour(timeValue), 0, 0)
//!     End If
//! End Function
//!
//! ' Pattern 5: Calculate hours elapsed
//! Function HoursElapsed(startTime As Date, endTime As Date) As Integer
//!     Dim totalHours As Double
//!     totalHours = (endTime - startTime) * 24
//!     HoursElapsed = Int(totalHours)
//! End Function
//!
//! ' Pattern 6: Check if after specific hour
//! Function IsAfterHour(checkTime As Date, hourThreshold As Integer) As Boolean
//!     IsAfterHour = (Hour(checkTime) >= hourThreshold)
//! End Function
//!
//! ' Pattern 7: Get hour range description
//! Function GetHourRange(timeValue As Date) As String
//!     Dim h As Integer
//!     h = Hour(timeValue)
//!     GetHourRange = h & ":00 - " & h & ":59"
//! End Function
//!
//! ' Pattern 8: Validate time is within allowed hours
//! Function IsWithinAllowedHours(checkTime As Date, startHour As Integer, endHour As Integer) As Boolean
//!     Dim h As Integer
//!     h = Hour(checkTime)
//!     
//!     If startHour <= endHour Then
//!         IsWithinAllowedHours = (h >= startHour And h <= endHour)
//!     Else
//!         ' Handle overnight range (e.g., 22:00 to 6:00)
//!         IsWithinAllowedHours = (h >= startHour Or h <= endHour)
//!     End If
//! End Function
//!
//! ' Pattern 9: Count hourly occurrences
//! Sub CountByHour(timestamps() As Date, hourCounts() As Long)
//!     Dim i As Long
//!     Dim h As Integer
//!     
//!     ReDim hourCounts(0 To 23)
//!     
//!     For i = LBound(timestamps) To UBound(timestamps)
//!         h = Hour(timestamps(i))
//!         hourCounts(h) = hourCounts(h) + 1
//!     Next i
//! End Sub
//!
//! ' Pattern 10: Create time from hour
//! Function CreateTimeFromHour(hourValue As Integer, Optional minuteValue As Integer = 0) As Date
//!     CreateTimeFromHour = TimeSerial(hourValue, minuteValue, 0)
//! End Function
//! ```
//!
//! ## Advanced Usage Examples
//!
//! ```vb
//! ' Example 1: Business hours scheduler
//! Public Class BusinessScheduler
//!     Private Const BUSINESS_START As Integer = 9
//!     Private Const BUSINESS_END As Integer = 17
//!     Private Const LUNCH_START As Integer = 12
//!     Private Const LUNCH_END As Integer = 13
//!     
//!     Public Function IsAvailable(checkTime As Date) As Boolean
//!         Dim h As Integer
//!         h = Hour(checkTime)
//!         
//!         If h < BUSINESS_START Or h >= BUSINESS_END Then
//!             IsAvailable = False
//!         ElseIf h >= LUNCH_START And h < LUNCH_END Then
//!             IsAvailable = False
//!         Else
//!             IsAvailable = True
//!         End If
//!     End Function
//!     
//!     Public Function GetNextAvailableSlot(currentTime As Date) As Date
//!         Dim h As Integer
//!         Dim nextSlot As Date
//!         
//!         h = Hour(currentTime)
//!         
//!         If h < BUSINESS_START Then
//!             nextSlot = DateSerial(Year(currentTime), Month(currentTime), Day(currentTime)) + _
//!                        TimeSerial(BUSINESS_START, 0, 0)
//!         ElseIf h >= LUNCH_START And h < LUNCH_END Then
//!             nextSlot = DateSerial(Year(currentTime), Month(currentTime), Day(currentTime)) + _
//!                        TimeSerial(LUNCH_END, 0, 0)
//!         ElseIf h >= BUSINESS_END Then
//!             nextSlot = DateSerial(Year(currentTime), Month(currentTime), Day(currentTime) + 1) + _
//!                        TimeSerial(BUSINESS_START, 0, 0)
//!         Else
//!             nextSlot = currentTime
//!         End If
//!         
//!         GetNextAvailableSlot = nextSlot
//!     End Function
//! End Class
//!
//! ' Example 2: Hourly activity analyzer
//! Public Class ActivityAnalyzer
//!     Private m_hourlyData(0 To 23) As Long
//!     
//!     Public Sub RecordActivity(activityTime As Date)
//!         Dim h As Integer
//!         h = Hour(activityTime)
//!         m_hourlyData(h) = m_hourlyData(h) + 1
//!     End Sub
//!     
//!     Public Function GetPeakHour() As Integer
//!         Dim i As Integer
//!         Dim maxCount As Long
//!         Dim peakHour As Integer
//!         
//!         maxCount = 0
//!         peakHour = 0
//!         
//!         For i = 0 To 23
//!             If m_hourlyData(i) > maxCount Then
//!                 maxCount = m_hourlyData(i)
//!                 peakHour = i
//!             End If
//!         Next i
//!         
//!         GetPeakHour = peakHour
//!     End Function
//!     
//!     Public Function GetActivityInRange(startHour As Integer, endHour As Integer) As Long
//!         Dim i As Integer
//!         Dim total As Long
//!         
//!         total = 0
//!         For i = startHour To endHour
//!             total = total + m_hourlyData(i)
//!         Next i
//!         
//!         GetActivityInRange = total
//!     End Function
//! End Class
//!
//! ' Example 3: Time slot manager
//! Public Class TimeSlotManager
//!     Private Type TimeSlot
//!         StartHour As Integer
//!         EndHour As Integer
//!         IsAvailable As Boolean
//!     End Type
//!     
//!     Private m_slots() As TimeSlot
//!     
//!     Public Sub Initialize()
//!         Dim i As Integer
//!         ReDim m_slots(0 To 23)
//!         
//!         For i = 0 To 23
//!             m_slots(i).StartHour = i
//!             m_slots(i).EndHour = i
//!             m_slots(i).IsAvailable = True
//!         Next i
//!     End Sub
//!     
//!     Public Function BookSlot(bookingTime As Date) As Boolean
//!         Dim h As Integer
//!         h = Hour(bookingTime)
//!         
//!         If m_slots(h).IsAvailable Then
//!             m_slots(h).IsAvailable = False
//!             BookSlot = True
//!         Else
//!             BookSlot = False
//!         End If
//!     End Function
//!     
//!     Public Function FindNextAvailable(afterTime As Date) As Integer
//!         Dim h As Integer
//!         Dim i As Integer
//!         
//!         h = Hour(afterTime)
//!         
//!         For i = h To 23
//!             If m_slots(i).IsAvailable Then
//!                 FindNextAvailable = i
//!                 Exit Function
//!             End If
//!         Next i
//!         
//!         FindNextAvailable = -1  ' No available slots
//!     End Function
//! End Class
//!
//! ' Example 4: Shift time calculator
//! Public Function CalculateShiftHours(clockIn As Date, clockOut As Date) As Double
//!     Dim totalHours As Double
//!     Dim inHour As Integer
//!     Dim outHour As Integer
//!     
//!     inHour = Hour(clockIn)
//!     outHour = Hour(clockOut)
//!     
//!     If clockOut < clockIn Then
//!         ' Overnight shift
//!         totalHours = (clockOut + 1 - clockIn) * 24
//!     Else
//!         totalHours = (clockOut - clockIn) * 24
//!     End If
//!     
//!     CalculateShiftHours = totalHours
//! End Function
//! ```
//!
//! ## Error Handling
//!
//! The Hour function can raise errors in certain situations:
//!
//! - **Type Mismatch (Error 13)**: If the argument cannot be interpreted as a date/time value
//! - **Invalid Procedure Call (Error 5)**: If the date value is invalid
//! - **Null Propagation**: If the argument is `Null`, the function returns `Null` (not an error)
//!
//! ```vb
//! On Error Resume Next
//! Dim h As Integer
//! h = Hour(someValue)
//! If Err.Number <> 0 Then
//!     Debug.Print "Error extracting hour: " & Err.Description
//!     h = 0  ' Default value
//!     Err.Clear
//! End If
//! On Error GoTo 0
//! ```
//!
//! ## Performance Considerations
//!
//! - **Fast Operation**: Hour extraction is a very fast, native operation
//! - **No Overhead**: Minimal performance impact even in tight loops
//! - **Caching**: If checking the same time repeatedly, cache the `Hour()` result
//! - **Comparison**: Direct `Hour()` comparisons are faster than full time comparisons
//!
//! ## Best Practices
//!
//! 1. **24-Hour Format**: Remember `Hour` returns 0-23, not 1-12 with AM/PM
//! 2. **Midnight**: `Hour(#12:00:00 AM#)` returns 0, not 12
//! 3. **Noon**: `Hour(#12:00:00 PM#)` returns 12
//! 4. **Validation**: Validate hour ranges (0-23) when accepting user input
//! 5. **Date-Only Values**: The hour component of a date-only value (no time) is always 0
//! 6. **Null Handling**: Check for `Null` when working with `Variant` date values
//! 7. **Time Zones**: `Hour` doesn't handle time zones; use explicit conversion if needed
//!
//! ## Comparison with Other Functions
//!
//! | Function | Purpose | Return Range |
//! |----------|---------|--------------|
//! | `Hour` | Extract hour from time | 0-23 (24-hour) |
//! | `Minute` | Extract minute from time | 0-59 |
//! | `Second` | Extract second from time | 0-59 |
//! | `Day` | Extract day from date | 1-31 |
//! | `Month` | Extract month from date | 1-12 |
//! | `Year` | Extract year from date | 100-9999 |
//! | `Weekday` | Get day of week | 1-7 |
//!
//! ## Conversion Examples
//!
//! ```vb
//! ' Convert 24-hour to 12-hour with AM/PM
//! Function To12Hour(hour24 As Integer) As String
//!     Dim hour12 As Integer
//!     Dim ampm As String
//!     
//!     If hour24 >= 12 Then
//!         ampm = "PM"
//!         hour12 = IIf(hour24 = 12, 12, hour24 - 12)
//!     Else
//!         ampm = "AM"
//!         hour12 = IIf(hour24 = 0, 12, hour24)
//!     End If
//!     
//!     To12Hour = hour12 & " " & ampm
//! End Function
//!
//! ' Convert 12-hour to 24-hour
//! Function To24Hour(hour12 As Integer, isPM As Boolean) As Integer
//!     If isPM Then
//!         To24Hour = IIf(hour12 = 12, 12, hour12 + 12)
//!     Else
//!         To24Hour = IIf(hour12 = 12, 0, hour12)
//!     End If
//! End Function
//! ```
//!
//! ## Platform and Version Notes
//!
//! - Available in all VB6 versions
//! - Consistent behavior across Windows platforms
//! - Uses system locale for time interpretation when parsing strings
//! - Returns Integer (2-byte signed integer, range: -32,768 to 32,767)
//!
//! ## Limitations
//!
//! - Returns 24-hour format only (0-23)
//! - No built-in AM/PM support (use Format$ for that)
//! - Cannot extract fractional hours (use full date arithmetic for precision)
//! - No time zone awareness (always uses local time interpretation)
//! - Date-only values always return hour 0
//! - Cannot handle dates before 1/1/100 or after 12/31/9999
//!
//! ## Related Functions
//!
//! - `Minute`: Returns the minute of the hour (0-59)
//! - `Second`: Returns the second of the minute (0-59)
//! - `Now`: Returns the current date and time
//! - `Time`: Returns the current system time
//! - `TimeSerial`: Returns a Date for a specified hour, minute, and second
//! - `TimeValue`: Converts a string to a time value
//! - `Format`: Formats a date/time with custom formatting including AM/PM

#[cfg(test)]
mod tests {
    use crate::*;

    #[test]
    fn hour_basic() {
        let source = r"
Sub Test()
    h = Hour(Now)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");
        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/datetime/hour");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn hour_in_function() {
        let source = r"
Function GetCurrentHour() As Integer
    GetCurrentHour = Hour(Now)
End Function
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");
        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/datetime/hour");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn hour_if_statement() {
        let source = r#"
Sub Test()
    If Hour(Now) >= 9 And Hour(Now) < 17 Then
        Debug.Print "Business hours"
    End If
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");
        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/datetime/hour");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn hour_debug_print() {
        let source = r"
Sub Test()
    Debug.Print Hour(Time)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");
        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/datetime/hour");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn hour_select_case() {
        let source = r#"
Sub Test()
    Select Case Hour(Now)
        Case 0 To 5
            Debug.Print "Night"
        Case 6 To 11
            Debug.Print "Morning"
        Case Else
            Debug.Print "Afternoon/Evening"
    End Select
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");
        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/datetime/hour");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn hour_for_loop() {
        let source = r"
Sub Test()
    Dim i As Integer
    For i = 0 To 23
        If Hour(Now) = i Then Exit For
    Next i
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");
        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/datetime/hour");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn hour_do_loop() {
        let source = r"
Sub Test()
    Do While Hour(Now) < 17
        DoWork
    Loop
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");
        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/datetime/hour");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn hour_class_member() {
        let source = r"
Private Sub Class_Initialize()
    m_hour = Hour(Now)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");
        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/datetime/hour");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn hour_type_field() {
        let source = r"
Sub Test()
    Dim timeInfo As TimeType
    timeInfo.currentHour = Hour(Now)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");
        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/datetime/hour");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn hour_collection_add() {
        let source = r"
Sub Test()
    Dim col As New Collection
    col.Add Hour(Now)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");
        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/datetime/hour");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn hour_with_statement() {
        let source = r"
Sub Test()
    With timeObject
        .HourValue = Hour(.TimeStamp)
    End With
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");
        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/datetime/hour");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn hour_msgbox() {
        let source = r#"
Sub Test()
    MsgBox "Current hour: " & Hour(Now)
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");
        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/datetime/hour");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn hour_property() {
        let source = r"
Property Get CurrentHour() As Integer
    CurrentHour = Hour(Now)
End Property
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");
        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/datetime/hour");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn hour_concatenation() {
        let source = r#"
Sub Test()
    msg = "The hour is " & Hour(Now)
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");
        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/datetime/hour");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn hour_for_each() {
        let source = r"
Sub Test()
    Dim dt As Variant
    For Each dt In dateCollection
        Debug.Print Hour(dt)
    Next
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");
        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/datetime/hour");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn hour_error_handling() {
        let source = r"
Sub Test()
    On Error Resume Next
    h = Hour(someDate)
    If Err.Number <> 0 Then Err.Clear
    On Error GoTo 0
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");
        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/datetime/hour");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn hour_comparison() {
        let source = r#"
Sub Test()
    If Hour(startTime) < Hour(endTime) Then
        Debug.Print "Same day"
    End If
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");
        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/datetime/hour");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn hour_array_assignment() {
        let source = r"
Sub Test()
    Dim hours(1 To 10) As Integer
    hours(1) = Hour(Now)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");
        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/datetime/hour");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn hour_function_argument() {
        let source = r"
Sub Test()
    ProcessHour Hour(Now)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");
        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/datetime/hour");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn hour_nested_call() {
        let source = r"
Sub Test()
    result = CStr(Hour(Now))
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");
        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/datetime/hour");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn hour_iif() {
        let source = r#"
Sub Test()
    period = IIf(Hour(Now) < 12, "AM", "PM")
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");
        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/datetime/hour");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn hour_time_literal() {
        let source = r"
Sub Test()
    h = Hour(#3:45:00 PM#)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");
        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/datetime/hour");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn hour_variable() {
        let source = r"
Sub Test()
    Dim myTime As Date
    myTime = Now
    h = Hour(myTime)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");
        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/datetime/hour");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn hour_parentheses() {
        let source = r"
Sub Test()
    value = (Hour(Now))
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");
        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/datetime/hour");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn hour_business_logic() {
        let source = r"
Function IsBusinessHours() As Boolean
    Dim h As Integer
    h = Hour(Now)
    IsBusinessHours = (h >= 9 And h < 17)
End Function
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");
        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/datetime/hour");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn hour_time_range() {
        let source = r#"
Sub Test()
    Dim h As Integer
    h = Hour(Now)
    If h >= 0 And h <= 23 Then
        Debug.Print "Valid hour"
    End If
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");
        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/datetime/hour");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn hour_math_operation() {
        let source = r"
Sub Test()
    hoursUntilMidnight = 24 - Hour(Now)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");
        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/datetime/hour");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }
}