|
| 1 | +Function ConvertVTDATELocalTimeToISO8601ExtendedFormatString(ByRef strISO8601Output, ByVal datetimeInput) |
| 2 | + 'region FunctionMetadata #################################################### |
| 3 | + ' Safely takes a VT_DATETIME (VBScript-native datetime variant) object and converts it to a |
| 4 | + ' string representation of the date and time, in compliance with ISO 8601's extended format |
| 5 | + ' |
| 6 | + ' The function takes two positional arguments: |
| 7 | + ' The first argument (strISO8601Output) is set upon success to a string representation of |
| 8 | + ' the date and time specified by the second argument (datetimeInput), represented in |
| 9 | + ' compliance with ISO 8601 |
| 10 | + ' The second argument (datetimeInput) is a VBScript-native datetime object (VT_DATE) |
| 11 | + ' containing a date and time in the local computer's time zone |
| 12 | + ' |
| 13 | + ' The function returns 0 or a positive number if the VBScript-native datetime object |
| 14 | + ' (VT_DATETIME) was converted to a ISO 8601-formatted string. A return of 1 indicates a |
| 15 | + ' warning condition in which the local computer's time zone adjustment could not be |
| 16 | + ' determined. It returns a negative number if an error occurred |
| 17 | + ' |
| 18 | + ' Example: |
| 19 | + ' datetimeDateFunctionAuthored = DateSerial(2021, 8, 8) |
| 20 | + ' datetimeDateFunctionAuthored = datetimeDateFunctionAuthored + TimeSerial(13, 0, 0) |
| 21 | + ' intReturnCode = ConvertVTDATELocalTimeToISO8601ExtendedFormatString(strISO8601Output, datetimeDateFunctionAuthored) |
| 22 | + ' If intReturnCode >= 0 Then |
| 23 | + ' ' Conversion completed successfully |
| 24 | + ' ' On a computer in the Central (US) Daylight Time (GMT-5) time zone, |
| 25 | + ' ' strISO8601Output is "2021-08-05T13:00:00-05:00" |
| 26 | + ' End If |
| 27 | + ' |
| 28 | + ' Version: 1.0.20210810.0 |
| 29 | + 'endregion FunctionMetadata #################################################### |
| 30 | + |
| 31 | + 'region License #################################################### |
| 32 | + ' Copyright 2021 Frank Lesniak |
| 33 | + ' |
| 34 | + ' Permission is hereby granted, free of charge, to any person obtaining a copy of this |
| 35 | + ' software and associated documentation files (the "Software"), to deal in the Software |
| 36 | + ' without restriction, including without limitation the rights to use, copy, modify, merge, |
| 37 | + ' publish, distribute, sublicense, and/or sell copies of the Software, and to permit |
| 38 | + ' persons to whom the Software is furnished to do so, subject to the following conditions: |
| 39 | + ' |
| 40 | + ' The above copyright notice and this permission notice shall be included in all copies or |
| 41 | + ' substantial portions of the Software. |
| 42 | + ' |
| 43 | + ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
| 44 | + ' INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
| 45 | + ' PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE |
| 46 | + ' FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 47 | + ' OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 48 | + ' DEALINGS IN THE SOFTWARE. |
| 49 | + 'endregion License #################################################### |
| 50 | + |
| 51 | + 'region DownloadLocationNotice #################################################### |
| 52 | + ' The most up-to-date version of this script can be found on the author's GitHub repository |
| 53 | + ' at https://github.com/franklesniak/sysadmin-accelerator |
| 54 | + 'endregion DownloadLocationNotice #################################################### |
| 55 | + |
| 56 | + 'region DependsOn #################################################### |
| 57 | + ' ConnectLocalWMINamespace() |
| 58 | + ' GetComputerSystemInstancesUsingWMINamespace() |
| 59 | + ' GetTimeZoneInstancesUsingWMINamespace() |
| 60 | + ' ConvertVTDATELocalTimeToISO8601ExtendedFormatStringUsingComputerSystemAndTimeZoneInstances() |
| 61 | + 'endregion DependsOn #################################################### |
| 62 | + |
| 63 | + Dim intFunctionReturn |
| 64 | + Dim intReturnCode |
| 65 | + Dim strISO8601OutputToReturn |
| 66 | + |
| 67 | + Dim objSWbemServicesWMINamespace |
| 68 | + Dim arrComputerSystemInstances |
| 69 | + Dim arrTimeZoneInstances |
| 70 | + |
| 71 | + intReturnCode = ConnectLocalWMINamespace(objSWbemServicesWMINamespace, Null, Null) |
| 72 | + intReturnCode = GetComputerSystemInstancesUsingWMINamespace(arrComputerSystemInstances, objSWbemServicesWMINamespace) |
| 73 | + intReturnCode = GetTimeZoneInstancesUsingWMINamespace(arrTimeZoneInstances, objSWbemServicesWMINamespace) |
| 74 | + intFunctionReturn = ConvertVTDATELocalTimeToISO8601ExtendedFormatStringUsingComputerSystemAndTimeZoneInstances(strISO8601OutputToReturn, datetimeInput, arrComputerSystemInstances, arrTimeZoneInstances) |
| 75 | + |
| 76 | + If intFunctionReturn >= 0 Then |
| 77 | + strISO8601Output = strISO8601OutputToReturn |
| 78 | + End If |
| 79 | + |
| 80 | + ConvertVTDATELocalTimeToISO8601ExtendedFormatString = intFunctionReturn |
| 81 | +End Function |
0 commit comments