Skip to content

Commit

Permalink
Refactor date conversion for DB Properties
Browse files Browse the repository at this point in the history
Save custom date properties in ISO (UTC) format in source files, without converting other property types like strings that may parse as dates. joyfullservice#459
  • Loading branch information
joyfullservice committed Nov 17, 2023
1 parent 64a14de commit adfaa01
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
21 changes: 16 additions & 5 deletions Version Control.accda.src/modules/clsDbProperty.cls
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,7 @@ Private Sub IDbComponent_Import(strFile As String)
Next prp

' Read properties from source file
' We don't want to parse the dates here, so turning them off for this operation only.
' See issue #459 for additional details.
JsonOptions.ConvertDateToIso = False
Set dImport = ReadJsonFile(strFile)
JsonOptions.ConvertDateToIso = True
If Not dImport Is Nothing Then
Set dItems = dImport("Items")
For Each varKey In dItems.Keys
Expand All @@ -100,6 +96,14 @@ Private Sub IDbComponent_Import(strFile As String)
varValue = dItems(varKey)("Value")
' Check for relative path
If IsRelativePath(CStr(varValue)) Then varValue = GetPathFromRelative(CStr(varValue))
' Check for UTC date that might need to be converted back to local
If dItems(varKey)("Type") = dbDate Then
If (Not IsDate(varValue)) And (Right(varValue, 1) = "Z") Then
' Convert UTC date to local date
dItems(varKey)("Value") = modUtcConverter.ParseIso(CStr(varValue))
varValue = CDate(dItems(varKey)("Value"))
End If
End If
Else
ReDim bArray(0 To dItems(varKey)("Value").Count - 1)
For Each varItem In dItems(varKey)("Value")
Expand Down Expand Up @@ -148,7 +152,7 @@ Private Sub IDbComponent_Import(strFile As String)
End If

' Can't add a text property with a null value. See issue #126
If dItems(varKey)("Type") = 10 Then
If dItems(varKey)("Type") = dbText Then
If varValue = vbNullChar Then blnAdd = False
End If
' Add the property if the flag has been set.
Expand Down Expand Up @@ -260,6 +264,13 @@ Private Function GetDictionary(Optional blnUseCache As Boolean) As Dictionary
varValue = GetRelativePath(CStr(varValue))
End If
End If
' Convert dates to UTC
If prp.Type = dbDate Then
If IsDate(varValue) Then
' Store dates in JSON as UTC dates.
varValue = modUtcConverter.ConvertToIsoTime(CDate(varValue))
End If
End If
Set dItem = New Dictionary
dItem.Add "Value", varValue
dItem.Add "Type", prp.Type
Expand Down
8 changes: 8 additions & 0 deletions Version Control.accda.src/modules/clsVCSIndex.cls
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ Public Sub Save(Optional strInFolder As String)
Dim varKey As Variant
Dim varValue As Variant
Dim strFile As String
Dim blnSavedValue As Boolean

' Exit if we have disabled the index functionality
If Me.Disabled Then Exit Sub
Expand Down Expand Up @@ -139,11 +140,18 @@ Public Sub Save(Optional strInFolder As String)
strFile = StripSlash(strInFolder) & PathSep & cstrFileName
End If

' Turn on ISO date conversion to save index dates in UTC
blnSavedValue = JsonOptions.ConvertDateToIso
JsonOptions.ConvertDateToIso = True

' Save index to file
If m_strFile <> vbNullString Then
WriteFile BuildJsonFile(TypeName(Me), m_dIndex, "Version Control System Index"), strFile
End If

' Restore previous setting
JsonOptions.ConvertDateToIso = blnSavedValue

End Sub


Expand Down
2 changes: 1 addition & 1 deletion Version Control.accda.src/modules/modJsonConverter.bas
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ Private Type json_Options
EscapeSolidus As Boolean

' Before version 2.3.1 dates were converted to UTC in ConvertToJson method, but not when json was parsed.
' Convert datetime values to UTC/ISO8601 (false, slower) or dont change local <-> global times (true, faster)
' Convert datetime values to UTC/ISO8601 (true, slower) or dont change local <-> global times (false, faster)
ConvertDateToIso As Boolean

' Allow Unicode characters in JSON text. Set to True to use native Unicode or false for escaped values.
Expand Down
2 changes: 1 addition & 1 deletion Version Control.accda.src/vcs-options.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Info": {
"AddinVersion": "4.0.27",
"AddinVersion": "4.0.28",
"AccessVersion": "14.0 32-bit"
},
"Options": {
Expand Down

0 comments on commit adfaa01

Please sign in to comment.