Results 1 to 40 of 132

Thread: VB6 - JsonBag, Another JSON Parser/Generator

Threaded View

  1. #11

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    21,041

    JsonDate date/time format conversion class

    One sore point with JSON is its weak intrinsic type system. In particular date/time values can be painful.

    In the wild you'll encounter several workarounds. Some will use ad-hoc formatted strings, and some will use either Unix "Epoch" timetamps (large numbers) or ISO 8601 date-time strings.

    Here's a helper class JsonDate for performing conversions on the latter two date/time representations.


    In this version IsoToDate() only handles ISO timestamps of the combined date and time type:

    YYYY-MM-DDTHH:MM{.SS{.mmm}}{{Z}|+/-HH|+/-HHMM|+/-HH:MM}

    Examples:

    2015-04-20T15:51:38.001+05:01
    1962-01-01T05:25Z
    1962-01-01T05:25

    In the last case there is no time zone specification and this can be ambiguous. The default is to treat this as meaning you have a local time, but you can modify this by setting the property:

    .AssumeZ = True

    Since the VB Date type doesn't have the resolution to use milliseconds this method just truncates and ignores any .mmm part found in input strings.

    While both Unix Epoch and ISO date/time values are considered Zulu/UTC/GMT values the VB Date type is normally considered a local time. By default the format conversion methods in JsonBag will perform this adjustment. However you can also choose to work entirely in UTC by setting the property:

    .UtcMode = True

    This causes the format conversions to skip the time zone adjustments.


    There isn't a lot of code here. So if you merely need a conversion or two it is easy enough to copy some of the code inline into your programs instead of using the JsonDate class at all, aside from maintenance issues if bugs are later discovered. Everything but IsoToDate() is trivial code.

    The code seems to be working properly, but having more eyes on it will help find and fix any lingering bugs.

    A simple test using Excel 2003 (32-bit) seemed to work just fine, and I suspect newer versions of VBA can use it as well, both 32-bit and 64-bit.

    The attachment has JsonDate.cls and a VB6 test Project and several test cases. The Project reads the test cases and displays the results of various conversions.
    Attached Files Attached Files
    Last edited by dilettante; Apr 23rd, 2015 at 09:52 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width