-
Notifications
You must be signed in to change notification settings - Fork 1
/
VDateCore.bas
1075 lines (848 loc) · 25 KB
/
VDateCore.bas
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
Attribute VB_Name = "VDateCore"
Option Explicit
'
' DateCore
' Version 1.4.0
'
' (c) Gustav Brock, Cactus Data ApS, CPH
' https://github.com/GustavBrock/VBA.Date
'
' Functions for all sorts of calculations related to date and time.
'
' License: MIT (http://opensource.org/licenses/mit-license.php)
'
' Required references:
' None
'
' Required modules:
' DateBase
' DateCalc
' DateFind
' DateMsec
' DateCore
'
' Returns the century of a date as the first year of the century.
' Returns Null if Date1 is Null or invalid.
' Value is 100 for the first century and 9900 for the last.
'
' 2016-04-08. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VCentury( _
ByVal Date1 As Variant) _
As Variant
Dim Result As Variant
If IsDateExt(Date1) Then
Result = Century(CDate(Date1))
Else
Result = Null
End If
VCentury = Result
End Function
' An extended replacement for DateAdd, that can handle any
' value set for Interval and Number that DateDiff can return.
' Returns Null if Date1 is Null or parameters are invalid.
'
' The maximum number is given by seconds of the full range of Date:
'
' SecondsMax = DateDiff("s", #1/1/100#, #12/31/9999 11:59:59 PM#)
' SecondsMax = 312413759999
'
' The maximum number DateAdd can accept is 2 ^ 31 - 1 or:
'
' MaxNumber = 2147483647
'
' For larger numbers, intervals are added in a loop, each adding
' the maximum number. Maximum loop count is:
'
' Max. loops = 312413759999 / 2147483647 = 145
'
' Inside the loop, Date- and TimeSerial are used to clear bit errors
' that would escalate to an error of one second for the outer day of
' the range of Date when adding seconds beyond the equivalent total
' interval of "Days of the range of Date" minus one - in other words:
'
' Adding seconds from times of 100-01-01 resulting in values
' later than 9999-12-30.
' Subtracting seconds from times of 9999-12-31 resulting in values
' earlier than 100-01-02.
'
' Will also handle additions of all non-native periods.
'
' 2016-02-15. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VDateAddExt( _
ByVal Interval As Variant, _
ByVal Number As Variant, _
ByVal Date1 As Variant) _
As Variant
Dim Result As Variant
Result = Null
If IsDateExt(Date1) And IsNumeric(Number) Then
Interval = Trim(Nz(Interval))
If IsIntervalSetting(Interval, True) Then
On Error Resume Next
Result = DateAddExt(Interval, CDbl(Number), CDate(Date1))
On Error GoTo 0
End If
End If
VDateAddExt = Result
End Function
' Returns the difference between two dates.
' Will also return the difference in extended
' intervals of half, third, and sixth years.
' Returns Null if Date1 or Date2 is Null or parameters are invalid.
'
' Note, that optional parameters for week settings
' are ignored, as weeks always are handled according
' to ISO 8601.
'
' 2015-11-24. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VDateDiffExt( _
ByVal Interval As Variant, _
ByVal Date1 As Variant, _
ByVal Date2 As Variant, _
Optional ByVal FirstDayOfWeek As VbDayOfWeek = vbSunday, _
Optional ByVal FirstWeekOfYear As VbFirstWeekOfYear = vbFirstJan1) _
As Variant
Dim Result As Variant
Result = Null
If IsDateExt(Date1) And IsDateExt(Date2) Then
Interval = Trim(Nz(Interval))
If IsIntervalSetting(Interval, True) Then
On Error Resume Next
Result = DateDiffExt(Interval, CDate(Date1), CDate(Date2), FirstDayOfWeek, FirstWeekOfYear)
On Error GoTo 0
End If
End If
VDateDiffExt = Result
End Function
' Returns a date that always will fall in the first
' ISO 8601 week of a year.
' If Year is not passed, the current year is used.
' Returns Null if Date1 is Null or parameters are invalid.
'
' 2015-12-04. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VDateFirstWeekYear( _
Optional ByVal Year As Variant = 0) _
As Variant
Dim Result As Variant
If VIsYear(Year) Then
Result = DateFirstWeekYear(CInt(Year))
Else
Result = Null
End If
VDateFirstWeekYear = Result
End Function
' Converts a timespan value to a date value.
' Returns Null if Value is Null or an invalid value.
' Useful only for result date values prior to 1899-12-30 as
' these have a negative numeric value.
'
' 2015-12-15. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VDateFromTimespan( _
ByVal Value As Variant) _
As Variant
Dim Result As Variant
If IsDateExt(Value) Then
Result = DateFromTimespan(CDate(Value))
Else
Result = Null
End If
VDateFromTimespan = Result
End Function
' Returns the first or earliest date and/or time of an interval of the date
' and/or time passed with an offset specified by Number.
' Optionally, milliseconds may be included.
' Returns Null if Date1 is Null or parameters are invalid.
'
' For intervals of a year down to a week, a time part is stripped.
' For intervals af a day down to millisecond, the time part is rounded down.
' Se the in-line comments for full details.
'
' Any date/time value is accepted and the return value will be correct within
' one millisecond as long as it will be within the range of Date. If not, an
' error is raised.
'
' 2016-01-13. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VDateIntervalPrimo( _
ByVal Interval As Variant, _
ByVal Number As Variant, _
ByVal Date1 As Variant, _
Optional ByVal FirstDayOfWeek As VbDayOfWeek = vbSunday, _
Optional AcceptMilliseconds As Boolean) _
As Variant
Dim Result As Variant
Result = Null
If IsDateExt(Date1) And IsNumeric(Number) Then
Interval = Trim(Nz(Interval))
If IsIntervalSetting(Interval, True) Then
On Error Resume Next
Result = DateIntervalPrimo(Interval, CDbl(Number), CDate(Date1), FirstDayOfWeek, AcceptMilliseconds)
On Error GoTo 0
End If
End If
VDateIntervalPrimo = Result
End Function
' Returns the last or latest date and/or time of an interval of the date
' and/or time passed with an offset specified by Number.
' Optionally, milliseconds may be included.
'
' For intervals of a year down to a week, a time part is stripped.
' For intervals af a day down to millisecond, the time part is rounded down.
' Se the in-line comments for full details.
'
' Any date/time value is accepted and the return value will be correct within
' one millisecond as long as it will be within the range of Date. If not, an
' error is raised.
'
' Returns Null if Date1 is Null or parameters are invalid.
'
' 2016-01-13. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VDateIntervalUltimo( _
ByVal Interval As Variant, _
ByVal Number As Variant, _
ByVal Date1 As Variant, _
Optional ByVal FirstDayOfWeek As VbDayOfWeek = vbSunday, _
Optional AcceptMilliseconds As Boolean) _
As Variant
Dim Result As Variant
Result = Null
If IsDateExt(Date1) And IsNumeric(Number) Then
Interval = Trim(Nz(Interval))
If IsIntervalSetting(Interval, True) Then
On Error Resume Next
Result = DateIntervalUltimo(Interval, CDbl(Number), CDate(Date1), FirstDayOfWeek, AcceptMilliseconds)
On Error GoTo 0
End If
End If
VDateIntervalUltimo = Result
End Function
' Returns a date that always will fall in the last
' ISO 8601 week of a year.
' If Year is not passed, the current year is used.
' Returns Null if Date1 is Null or parameters are invalid.
'
' 2015-12-04. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VDateLastWeekYear( _
Optional ByVal Year As Variant = 0) _
As Variant
Dim Result As Variant
If VIsYear(Year) Then
Result = DateLastWeekYear(CInt(Year))
Else
Result = Null
End If
VDateLastWeekYear = Result
End Function
' Returns the date part of a date.
' Will also return the extended period types of a date.
' Will return the correct ISO week number with parameters:
'
' FirstDayOfWeek = vbMonday
' FirstWeekOfYear = vbFirstFourDays
'
' equivalent to:
'
' FirstDayOfWeek = 2
' FirstWeekOfYear = 2
'
' Returns Null if Date1 is Null or parameters are invalid.
'
' 2015-11-24. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VDatePartExt( _
ByVal Interval As Variant, _
ByVal Date1 As Variant, _
Optional ByVal FirstDayOfWeek As VbDayOfWeek = vbSunday, _
Optional ByVal FirstWeekOfYear As VbFirstWeekOfYear = vbFirstJan1) _
As Variant
Dim Result As Variant
Result = Null
If IsDateExt(Date1) Then
Interval = Trim(Nz(Interval))
If IsIntervalSetting(Interval, True) Then
On Error Resume Next
Result = DatePartExt(Interval, CDate(Date1), FirstDayOfWeek, FirstWeekOfYear)
On Error GoTo 0
End If
End If
VDatePartExt = Result
End Function
' Returns a date value from its year, month, day,
' hour, minute, and second part.
' Except for year, default values are used for parameters omitted.
' Returns Null if any parameter is Null or invalid.
'
' Will accept any combination of parameters that can build a
' date/time within the range of Date, including dates before
' 1899-12-30.
'
' 2015-11-24. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VDateTimeSerial( _
ByVal Year As Variant, _
Optional ByVal Month As Variant = 1, _
Optional ByVal Day As Variant = 1, _
Optional ByVal Hour As Variant = 0, _
Optional ByVal Minute As Variant = 0, _
Optional ByVal Second As Variant = 0) _
As Variant
Dim ResultDate As Variant
ResultDate = Null
On Error Resume Next
ResultDate = DateTimeSerial(Year, Month, Day, Hour, Minute, Second)
On Error GoTo 0
VDateTimeSerial = ResultDate
End Function
' Converts a date value to a timespan value.
' Returns Null if Value is Null or an invalid value.
' Useful only for date values prior to 1899-12-30 as
' these have a negative numeric value.
'
' 2015-12-15. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VDateToTimespan( _
ByVal Value As Variant) _
As Variant
Dim Result As Variant
If IsDateExt(Value) Then
Result = DateToTimespan(CDate(Value))
Else
Result = Null
End If
VDateToTimespan = Result
End Function
' Returns the day of the month like the native VBA.Day.
' However, the ultimo date(s) will always be returned as day 30.
' Returns Null if Date1 is Null or invalid.
'
' Examples:
' VDay30(#2000-01-29#) -> 29
' VDay30(#2000-01-30#) -> 30
' VDay30(#2000-01-31#) -> 30
' VDay30(#2000-02-27#) -> 27
' VDay30(#2000-02-28#) -> 30
' VDay30(#2000-02-29#) -> 30
' VDay30(#2000-03-29#) -> 29
' VDay30(#2000-03-31#) -> 30
' VDay30(Null) -> Null
'
' 2019-01-26. Gustav Brock. Cactus Data ApS, CPH.
'
Public Function VDay30( _
ByVal Date1 As Variant) _
As Variant
Dim Result As Variant
If IsDateExt(Date1) Then
Result = Day30(CDate(Date1))
Else
Result = Null
End If
VDay30 = Result
End Function
' Returns the decade of a date as the first year of the decade.
' Returns Null if Date1 is Null or invalid.
' Value is 100 for the first decade and 9990 for the last.
'
' 2016-04-08. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VDecade( _
ByVal Date1 As Variant) _
As Variant
Dim Result As Variant
If IsDateExt(Date1) Then
Result = Decade(CDate(Date1))
Else
Result = Null
End If
VDecade = Result
End Function
' Returns the fortnight of a date based on the ISO 8601 week number.
' Returns Null if Date1 is Null or invalid.
' The related ISO year is returned by ref.
'
' 2016-01-06. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VFortnight( _
ByVal Date1 As Variant, _
Optional ByRef IsoYear As Variant) _
As Variant
Dim Year As Integer
Dim Result As Variant
If IsDateExt(Date1) Then
If VIsYear(IsoYear) Then
Year = CInt(IsoYear)
Else
Year = VBA.Year(CDate(Date1))
End If
Result = Fortnight(CDate(Date1), Year)
IsoYear = Year
Else
Result = Null
IsoYear = Null
End If
VFortnight = Result
End Function
' Returns the weekday within a fortnight based on an ISO 8601 week.
' Parameter FirstDayOfWeek is ignored as the first day must be Monday.
'
' Return values for the first seven days, Monday-Sunday, are 1 to 7.
' Return values for the next seven days, Monday-Sunday, are 8 to 14.
' Note that a fortnight of 27 will only have days of the first week.
' Returns Null if Date1 is Null or invalid.
'
' 2016-02-06. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VFortnightday( _
ByVal Date1 As Variant, _
Optional ByVal FirstDayOfWeek As VbDayOfWeek = vbMonday) _
As Variant
Dim Result As Variant
If IsDateExt(Date1) Then
FirstDayOfWeek = vbMonday
Result = Fortnightday(CDate(Date1), FirstDayOfWeek)
Else
Result = Null
End If
VFortnightday = Result
End Function
' Returns the count of a fortnightday between two dates.
' Returns Null if Date1 or Date2 is Null or invalid.
'
' 2016-02-14. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VFortnightdayCount( _
ByVal Date1 As Variant, _
ByVal Date2 As Variant) _
As Variant
Dim Result As Variant
If IsDateExt(Date1) And IsDateExt(Date2) Then
Result = FortnightdayCount(CDate(Date1), CDate(Date2))
Else
Result = Null
End If
VFortnightdayCount = Result
End Function
' Returns the count of fortnights based on the ISO 8601 week count of a year.
' If Year is not passed, the current year is used.
' Returns Null if Year is Null or an invalid value.
'
' 2016-02-14. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VFortnightsOfYear( _
Optional ByVal Year As Variant = 0) _
As Variant
Dim Result As Variant
If VIsYear(Year) Then
Result = FortnightsOfYear(CInt(Year))
Else
Result = Null
End If
VFortnightsOfYear = Result
End Function
' Returns True if Century can be a century.
' Returns Null if Century is Null or an invalid value.
'
' 2016-04-11. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VIsCentury( _
ByVal Century As Variant) _
As Variant
Dim Result As Variant
Result = Null
On Error Resume Next
Result = IsCentury(Century)
On Error GoTo 0
VIsCentury = Result
End Function
' Returns True if Decade can be a decade.
' Returns Null if Decade is Null or an invalid value.
'
' 2016-04-11. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VIsDecade( _
ByVal Decade As Variant) _
As Variant
Dim Result As Variant
Result = Null
On Error Resume Next
Result = IsDecade(Decade)
On Error GoTo 0
VIsDecade = Result
End Function
' Returns True if Fortnight can be a fortnight of Year.
' If Year is not specified, the current year is used.
' Returns Null if Fortnight or Year is Null or an invalid value.
'
' 2016-02-14. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VIsFortnight( _
ByVal Fortnight As Variant, _
Optional ByVal Year As Variant = 0) _
As Variant
Dim Result As Variant
Result = Null
On Error Resume Next
Result = IsFortnight(Fortnight, Year)
On Error GoTo 0
VIsFortnight = Result
End Function
' Returns True if Year is a leap year.
' If Year is not passed, the current year is used.
' Returns Null if Year is Null or an invalid value.
'
' 2015-11-24. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VIsLeapYear( _
Optional ByVal Year As Variant = 0) _
As Variant
Dim LeapYear As Variant
LeapYear = Null
On Error Resume Next
LeapYear = IsLeapYear(Year)
On Error GoTo 0
VIsLeapYear = LeapYear
End Function
' Returns True if Millenium can be a millenium.
' Returns Null if Century is Null or an invalid value.
'
' 2016-04-11. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VIsMillenium( _
ByVal Millenium As Variant) _
As Variant
Dim Result As Variant
Result = Null
On Error Resume Next
Result = IsMillenium(Millenium)
On Error GoTo 0
VIsMillenium = Result
End Function
' Returns True if Month can be a month.
' Returns Null if Month is Null or an invalid value.
'
' 2015-11-24. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VIsMonth( _
ByVal Month As Variant) _
As Variant
Dim Result As Variant
Result = Null
On Error Resume Next
Result = IsMonth(Month)
On Error GoTo 0
VIsMonth = Result
End Function
' Returns True if Quarter can be a quarter.
' Returns Null if Quarter is Null or an invalid value.
'
' 2015-11-24. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VIsQuarter( _
ByVal Quarter As Variant) _
As Variant
Dim Result As Variant
Result = Null
On Error Resume Next
Result = IsQuarter(Quarter)
On Error GoTo 0
VIsQuarter = Result
End Function
' Returns True if Semimonth can be a semimonth.
' Returns Null if Semimonth is Null or an invalid value.
'
' 2016-02-15. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VIsSemimonth( _
ByVal Semimonth As Variant) _
As Variant
Dim Result As Variant
Result = Null
On Error Resume Next
Result = IsSemimonth(Semimonth)
On Error GoTo 0
VIsSemimonth = Result
End Function
' Returns True if Semiyear can be a semiyear.
' Returns Null if Semiyear is Null or an invalid value.
'
' 2015-11-24. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VIsSemiyear( _
ByVal Semiyear As Variant) _
As Variant
Dim Result As Variant
Result = Null
On Error Resume Next
Result = IsSemiyear(Semiyear)
On Error GoTo 0
VIsSemiyear = Result
End Function
' Returns True if Sextayear can be a sextayear.
' Returns Null if Sextayear is Null or an invalid value.
'
' 2015-11-24. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VIsSextayear( _
ByVal Sextayear As Variant) _
As Variant
Dim Result As Variant
Result = Null
On Error Resume Next
Result = IsSextayear(Sextayear)
On Error GoTo 0
VIsSextayear = Result
End Function
' Returns True if Tertiayear can be a tertiayear.
' Returns Null if Tertiayear is Null or an invalid value.
'
' 2015-11-24. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VIsTertiayear( _
ByVal Tertiayear As Variant) _
As Variant
Dim Result As Variant
Result = Null
On Error Resume Next
Result = IsTertiayear(Tertiayear)
On Error GoTo 0
VIsTertiayear = Result
End Function
' Returns True if IsoWeek can be an ISO 8601 week of IsoYear.
' If Year is not specified, the current year is used.
' Returns Null if Week or Year is Null or an invalid value.
'
' 2016-01-06. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VIsWeek( _
ByVal IsoWeek As Variant, _
Optional ByVal IsoYear As Variant = 0) _
As Variant
Dim Result As Variant
Result = Null
On Error Resume Next
Result = IsWeek(IsoWeek, IsoYear)
On Error GoTo 0
VIsWeek = Result
End Function
' Returns True if Year can be a year.
' Returns Null if Year is Null or an invalid value.
'
' 2015-11-24. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VIsYear( _
ByVal Year As Variant) _
As Variant
Dim Result As Variant
Result = Null
On Error Resume Next
Result = IsYear(Year)
On Error GoTo 0
VIsYear = Result
End Function
' Returns the millenium of a date as the first year of the millenium.
' Returns Null if Date1 is Null or invalid.
' Value is 0 for the first millenium and 9000 for the last.
'
' 2016-04-08. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VMillenium( _
ByVal Date1 As Variant) _
As Variant
Dim Result As Variant
If IsDateExt(Date1) Then
Result = Millenium(CDate(Date1))
Else
Result = Null
End If
VMillenium = Result
End Function
' Returns the quarter of a date.
' Value is 1 for the first quarter of the year,
' 4 for the last.
' Returns Null if Date1 is Null or invalid.
'
' 2015-12-21. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VQuarter( _
ByVal Date1 As Variant) _
As Variant
Dim Result As Variant
If IsDateExt(Date1) Then
Result = Quarter(CDate(Date1))
Else
Result = Null
End If
VQuarter = Result
End Function
' Returns the second of a date.
' Returns Null if Time1 is Null or invalid.
'
' Will return correct reading of seconds of the last day of Date (9999-12-31).
' See function DateTest.TheLastSeconds for full information.
'
' 2016-02-14. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VSecondExt( _
ByVal Time1 As Variant) _
As Variant
Dim Result As Variant
If IsDateExt(Time1) Then
Result = SecondExt(CDate(Time1))
Else
Result = Null
End If
VSecondExt = Result
End Function
' Returns the semimonth of a date.
' Returns Null if Date1 is Null or invalid.
'
' 2016-02-14. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VSemimonth( _
ByVal Date1 As Variant) _
As Variant
Dim Result As Variant
If IsDateExt(Date1) Then
Result = Semimonth(CDate(Date1))
Else
Result = Null
End If
VSemimonth = Result
End Function
' Returns the semiyear of a date.
' Value is 1 for the first semiyear of a year,
' 2 for the second.
' Returns Null if Date1 is Null or invalid.
'
' 2015-11-24. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VSemiyear( _
ByVal Date1 As Variant) _
As Variant
Dim Result As Variant
If IsDateExt(Date1) Then
Result = Semiyear(CDate(Date1))
Else
Result = Null
End If
VSemiyear = Result
End Function
' Returns the sextayear of a date.
' Value is 1 for the first sextayear of a year,
' 2 for the second.
' Returns Null if Date1 is Null or invalid.
'
' 2015-11-24. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VSextayear( _
ByVal Date1 As Variant) _
As Variant
Dim Result As Variant
If IsDateExt(Date1) Then
Result = Sextayear(CDate(Date1))
Else
Result = Null
End If
VSextayear = Result
End Function
' Returns the tertiayear of a date.
' Value is 1 for the first tertiayear of a year,
' 2 for the second.
' Returns Null if Date1 is Null or invalid.
'
' 2015-11-24. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VTertiayear( _
ByVal Date1 As Variant) _
As Variant
Dim Result As Variant
If IsDateExt(Date1) Then
Result = Tertiayear(CDate(Date1))
Else
Result = Null
End If
VTertiayear = Result
End Function
' Returns an invalid numeric negative time Date1
' as its positive equivalent.
' Returns Null if Date1 is Null or invalid.
'
' 2015-12-15. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function VTimeEmend( _
ByVal Date1 As Variant) _
As Variant
Dim ResultDate As Variant
If IsDateExt(Date1) Then
' Emend the time Date1.
ResultDate = TimeEmend(CDate(Date1))
Else
ResultDate = Null
End If
VTimeEmend = ResultDate
End Function