11Attribute VB_Name = "Specs"
2+ Private pOffsetMinutes As Long
3+ Private pOffsetLoaded As Boolean
4+ Public Property Get OffSetMinutes() As Long
5+ If Not pOffsetLoaded Then
6+ Dim InputValue As String
7+ InputValue = VBA.InputBox("Enter UTC Offset (in minutes)" & vbNewLine & vbNewLine & _
8+ "Example:" & vbNewLine & _
9+ "EST (UTC-5:00) and DST (+1:00)" & vbNewLine & _
10+ "= UTC-4:00" & vbNewLine & _
11+ "= -240" , "Enter UTC Offset" , 0 )
12+
13+ If InputValue <> "" Then : pOffsetMinutes = CLng(InputValue)
14+
15+ pOffsetLoaded = True
16+ End If
17+
18+ OffSetMinutes = pOffsetMinutes
19+ End Property
20+ Public Property Let OffSetMinutes(Value As Long )
21+ pOffsetMinutes = Value
22+ pOffsetLoaded = True
23+ End Property
24+
225Public Function Specs () As SpecSuite
326 Set Specs = New SpecSuite
427 Specs.Description = "VBA-UTC"
528
6- ' Override UTC Offset for specs
7- UtcConverter.utc_Override = True
8- UtcConverter.utc_UtcOffsetMinutes = -4 * 60
9-
1029 Dim LocalDate As Date
1130 Dim LocalIso As String
1231 Dim UtcDate As Date
@@ -17,47 +36,49 @@ Public Function Specs() As SpecSuite
1736 LocalIso = "2004-05-06T19:08:09.000Z"
1837
1938 ' May 6, 2004 11:08:09 PM
20- UtcDate = 38113.9639930556
21- UtcIso = "2004-05-06T23:08:09 .000Z"
39+ UtcDate = LocalDate - OffSetMinutes / 60 / 24
40+ UtcIso = VBA.Format$(UtcDate, "yyyy-mm-ddTHH:mm:ss .000Z")
2241
2342 ' ============================================= '
2443 ' ParseUTC
2544 ' ============================================= '
2645 With Specs.It("should parse UTC" )
27- .Expect(VBA.Format$ (UtcConverter.ParseUtc(UtcDate), "yyyy-mm-ddTHH:mm:ss.000Z" )).ToEqual LocalIso
46+ .Expect(DateToString (UtcConverter.ParseUtc(UtcDate))).ToEqual DateToString(LocalDate)
2847 End With
2948
3049 ' ============================================= '
3150 ' ConvertToUTC
3251 ' ============================================= '
3352 With Specs.It("should convert to UTC" )
34- .Expect(VBA.Format$ (UtcConverter.ConvertToUtc(LocalDate), "yyyy-mm-ddTHH:mm:ss.000Z" )).ToEqual UtcIso
53+ .Expect(DateToString (UtcConverter.ConvertToUtc(LocalDate))).ToEqual DateToString(UtcDate)
3554 End With
3655
3756 ' ============================================= '
3857 ' ParseISO
3958 ' ============================================= '
4059 With Specs.It("should parse ISO 8601" )
41- .Expect(VBA.Format$ (UtcConverter.ParseIso(UtcIso), "yyyy-mm-ddTHH:mm:ss.000Z" )).ToEqual LocalIso
60+ .Expect(DateToString (UtcConverter.ParseIso(UtcIso))).ToEqual "2004-05-06T19:08:09"
4261 End With
4362
4463 With Specs.It("should parse ISO 8601 with offset" )
45- .Expect(VBA.Format$ (UtcConverter.ParseIso("2004-05-06T12:08:09+04:05:06" ), "yyyy-mm-ddTHH:mm:ss" )).ToEqual "2004-05-06T16:13:15"
46- .Expect(VBA.Format$ (UtcConverter.ParseIso("2004-05-06T12:08:09-04:05:06" ), "yyyy-mm-ddTHH:mm:ss" )).ToEqual "2004-05-06T08:03:03"
64+ .Expect(DateToString (UtcConverter.ParseIso("2004-05-06T12:08:09+04:05:06" ))).ToEqual "2004-05-06T16:13:15"
65+ .Expect(DateToString (UtcConverter.ParseIso("2004-05-06T12:08:09-04:05:06" ))).ToEqual "2004-05-06T08:03:03"
4766 End With
4867
4968 With Specs.It("should parse ISO 8601 with varying time format" )
50- .Expect(VBA.Format$(UtcConverter.ParseIso("2004-05-06T12+04" ), "yyyy-mm-ddTHH:mm:ss" )).ToEqual "2004-05-06T16:00:00"
51- .Expect(VBA.Format$(UtcConverter.ParseIso("2004-05-06T12:08+04:05" ), "yyyy-mm-ddTHH:mm:ss" )).ToEqual "2004-05-06T16:13:00"
52- .Expect(VBA.Format$(UtcConverter.ParseIso("2004-05-06T12Z" ), "yyyy-mm-ddTHH:mm:ss" )).ToEqual "2004-05-06T08:00:00"
53- .Expect(VBA.Format$(UtcConverter.ParseIso("2004-05-06T12:08Z" ), "yyyy-mm-ddTHH:mm:ss" )).ToEqual "2004-05-06T08:08:00"
69+ .Expect(DateToString(UtcConverter.ParseIso("2004-05-06T12+04" ))).ToEqual "2004-05-06T16:00:00"
70+ .Expect(DateToString(UtcConverter.ParseIso("2004-05-06T12:08+04:05" ))).ToEqual "2004-05-06T16:13:00"
71+ .Expect(DateToString(UtcConverter.ParseIso("2004-05-06T12Z" ))).ToEqual _
72+ DateToString(DateSerial(2004 , 5 , 6 ) + TimeSerial(12 , 0 , 0 ) + OffSetMinutes / 60 / 24 )
73+ .Expect(DateToString(UtcConverter.ParseIso("2004-05-06T12:08Z" ))).ToEqual _
74+ DateToString(DateSerial(2004 , 5 , 6 ) + TimeSerial(12 , 8 , 0 ) + OffSetMinutes / 60 / 24 )
5475 End With
5576
5677 ' ============================================= '
5778 ' ConvertToISO
5879 ' ============================================= '
5980 With Specs.It("should convert to ISO 8601" )
60- .Expect(VBA.Format$( UtcConverter.ConvertToIso(LocalDate), "yyyy-mm-ddTHH:mm:ss.000Z" )).ToEqual UtcIso
81+ .Expect(UtcConverter.ConvertToIso(LocalDate)).ToEqual UtcIso
6182 End With
6283
6384 ' ============================================= '
@@ -77,3 +98,7 @@ Public Sub RunSpecs()
7798
7899 DisplayRunner.RunSuite Specs
79100End Sub
101+
102+ Private Function DateToString (Value As Date ) As String
103+ DateToString = VBA.Format$(Value, "yyyy-mm-ddTHH:mm:ss" )
104+ End Function
0 commit comments