Proxyman icon indicating copy to clipboard operation
Proxyman copied to clipboard

HAR Export on 12h Time Produces Incorrect Timestamps

Open SimonRice opened this issue 1 year ago • 8 comments

Description

It seems like that if I have my time format set to 12h & I export an HAR file between 1AM & 10AM or between 1PM & 10PM, the timestamps are incorrectly formatted, missing a leading 0 in the hour component.

As a result, the file can't be opened with Charles Proxy, and possibly other apps. Interestingly, Proxyman can still read the file correctly!

Steps to Reproduce

  1. Set your time format to 12 hour & ensure your time is either between 1AM & 10AM or between 1PM & 10PM.
  2. Record your session.
  3. Right click under "Apps" and go to Export -> as HAR (HTTP Archive). Save your file accordingly.
  4. Attempt to open your HAR file with Charles Proxy.

I do have an HAR file of a couple of Google request-response pairs I made with Proxyman that you're also welcome to use.

Current Behavior

The resulting HAR file imports in to Charles Proxy correctly.

Expected Behavior

The resulting HAR file fails to import in to Charles Proxy. It shows there's an issue with the timestamp(s).

Screenshot

Manually editing the timestamps via search/replace makes the file compatible with Charles Proxy again.

Environment

  • App version: Proxyman v5.0.0 (50000)
  • macOS version: macOS Sonoma v14.3.1

SimonRice avatar Feb 22 '24 12:02 SimonRice

Thanks @SimonRice , let me fix it 👍

NghiaTranUIT avatar Feb 23 '24 05:02 NghiaTranUIT

@SimonRice it's odd that I can't reproduce it 🤔

Currently, Proxyman uses this format yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ to generate the startedDateTime

You can find this HAR Log: Apps_02-28-2024-14-23-00.har.zip

The startedDateTime format is correct and it doesn't affect by the Use 12h format Option in the Setting.

"startedDateTime": "2024-02-28T14:22:54.786+07:00",

Can I ask if this bug still happen if you use 24h mode ?

NghiaTranUIT avatar Feb 28 '24 07:02 NghiaTranUIT

even though I force the UK timezone in the TimeFormatter, it still has the leading 0

    static let iso8601: DateFormatter = {
        let formatter = DateFormatter()
        formatter.calendar = Calendar(identifier: .iso8601)
        formatter.locale = Locale(identifier: "en_GB")
        formatter.timeZone = TimeZone(identifier: "Europe/London")
        formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ" // there is second decimal
        return formatter
    }()

HAR:

"startedDateTime": "2024-02-28T07:36:33.960Z",

NghiaTranUIT avatar Feb 28 '24 07:02 NghiaTranUIT

Hi @NghiaTranUIT,

First of all, thank you so much for the reply.

I tried the above for a command line app, based on what you gave me:

import Foundation

let iso8601: DateFormatter = {
    let formatter = DateFormatter()
    formatter.calendar = Calendar(identifier: .iso8601)
    formatter.locale = Locale(identifier: "en_GB")
    formatter.timeZone = TimeZone(identifier: "Europe/London")
    formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ" // there is second decimal
    return formatter
}()

let date = Date(timeIntervalSince1970: 1709106415) // Roughly 7:47 AM GMT on 2022-02-28

print(iso8601.string(from: date))

With this sample, it does print out 2024-02-28T07:46:55.000Z.

However, if I leave / comment out formatter.locale = Locale(identifier: "en_GB") it does not print out correctly - this prints out 2024-02-28T7:46:55.000Z.

Bizarrely, if I print out the formatter's locale's identifier within the body of iso8601 without setting the formatter's locale, I get en_GB@calendar=iso8601. Whereas with the formatter's locale set, that's understandably en_GB. I do wonder if using en_US_POSIX will do the trick here!

If it helps at all, I've attached my date & time and language & region settings here.

Screenshot 2024-02-28 at 7 42 49 am Screenshot 2024-02-28 at 7 52 27 am

Finally, if I do set my time setting to 24h, I do get a leading zero with your above sample and with the local setting commented out.

I hope this all helps.

SimonRice avatar Feb 28 '24 07:02 SimonRice

Nice, I realize my original implementation is:

    static let iso8601: DateFormatter = {
        let formatter = DateFormatter()
        formatter.calendar = Calendar(identifier: .iso8601)
        formatter.locale = Locale.current
        formatter.timeZone = TimeZone.current
        formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ" // there is second decimal
        return formatter
    }()

It means it somehow changes the behavior of the dateFormat string. Let me investigate it.


May I ask: Set your time format to 12 hour & ensure your time is either between 1AM & 10AM or between 1PM & 10PM.

Do you mean the 12 Format in Proxyman -> Setting -> Advance Tab -> Use 24h format ?

Or the System Time Format (Date & Time) ?

NghiaTranUIT avatar Feb 28 '24 08:02 NghiaTranUIT

May I ask: Set your time format to 12 hour & ensure your time is either between 1AM & 10AM or between 1PM & 10PM.

Do you mean the 12 Format in Proxyman -> Setting -> Advance Tab -> Use 24h format ?

Or the System Time Format (Date & Time) ?

I did mean system format - however, on Proxyman's advanced tab, it's switched off as well.

Screenshot 2024-02-28 at 8 09 38 am

SimonRice avatar Feb 28 '24 08:02 SimonRice

@SimonRice can you try this build: https://download.proxyman.io/beta/Proxyman_5.0.0_Try_to_fix_the_ISO_8601.dmg

I use ISO8601DateFormatter rather than DateFormatter with a custom dateString. ISO8601DateFormatter doesn't allow to have the time zone, it always use UTC and we should not override with current timezone or locale.

I test and it works on my end 👍

NghiaTranUIT avatar Feb 29 '24 00:02 NghiaTranUIT

Thank you so much for this @NghiaTranUIT - this works perfectly 🎉

SimonRice avatar Feb 29 '24 07:02 SimonRice

Awesome 👍

NghiaTranUIT avatar Mar 01 '24 02:03 NghiaTranUIT

The amend in question is still working brilliantly 🎉 I've been meaning to close this issue for ages, so I'll do that now! Thank you @NghiaTranUIT once again for your brilliant support!

SimonRice avatar Apr 23 '24 11:04 SimonRice