mczachurski / wallpapper

:computer: Console application for creating dynamic wallpapers for macOS Mojave and newer
MIT License
3.32k stars 137 forks source link

Date parsing error #47

Open VictorPuga opened 3 years ago

VictorPuga commented 3 years ago

I am trying to generate a wallpaper using the "filename" "time" option, but when the JSONDecoder reads: "2021-02-17T13:00:00Z", I am getting the error: Date string does not match format expected by formatter. However, if the same date is 12 instead of 13 ("2021-02-17T12:00:00Z"), there is no problem.

VictorPuga commented 3 years ago

Im using v1.7.1

mczachurski commented 3 years ago

Unfortunately I cannot reproduce that bug. I'm using below JSON and everything is working. Can you provide more information (full log, swift version, os version etc.)?

[
    {
        "fileName": "1.png",
        "isPrimary": true,
        "time": "2021-02-17T04:00:00Z"
    },
    {
        "fileName": "2.png",
        "time": "2021-02-17T05:00:00Z"
    },
    {
        "fileName": "3.png",
        "time": "2021-02-17T06:00:00Z"
    },
    {
        "fileName": "4.png",
        "time": "2021-02-17T07:00:00Z"
    },
    {
        "fileName": "5.png",
        "time": "2021-02-17T08:00:00Z"
    },
    {
        "fileName": "6.png",
        "time": "2021-02-17T10:00:00Z"
    },
    {
        "fileName": "7.png",
        "time": "2021-02-17T12:00:00Z"
    },
    {
        "fileName": "8.png",
        "time": "2021-02-17T13:00:00Z"
    },
    {
        "fileName": "8.png",
        "time": "2021-02-17T15:00:00Z"
    },
    {
        "fileName": "9.png",
        "time": "2021-02-17T16:00:00Z"
    },
    {
        "fileName": "10.png",
        "time": "2021-02-17T17:00:00Z"
    },
    {
        "fileName": "11.png",
        "time": "2021-02-17T18:00:00Z"
    },
    {
        "fileName": "12.png",
        "time": "2021-02-17T19:00:00Z"
    },
    {
        "fileName": "13.png",
        "time": "2021-02-17T20:00:00Z"
    },
    {
        "fileName": "14.png",
        "time": "2021-02-17T21:00:00Z"
    },
    {
        "fileName": "15.png",
        "time": "2021-02-17T22:00:00Z"
    },
    {
        "fileName": "16.png",
        "time": "2021-02-17T23:00:00Z"
    }
]
VictorPuga commented 3 years ago

Same issue with the JSON above. I will try to provide some information

y-neck commented 3 years ago

I have got exactly the same problem (same error log).

eduarbo commented 3 years ago

I had the same issue, apparently the parser breaks when you set the time format to 12-Hour in System Preferences. As a workaround try enabling the 24-Hour format temporarily while running the command.

Screen Shot 2021-10-11 at 8 04 46 p m
patrickhoette commented 1 year ago

I solved this issue by changing line 40 of Program.swift to:

formatter.dateFormat = "hh:mm a"

and then used the following in my JSON:

[
    {
        "fileName": "light.jpg",
        "isPrimary": true,
        "isForLight": true,
        "time": "08:30 AM"
    },
    {
        "fileName": "dark.jpg",
        "isForDark": true,
        "time": "06:00 PM"
    }
]

This doesn't fundamentally fix the issue though, this just made it work with 12h formatted time. In case anyone is interested in a more permanent fix to the issue. This will mean making the change yourself and compiling the code but thats simple enough. Instructions are in the readme.