Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

Time: Improve Generic Time handling #2357

Merged
merged 5 commits into from Dec 25, 2015
Merged

Conversation

nilnilnil
Copy link
Contributor

@MrChrisW @moollaza @bsstoner

@bsstoner I could probably use some JS cleanup :)


IA Page: https://duck.co/ia/view/time

@daxtheduck
Copy link

daxtheduck commented Dec 24, 2015

Time

Description: Provides the local time of country, city or state searched

Example Query: [time in Melbourne](https://beta.duckduckgo.com/?q=time in Melbourne), [what time is it in Melbourne](https://beta.duckduckgo.com/?q=what time is it in Melbourne), [what is the time in Birmingham](https://beta.duckduckgo.com/?q=what is the time in Birmingham), [time for Australia](https://beta.duckduckgo.com/?q=time for Australia)

Tab Name: Time

Source:

These are the important fields from the IA page. Please check these for errors or missing information and update the IA page


This is an automated message which will be updated as changes are made to the IA page

var script = $('[src*="/js/spice/time/"]')[0],
source = $(script).attr("src"),
// Query is normalized as we'll normalize the generated strings.
// if we have a comma separated query it is in the form:
// "town, state, country" but state is optional
query = decodeURIComponent(source.match(/time\/([^\/]+)/)[1]).toLowerCase().split(','),
isGeneric = /\/generic\//.test(source),
callParameters = decodeURIComponent(source).split('/'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use decodeURIComponentSafe(source) here to avoid page crashing errors?

@nilnilnil
Copy link
Contributor Author

@bsstoner all done.

@nilnilnil nilnilnil assigned MrChrisW and unassigned bsstoner Dec 24, 2015
@nilnilnil
Copy link
Contributor Author

@bsstoner Thanks for the feedback. Handing off to original maintainer @MrChrisW for final review.

I think there is a lot more low hanging fruit here. This still doesn't solve the query time in new york.

@MrChrisW
Copy link
Collaborator

@nilnilnil Have tested, looks good to me.

Any reason you also check the length of callParameters? Assuming 'generic' is found in the call all parameters "should" be found, doesn't make much difference... anyway a comment might be good like @bsstoner suggested.

I'll hand this to @moollaza to merge 👍

🎄

@nilnilnil
Copy link
Contributor Author

I added a comment. Is it confusing? I'm happy to revise. I check it because I don't want to assume everything will be defined properly. It's probably a safe bet though. Didn't see a reason to risk it.

@MrChrisW
Copy link
Collaborator

@nilnilnil Nah it's fine! Makes sense to check the array items exist before using them. 👍 Merry Christmas

@daxtheduck daxtheduck deployed to beta.duckduckgo.com December 25, 2015 18:37 Active
@daxtheduck
Copy link

Automated screenshot from [beta.duckduckgo.com](https://beta.duckduckgo.com/?q=time in Melbourne)

Mobile screenshot

@jagtalon
Copy link
Member

👍

giphy

jagtalon pushed a commit that referenced this pull request Dec 25, 2015
@jagtalon jagtalon merged commit 3519b43 into master Dec 25, 2015
@jagtalon jagtalon deleted the nilnilnil/better-generic-time branch December 25, 2015 19:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants