Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove seconds, regardless if it has AM/PM or not. #968

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

imsaguy
Copy link
Contributor

@imsaguy imsaguy commented Mar 31, 2015

This will trim the seconds, even if the string ends in AM or PM.

This will trim the seconds, even if the string ends in AM or PM.
@@ -57,7 +57,7 @@ window.plugin.scoreCycleTimes.update = function() {

var formatRow = function(label,time) {
var timeStr = unixTimeToString(time,true);
timeStr = timeStr.replace(/:00$/,''); //FIXME: doesn't remove seconds from AM/PM formatted dates
timeStr = timeStr.replace(/:00$|:00(?= [AP]M$)/,'');
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure the (?=) assertion is necessary; why not /:00(?: [ap]m)?$/i instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, although I'd tweak it to be :00(?:\s?[ap]m)?$/i or :00(?: ?[ap]m)?$/i to cover for instances where certain clients aren't giving it how we expect with the space included.

@imsaguy
Copy link
Contributor Author

imsaguy commented Jun 14, 2016

Actually no, I remember now why I had the lookahead. It was to prevent stripping the AM/PM as part of the match.

imsaguy added 3 commits June 14, 2016 02:48
This will trim seconds and minutes if they both end up being :00.  If
local time isn't a whole hour step from UMT, the minutes won't be :00
and instead will be :30 or whatever the step is while still trimming the
seconds.  If seconds are somehow not :00, they'll remain.  The lookahead
is to keep am/pm from being stripped.
@imsaguy
Copy link
Contributor Author

imsaguy commented Jun 14, 2016

I'll let you do the merge and squash if you decide to take the pull versus doing the squash on my end.

@dingram
Copy link
Contributor

dingram commented Jun 14, 2016

I'll end up squashing, but I see you've added a repeat group to the :00. I'd prefer not to change "11:00:00 am" to "11 am", so that all entries have a consistent style.

@imsaguy
Copy link
Contributor Author

imsaguy commented Jun 14, 2016

Will unixTimeToString always return seconds? If not, a single :00 will
cause 9:00 am to truncate to 9 am. Do we need to account for that cause?
On Jun 14, 2016 12:39 PM, "Dave Ingram" [email protected] wrote:

I'll end up squashing, but I see you've added a repeat group to the :00.
I'd prefer not to change "11:00:00 am" to "11 am", so that all entries have
a consistent style.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#968 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AA-GFU2PjpXKGfMfRzcvGUONqfrpILcyks5qLudLgaJpZM4D4Dga
.

@PrinterElf
Copy link

Maybe just me, but I'm not sure why we have am/pm inn the first place - 24hr clock all the way to avoid ambiguity

@dingram
Copy link
Contributor

dingram commented Jun 14, 2016

@imsaguy Under the hood, unixTimeToString calls toLocaleTimeString, which always returns seconds.

That being said, we don't have any guarantees about exactly how that output is formatted. Maybe we should detect whether the user prefers 12-hour or 24-hour and then just use a specific canned format rather than a locale-specific one. There are many more outputs returned than this function copes with — see the MDN page linked above for some examples.

@PrinterElf Many American agents in particular prefer the 12-hour clock to 24-hour.

@nexushoratio
Copy link
Contributor

I think the filtering of am/pm should be done on as part of the API rather than post processing such as we see here. Otherwise, it'd be just was straightforward to make this a Date object here and format it the way you please, rather than trying to parse random strings. And if someone else tweaks unixTimeToString() later on, you wouldn't have gained much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants