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
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
//! VB6 `Time` Function
//!
//! The `Time` function returns a Variant (Date) indicating the current system time.
//!
//! ## Syntax
//! ```vb6
//! Time()
//! ```
//! or
//! ```vb6
//! Time
//! ```
//!
//! ## Parameters
//! None. The `Time` function takes no arguments.
//!
//! ## Returns
//! Returns a `Variant` of subtype `Date` containing the current system time. The date portion is set to zero (December 30, 1899).
//!
//! ## Remarks
//! The `Time` function retrieves the current system time:
//!
//! - **No arguments**: Called without parentheses or with empty parentheses
//! - **Date portion**: Always returns date as zero (12/30/1899)
//! - **Time precision**: Returns time to the nearest second (no milliseconds)
//! - **System dependent**: Returns time from system clock
//! - **Time vs Time$**: `Time` returns Variant (Date), `Time$` returns String in format "HH:MM:SS"
//! - **Now function**: Use `Now()` to get current date and time together
//! - **Date function**: Use `Date()` to get current date only
//! - **Timer function**: Use `Timer` for elapsed time measurements (returns seconds since midnight)
//! - **Setting time**: Use `Time` statement (not function) to set system time
//! - **24-hour format**: Internal representation is 24-hour, but display depends on system settings
//!
//! ### Time vs Related Functions
//! - `Time` - Returns current time only (date portion is zero)
//! - `Date` - Returns current date only (time portion is midnight)
//! - `Now` - Returns current date and time together
//! - `Timer` - Returns seconds elapsed since midnight as Single
//! - `Time$` - Returns current time as formatted String
//!
//! ### Time Components
//! Extract time components using:
//! ```vb6
//! currentHour = Hour(Time)      ' 0-23
//! currentMinute = Minute(Time)  ' 0-59
//! currentSecond = Second(Time)  ' 0-59
//! ```
//!
//! ### Time Arithmetic
//! ```vb6
//! ' Add 1 hour to current time
//! newTime = Time + TimeSerial(1, 0, 0)
//!
//! ' Add 30 minutes to current time
//! newTime = DateAdd("n", 30, Time)
//! ```
//!
//! ## Typical Uses
//! 1. **Timestamp Logging**: Record when events occur
//! 2. **Time-based Triggers**: Check current time for scheduled operations
//! 3. **Time Display**: Show current time in user interface
//! 4. **Performance Timing**: Measure operation duration (though Timer is better)
//! 5. **Time Validation**: Check if operation is within allowed time window
//! 6. **Time Calculations**: Calculate time differences or future times
//! 7. **Scheduling**: Determine if tasks should run now
//! 8. **Time Formatting**: Create custom time displays
//!
//! ## Basic Examples
//!
//! ### Example 1: Display Current Time
//! ```vb6
//! Sub ShowCurrentTime()
//!     MsgBox "Current time is: " & Time
//! End Sub
//! ```
//!
//! ### Example 2: Log Event Time
//! ```vb6
//! Sub LogEvent(eventName As String)
//!     Dim logEntry As String
//!     logEntry = Time & " - " & eventName
//!     Debug.Print logEntry
//! End Sub
//! ```
//!
//! ### Example 3: Check Business Hours
//! ```vb6
//! Function IsBusinessHours() As Boolean
//!     Dim currentHour As Integer
//!     currentHour = Hour(Time)
//!     IsBusinessHours = (currentHour >= 9 And currentHour < 17)
//! End Function
//! ```
//!
//! ### Example 4: Format Time Display
//! ```vb6
//! Function GetFormattedTime() As String
//!     GetFormattedTime = Format$(Time, "hh:mm:ss AM/PM")
//! End Function
//! ```
//!
//! ## Common Patterns
//!
//! ### Pattern 1: Get Current Hour
//! ```vb6
//! Function GetCurrentHour() As Integer
//!     GetCurrentHour = Hour(Time)
//! End Function
//! ```
//!
//! ### Pattern 2: Time-based Greeting
//! ```vb6
//! Function GetGreeting() As String
//!     Dim currentHour As Integer
//!     currentHour = Hour(Time)
//!     
//!     Select Case currentHour
//!         Case 0 To 11
//!             GetGreeting = "Good morning"
//!         Case 12 To 17
//!             GetGreeting = "Good afternoon"
//!         Case Else
//!             GetGreeting = "Good evening"
//!     End Select
//! End Function
//! ```
//!
//! ### Pattern 3: Create Timestamp
//! ```vb6
//! Function CreateTimestamp() As String
//!     CreateTimestamp = Format$(Date, "yyyy-mm-dd") & " " & Format$(Time, "hh:nn:ss")
//! End Function
//! ```
//!
//! ### Pattern 4: Check Time Window
//! ```vb6
//! Function IsWithinTimeWindow(startTime As Date, endTime As Date) As Boolean
//!     Dim currentTime As Date
//!     currentTime = Time
//!     IsWithinTimeWindow = (currentTime >= startTime And currentTime <= endTime)
//! End Function
//! ```
//!
//! ### Pattern 5: Add Time Duration
//! ```vb6
//! Function AddMinutes(minutes As Integer) As Date
//!     AddMinutes = DateAdd("n", minutes, Time)
//! End Function
//! ```
//!
//! ### Pattern 6: Time Until Target
//! ```vb6
//! Function MinutesUntil(targetTime As Date) As Long
//!     MinutesUntil = DateDiff("n", Time, targetTime)
//! End Function
//! ```
//!
//! ### Pattern 7: Round Time to Nearest Interval
//! ```vb6
//! Function RoundToNearest15Minutes() As Date
//!     Dim currentTime As Date
//!     Dim minutes As Integer
//!     
//!     currentTime = Time
//!     minutes = Minute(currentTime)
//!     minutes = ((minutes + 7) \ 15) * 15
//!     
//!     RoundToNearest15Minutes = TimeSerial(Hour(currentTime), minutes, 0)
//! End Function
//! ```
//!
//! ### Pattern 8: Compare Times
//! ```vb6
//! Function IsTimeBefore(compareTime As Date) As Boolean
//!     IsTimeBefore = (Time < compareTime)
//! End Function
//! ```
//!
//! ### Pattern 9: Get Time String
//! ```vb6
//! Function GetTimeString() As String
//!     GetTimeString = Format$(Time, "hh:mm:ss")
//! End Function
//! ```
//!
//! ### Pattern 10: Calculate Elapsed Time
//! ```vb6
//! Function GetElapsedMinutes(startTime As Date) As Long
//!     GetElapsedMinutes = DateDiff("n", startTime, Time)
//! End Function
//! ```
//!
//! ## Advanced Usage
//!
//! ### Example 1: Time Tracker Class
//! ```vb6
//! ' Class: TimeTracker
//! ' Tracks operation start/end times and durations
//! Option Explicit
//!
//! Private m_StartTime As Date
//! Private m_EndTime As Date
//! Private m_IsRunning As Boolean
//!
//! Public Sub StartTracking()
//!     m_StartTime = Time
//!     m_IsRunning = True
//! End Sub
//!
//! Public Sub StopTracking()
//!     If Not m_IsRunning Then
//!         Err.Raise 5, , "Tracking not started"
//!     End If
//!     
//!     m_EndTime = Time
//!     m_IsRunning = False
//! End Sub
//!
//! Public Function GetElapsedMinutes() As Long
//!     If m_IsRunning Then
//!         GetElapsedMinutes = DateDiff("n", m_StartTime, Time)
//!     Else
//!         GetElapsedMinutes = DateDiff("n", m_StartTime, m_EndTime)
//!     End If
//! End Function
//!
//! Public Function GetElapsedSeconds() As Long
//!     If m_IsRunning Then
//!         GetElapsedSeconds = DateDiff("s", m_StartTime, Time)
//!     Else
//!         GetElapsedSeconds = DateDiff("s", m_StartTime, m_EndTime)
//!     End If
//! End Function
//!
//! Public Function GetFormattedDuration() As String
//!     Dim totalSeconds As Long
//!     Dim hours As Long
//!     Dim minutes As Long
//!     Dim seconds As Long
//!     
//!     totalSeconds = GetElapsedSeconds()
//!     hours = totalSeconds \ 3600
//!     minutes = (totalSeconds Mod 3600) \ 60
//!     seconds = totalSeconds Mod 60
//!     
//!     GetFormattedDuration = Format$(hours, "00") & ":" & _
//!                           Format$(minutes, "00") & ":" & _
//!                           Format$(seconds, "00")
//! End Function
//!
//! Public Property Get IsRunning() As Boolean
//!     IsRunning = m_IsRunning
//! End Property
//! ```
//!
//! ### Example 2: Schedule Manager Module
//! ```vb6
//! ' Module: ScheduleManager
//! ' Manages time-based scheduling and windows
//! Option Explicit
//!
//! Public Function IsWithinSchedule(scheduleStart As Date, scheduleEnd As Date) As Boolean
//!     Dim currentTime As Date
//!     currentTime = Time
//!     
//!     ' Handle overnight schedules (e.g., 10 PM to 6 AM)
//!     If scheduleStart > scheduleEnd Then
//!         IsWithinSchedule = (currentTime >= scheduleStart Or currentTime <= scheduleEnd)
//!     Else
//!         IsWithinSchedule = (currentTime >= scheduleStart And currentTime <= scheduleEnd)
//!     End If
//! End Function
//!
//! Public Function GetNextScheduledTime(targetTime As Date) As Date
//!     Dim currentTime As Date
//!     currentTime = Time
//!     
//!     If currentTime < targetTime Then
//!         ' Target time is later today
//!         GetNextScheduledTime = Date + targetTime
//!     Else
//!         ' Target time is tomorrow
//!         GetNextScheduledTime = Date + 1 + targetTime
//!     End If
//! End Function
//!
//! Public Function MinutesUntilSchedule(scheduleTime As Date) As Long
//!     Dim currentTime As Date
//!     Dim targetDateTime As Date
//!     
//!     currentTime = Time
//!     
//!     If currentTime < scheduleTime Then
//!         ' Later today
//!         targetDateTime = Date + scheduleTime
//!     Else
//!         ' Tomorrow
//!         targetDateTime = Date + 1 + scheduleTime
//!     End If
//!     
//!     MinutesUntilSchedule = DateDiff("n", Now, targetDateTime)
//! End Function
//!
//! Public Function FormatTimeRemaining(targetTime As Date) As String
//!     Dim minutesLeft As Long
//!     Dim hours As Long
//!     Dim minutes As Long
//!     
//!     minutesLeft = MinutesUntilSchedule(targetTime)
//!     
//!     If minutesLeft < 0 Then
//!         FormatTimeRemaining = "Overdue"
//!         Exit Function
//!     End If
//!     
//!     hours = minutesLeft \ 60
//!     minutes = minutesLeft Mod 60
//!     
//!     If hours > 0 Then
//!         FormatTimeRemaining = hours & "h " & minutes & "m remaining"
//!     Else
//!         FormatTimeRemaining = minutes & "m remaining"
//!     End If
//! End Function
//! ```
//!
//! ### Example 3: Time Logger Class
//! ```vb6
//! ' Class: TimeLogger
//! ' Logs timestamped events
//! Option Explicit
//!
//! Private m_LogEntries As Collection
//!
//! Private Sub Class_Initialize()
//!     Set m_LogEntries = New Collection
//! End Sub
//!
//! Public Sub LogEvent(eventDescription As String)
//!     Dim logEntry As String
//!     logEntry = Format$(Time, "hh:mm:ss") & " - " & eventDescription
//!     m_LogEntries.Add logEntry
//! End Sub
//!
//! Public Sub LogEventWithDetails(eventName As String, details As String)
//!     Dim logEntry As String
//!     logEntry = Format$(Time, "hh:mm:ss") & " - " & eventName & ": " & details
//!     m_LogEntries.Add logEntry
//! End Sub
//!
//! Public Function GetLogEntries() As String
//!     Dim result As String
//!     Dim entry As Variant
//!     
//!     result = "Event Log:" & vbCrLf
//!     result = result & String$(50, "=") & vbCrLf
//!     
//!     For Each entry In m_LogEntries
//!         result = result & entry & vbCrLf
//!     Next entry
//!     
//!     GetLogEntries = result
//! End Function
//!
//! Public Sub ClearLog()
//!     Set m_LogEntries = New Collection
//! End Sub
//!
//! Public Property Get EntryCount() As Long
//!     EntryCount = m_LogEntries.Count
//! End Property
//!
//! Public Function ExportToFile(filename As String) As Boolean
//!     On Error GoTo ErrorHandler
//!     
//!     Dim fileNum As Integer
//!     Dim entry As Variant
//!     
//!     fileNum = FreeFile
//!     Open filename For Output As #fileNum
//!     
//!     Print #fileNum, "Event Log - " & Format$(Date, "yyyy-mm-dd")
//!     Print #fileNum, String$(50, "=")
//!     
//!     For Each entry In m_LogEntries
//!         Print #fileNum, entry
//!     Next entry
//!     
//!     Close #fileNum
//!     ExportToFile = True
//!     Exit Function
//!     
//! ErrorHandler:
//!     ExportToFile = False
//!     If fileNum > 0 Then Close #fileNum
//! End Function
//! ```
//!
//! ### Example 4: Business Hours Validator Module
//! ```vb6
//! ' Module: BusinessHoursValidator
//! ' Validates and manages business hours
//! Option Explicit
//!
//! Private m_BusinessStart As Date
//! Private m_BusinessEnd As Date
//! Private m_LunchStart As Date
//! Private m_LunchEnd As Date
//!
//! Public Sub Initialize(businessStart As Date, businessEnd As Date, _
//!                      Optional lunchStart As Variant, Optional lunchEnd As Variant)
//!     m_BusinessStart = businessStart
//!     m_BusinessEnd = businessEnd
//!     
//!     If Not IsMissing(lunchStart) Then m_LunchStart = lunchStart
//!     If Not IsMissing(lunchEnd) Then m_LunchEnd = lunchEnd
//! End Sub
//!
//! Public Function IsBusinessHours() As Boolean
//!     Dim currentTime As Date
//!     currentTime = Time
//!     
//!     ' Check if within business hours
//!     If currentTime < m_BusinessStart Or currentTime >= m_BusinessEnd Then
//!         IsBusinessHours = False
//!         Exit Function
//!     End If
//!     
//!     ' Check if during lunch (if configured)
//!     If m_LunchStart > 0 And m_LunchEnd > 0 Then
//!         If currentTime >= m_LunchStart And currentTime < m_LunchEnd Then
//!             IsBusinessHours = False
//!             Exit Function
//!         End If
//!     End If
//!     
//!     IsBusinessHours = True
//! End Function
//!
//! Public Function GetBusinessHoursStatus() As String
//!     Dim currentTime As Date
//!     currentTime = Time
//!     
//!     If currentTime < m_BusinessStart Then
//!         GetBusinessHoursStatus = "Before business hours (opens at " & _
//!                                 Format$(m_BusinessStart, "h:mm AM/PM") & ")"
//!     ElseIf currentTime >= m_BusinessEnd Then
//!         GetBusinessHoursStatus = "After business hours (closed at " & _
//!                                 Format$(m_BusinessEnd, "h:mm AM/PM") & ")"
//!     ElseIf m_LunchStart > 0 And currentTime >= m_LunchStart And currentTime < m_LunchEnd Then
//!         GetBusinessHoursStatus = "Lunch break (returns at " & _
//!                                 Format$(m_LunchEnd, "h:mm AM/PM") & ")"
//!     Else
//!         GetBusinessHoursStatus = "Open for business"
//!     End If
//! End Function
//!
//! Public Function MinutesUntilOpen() As Long
//!     Dim currentTime As Date
//!     currentTime = Time
//!     
//!     If currentTime < m_BusinessStart Then
//!         MinutesUntilOpen = DateDiff("n", currentTime, m_BusinessStart)
//!     Else
//!         ' Next business day
//!         Dim nextOpen As Date
//!         nextOpen = DateAdd("d", 1, Date) + m_BusinessStart
//!         MinutesUntilOpen = DateDiff("n", Now, nextOpen)
//!     End If
//! End Function
//!
//! Public Function MinutesUntilClose() As Long
//!     Dim currentTime As Date
//!     currentTime = Time
//!     
//!     If currentTime >= m_BusinessEnd Then
//!         MinutesUntilClose = 0
//!     Else
//!         MinutesUntilClose = DateDiff("n", currentTime, m_BusinessEnd)
//!     End If
//! End Function
//! ```
//!
//! ## Error Handling
//! The `Time` function typically does not raise errors under normal circumstances:
//!
//! - **No parameters**: Cannot have parameter errors
//! - **System dependent**: Relies on system clock being set correctly
//! - **Always succeeds**: Returns current time from system
//!
//! ## Performance Notes
//! - Very fast operation - direct system call
//! - Negligible performance impact
//! - Can be called repeatedly without concern
//! - For high-precision timing, use `Timer` function instead
//! - Time resolution limited to one second
//!
//! ## Best Practices
//! 1. **Use Now for timestamps** if you need both date and time
//! 2. **Use Timer for performance** measurements (higher precision)
//! 3. **Cache Time value** if using multiple times in tight loop
//! 4. **Use Format$** to display time in specific format
//! 5. **Consider time zones** for distributed applications
//! 6. **Validate system time** is set correctly if critical
//! 7. **Use `TimeSerial`** to create specific time values for comparison
//! 8. **Handle overnight periods** carefully (when start > end time)
//! 9. **Store as Date type** not String for calculations
//! 10. **Document time format** assumptions in code comments
//!
//! ## Comparison Table
//!
//! | Function | Returns | Includes Date | Includes Time | Precision |
//! |----------|---------|---------------|---------------|-----------|
//! | `Time` | Variant (Date) | No (zero date) | Yes | 1 second |
//! | `Date` | Variant (Date) | Yes | No (midnight) | 1 day |
//! | `Now` | Variant (Date) | Yes | Yes | 1 second |
//! | `Timer` | Single | No | Yes (seconds since midnight) | High |
//! | `Time$` | String | No | Yes | 1 second |
//!
//! ## Platform Notes
//! - Available in VB6, VBA, and `VBScript`
//! - Consistent behavior across platforms
//! - Returns time based on system clock
//! - Time format display depends on regional settings
//! - Internal representation is numeric (fraction of a day)
//! - Date portion always 12/30/1899 (zero date)
//!
//! ## Limitations
//! - No millisecond precision (use Timer for better precision)
//! - Cannot get time from different time zone
//! - No built-in UTC time support
//! - Cannot specify which clock source to use
//! - Display format depends on system locale settings
//! - Cannot return time as numeric value directly (use `CDbl` or cast)
//! - No built-in support for daylight saving time handling

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

    #[test]
    fn time_basic() {
        let source = r"
Sub Test()
    currentTime = 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/time");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn time_with_parentheses() {
        let source = r"
Sub Test()
    currentTime = 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/time");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn time_variable_assignment() {
        let source = r"
Sub Test()
    Dim t As Date
    t = 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/time");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn time_msgbox() {
        let source = r#"
Sub Test()
    MsgBox "Current time: " & 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/time");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn time_debug_print() {
        let source = r"
Sub Test()
    Debug.Print 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/time");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn time_function_return() {
        let source = r"
Function GetCurrentTime() As Date
    GetCurrentTime = Time
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/time");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn time_with_hour() {
        let source = r"
Sub Test()
    currentHour = 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/time");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn time_comparison() {
        let source = r"
Sub Test()
    If Time > startTime Then
        DoSomething
    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/time");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn time_format() {
        let source = r#"
Sub Test()
    formatted = Format$(Time, "hh:mm:ss")
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/time");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn time_dateadd() {
        let source = r#"
Sub Test()
    futureTime = DateAdd("n", 30, 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/time");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn time_datediff() {
        let source = r#"
Sub Test()
    elapsed = DateDiff("n", startTime, 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/time");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn time_if_statement() {
        let source = r"
Sub Test()
    If Hour(Time) >= 9 And Hour(Time) < 17 Then
        BusinessHours
    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/time");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn time_select_case() {
        let source = r"
Sub Test()
    Select Case Hour(Time)
        Case 0 To 11
            Morning
        Case 12 To 17
            Afternoon
        Case Else
            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/time");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn time_function_argument() {
        let source = r"
Sub Test()
    Call LogTime(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/time");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn time_property_assignment() {
        let source = r"
Sub Test()
    obj.CurrentTime = 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/time");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn time_with_statement() {
        let source = r"
Sub Test()
    With tracker
        .StartTime = Time
    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/time");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn time_concatenation() {
        let source = r#"
Sub Test()
    logEntry = Time & " - Event occurred"
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/time");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn time_array_assignment() {
        let source = r"
Sub Test()
    timestamps(i) = 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/time");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn time_print_statement() {
        let source = r"
Sub Test()
    Print #1, 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/time");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn time_elseif() {
        let source = r"
Sub Test()
    If x = 1 Then
        y = 1
    ElseIf Time > deadline Then
        y = 2
    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/time");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn time_do_while() {
        let source = r"
Sub Test()
    Do While Time < endTime
        Process
    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/time");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn time_do_until() {
        let source = r"
Sub Test()
    Do Until Time >= targetTime
        Wait
    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/time");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn time_while_wend() {
        let source = r"
Sub Test()
    While Time < stopTime
        Continue
    Wend
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/time");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn time_iif() {
        let source = r#"
Sub Test()
    message = IIf(Time > noon, "PM", "AM")
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/time");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn time_arithmetic() {
        let source = r"
Sub Test()
    futureTime = Time + TimeSerial(1, 0, 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/time");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn time_cdate() {
        let source = r"
Sub Test()
    timeValue = CDate(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/time");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn time_class_usage() {
        let source = r"
Sub Test()
    Set logger = New TimeLogger
    logger.LogTime 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/time");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn time_minute() {
        let source = r"
Sub Test()
    currentMinute = Minute(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/time");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }
}