ProxymanApp / Proxyman

Modern. Native. Delightful Web Debugging Proxy for macOS, iOS, and Android ⚡️
https://proxyman.io
5.56k stars 185 forks source link

HAR Export on 12h Time Produces Incorrect Timestamps #1944

Closed SimonRice closed 5 months ago

SimonRice commented 7 months ago

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

NghiaTranUIT commented 7 months ago

Thanks @SimonRice , let me fix it 👍

NghiaTranUIT commented 7 months ago

@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 commented 7 months ago

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",
SimonRice commented 7 months ago

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.

NghiaTranUIT commented 7 months ago

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) ?

SimonRice commented 7 months ago

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
NghiaTranUIT commented 7 months ago

@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 👍

SimonRice commented 7 months ago

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

NghiaTranUIT commented 7 months ago

Awesome 👍

SimonRice commented 5 months ago

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!