-
Notifications
You must be signed in to change notification settings - Fork 7k
-
Star 48k
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
get/set the meridiem #3873
get/set the meridiem #3873
Comments
alburthoffman
commented
Mar 29, 2017
just curios about why u want to set the meridiem? for gettting the meridiem, why not get the current hour and do ur own checks? |
maggiepint
commented
Mar 29, 2017
Can you clarify what you mean by this? To get the meridiem you would use an If you are thinking of the use case of setting 8 AM or 8 PM - this isn't supported because it's culture specific. Many cultures actually don't use meridiem, and some of them don't think of it in terms of 12 hours. For instance, look at the implementation of meridiem determination in Azerbaijani: meridiem : function (hour, minute, isLower) {
if (hour < 4) {
return 'gecə';
} else if (hour < 12) {
return 'səhər';
} else if (hour < 17) {
return 'gündüz';
} else {
return 'axşam';
}
} As you can see, in this culture the meridiem changes at both 12:00 and 17:00. So, as you can see, it would get a little crazy to start generalizing this for setting hour values. You could probably hook the `moment().localeData() meridiem functions, if you were looking for locale specific rules. If you're just looking for US AM/PM though, I think a manual adjustment of the hours in your code is just as well. |
erin-doyle
commented
Mar 29, 2017
I'm working on an application that uses a clock style time picker where the user can switch the meridiem. I realize I could get the meridiem by using |
alburthoffman
commented
Mar 31, 2017
it depends the language you use. and have to define meridiem, meridiemParse, meridiemHour in ur locale. checked https://github.com/moment/moment/search?utf8=%E2%9C%93&q=meridiem&type= |
erin-doyle
commented
Mar 31, 2017
•
edited
Loading
edited
I guess I don't follow. It still seems to me like all of that information is already available to |
butterflyhug
commented
Apr 1, 2017
To be clear, it sounds like you're wanting a function to toggle between the two times during a day that have the same numbers on a 12-hour clock? E.g. change 2am to 2pm or vice-versa. We don't have a dedicated API for this, and I don't think we're interested in adding one to the core library due to the considerations that @maggiepint was describing: the notion of a day divided into two halves at 12am and 12pm is a culture-specific thing, and some of Moment's locales work rather differently. That said, if the western notion of AM/PM is indeed what you want, then it's easy enough to implement that as a plugin for your own use: moment.fn.meridiem = function(newMeridiem) {
if (!newMeridiem) {
return this.format('A'); // or `return this.hours() < 12 ? 'AM' : 'PM';`
}
if (newMeridiem.toUpperCase() === 'AM' && this.hours() > 12) {
this.hours(this.hours() - 12);
} else if (newMeridiem.toUpperCase() === 'PM' && this.hours() <= 12) {
this.hours(this.hours() + 12);
}
return this;
} Make sense? You might need something slightly different depending on your requirements, but hopefully this should get you pointed in the right direction. |
butterflyhug
commented
Apr 1, 2017
To elaborate slightly further: @maggiepint pointed out an example where the "meridiem" value changes at midnight, 4am, noon, and 5pm every day. That culture is dividing the day into unequal sections, so it doesn't even make sense to say "keep the same numbers and just set a different meridiem" in locales like that. We try not to implement things that won't make sense in some supported locales. |
erin-doyle
commented
Apr 1, 2017
Ok, yes @butterflyhug you have accurately summed up what it is I'm trying to do and clarified why that's not a realistic ask, thank you! What I was hoping to achieve, with this clock time picker I'm using, is to be totally internationalized, not Western only, which is why the simple check on < or > 12 hours was not sufficient for what I wanted to do. But as I am not nearly as versed on how meridiem works for all cultures I didn't realize that it just doesn't make sense to use at all for certain locales. It sounds like the better fit would be to determine which locales should use a meridiem toggle with 12 hour mode and which are better suited to use 24 hour mode instead. I really appreciate all of the time and help you all spent in explaining this! |
Is it already possible and I just can't find it, or if not, could an enhancement be made to get and set just the meridiem? Or maybe there is a good reason not to that I'm not thinking of?
The text was updated successfully, but these errors were encountered: