public-transport / hafas-client

JavaScript client for HAFAS public transport APIs.
ISC License
277 stars 53 forks source link

problem with reference date in scheduledDays computation #277

Closed bergmannjg closed 2 years ago

bergmannjg commented 2 years ago

Given the following TripSearch response

{
    ... 
    "svcResL": [
        {
            "meth": "TripSearch",
            "res": {
                ...
                "outConL": [
                    {
                        "date": "20221115",
                        "sDays": {
                            "sDaysR": "runs 15. Nov until 10. Dec 2022 ",
                            "sDaysB": "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF807FFFFFF0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
                        },
                    ...
                ],
                "fpB": "20211212",
                "fpE": "20231209",
        ...
        }
    ]
}

hafas-client computes the last scheduledDay as 2022-12-30, the correct value should be 2022-12-10 as in field sDaysR.

hafas-client uses the year of "date": "20221115" as the reference date.

https://github.com/public-transport/hafas-client/blob/61fc2293fb41df5a7c43a202df8707134cd51759/parse/journey.js#L60-L63

https://github.com/public-transport/hafas-client/blob/61fc2293fb41df5a7c43a202df8707134cd51759/parse/journey.js#L10-L15

I would suggest to take the reference date from "fpB": "20211212" as year/month/day.

derhuerst commented 2 years ago

hafas-client computes the last scheduledDay as 2022-12-30, the correct value should be 2022-12-10 as in field sDaysR.

Good catch!

I would suggest to take the reference date from "fpB": "20211212" as year/month/day.

This seems to be the intended way, yes.

derhuerst commented 2 years ago

Just found this weird example, can you make sense of it?

{
    // […]
    "fpB": "20211212",
    "fpE": "20231209",
    // […]
    "sDays": {
        "sDaysR": "runs 16. Nov 2022 ",
        "sDaysB": "000000000000000000000000000000000000000000000000000000000000000000000000000000000001F0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
    },
}

The sDaysB bit mask doesn't specify just one date.

bergmannjg commented 2 years ago

sDaysB decodes the range from 2022-11-12 to 2022-11-16

if current day is in the sDaysB range then sDaysR range starts from current day '2022-11-16'

derhuerst commented 2 years ago

if current day is in the sDaysB range then sDaysR range starts from current day '2022-11-16' [but sDaysB does not]

That is a weird API!

derhuerst commented 2 years ago

Fix published as hafas-client@5.26.2. 🎉