manrajgrover / football-cli

⚽ Command line interface for Hackers who love football
MIT License
1.07k stars 80 forks source link

Suggestion: format fixture.date to local time #39

Closed danoscarmike closed 6 years ago

danoscarmike commented 6 years ago

Description

football fixtures returns fixture date and time in the original time zone (or maybe UTC?)

Suggestion

use moment.js local() to convert to user's local time perhaps, add this an option using a flag or toggle in configuration

Happy to open if PR if you like?

manrajgrover commented 6 years ago

Hi @danoscarmike

As far as I can tell, football fixtures makes use of moment.calendar() which converts date and time to text based on your local time.

Maybe I didn't quite get the issue. If you could add an example for it, it would be great. :smile:

danoscarmike commented 6 years ago

Looking into this a bit more, according to the API's docs it returns fixture.date formatted as UTC (based on the ISO format with 'Z' and no offset).

I think the default referenceTime argument to moment.calendar() is also UTC (that is, Unix time).

Current output to date on my machine: Wed Jun 27 06:16:48 UTC 2018 Local time for me (US PST): Tue Jun 26 23:16:48

So when I run football fixtures -d 2 -l WC I get the following output:

World Cup Saudi Arabia 2 vs. 1 Egypt Last Monday at 2:00 PM World Cup Uruguay 3 vs. 0 Russia Last Monday at 2:00 PM World Cup Iran 1 vs. 1 Portugal Last Monday at 6:00 PM World Cup Spain 2 vs. 2 Morocco Last Monday at 6:00 PM World Cup Denmark 0 vs. 0 France Yesterday at 2:00 PM World Cup Australia 0 vs. 2 Peru Yesterday at 2:00 PM World Cup Nigeria 1 vs. 2 Argentina Yesterday at 6:00 PM World Cup Iceland 1 vs. 2 Croatia Yesterday at 6:00 PM

What I'd like to see is, taking the Iceland v Croatia game as an example:

World Cup Iceland 1 vs. 2 Croatia Today at 11:00 AM

Thanks @ManrajGrover! Really enjoying using the tool.

danoscarmike commented 6 years ago

Looked into it even more ;)

You are absolutely correct and moment() does indeed try to set the user's local time.

My own timezone settings were not configured correctly. I'm now seeing results as expected:

me@mine:~ $ football scores Denmark 0 vs. 0 France Yesterday at 7:00 AM Australia 0 vs. 2 Peru Yesterday at 7:00 AM Nigeria 1 vs. 2 Argentina Yesterday at 11:00 AM Iceland 1 vs. 2 Croatia Yesterday at 11:00 AM Mexico 0 vs. 3 Sweden Today at 7:00 AM Korea Republic 2 vs. 0 Germany Today at 7:00 AM

Nice looking Pacific times!

manrajgrover commented 6 years ago

@danoscarmike Thank you for looking into it!

Hope you're enjoying the world cup. :D