Skip to content
/ moment Public
  • 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.

Sign up for GitHub

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

Jump to bottom

get/set the meridiem #3873

Closed
erin-doyle opened this issue Mar 28, 2017 · 8 comments
Closed

get/set the meridiem #3873

erin-doyle opened this issue Mar 28, 2017 · 8 comments

Comments

@erin-doyle
Copy link

erin-doyle commented Mar 28, 2017

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?

@alburthoffman
Copy link
Contributor

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
Copy link
Member

maggiepint commented Mar 29, 2017

Can you clarify what you mean by this? To get the meridiem you would use an A token in the format function.

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
Copy link
Author

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 format() but there is no way to easily set it. It seems to me that since moment already has all of this wonderful locale specific information about what hours equal what meridiem values then it would be much easier to have a setter than for others to try to replicate that logic. It's the only part of the time that there isn't a getter and setter for.

@alburthoffman
Copy link
Contributor

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
Copy link
Author

erin-doyle commented Mar 31, 2017

I guess I don't follow. It still seems to me like all of that information is already available to moment and would be much easier for moment to determine without the consumer application having to replicate all of that logic and checking. If I set the locale then I would think calling a moment().meridiem() or moment().meridiem('PM') would be simpler. But maybe there is an aspect I'm just not understanding?

@butterflyhug
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Author

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!

@erin-doyle erin-doyle closed this as completed Apr 1, 2017
@marwahaha marwahaha mentioned this issue Apr 3, 2017
Feature request: allow parsing 12 noon / 12 midnight and formatting 12 noon / 12 midnight #3760
Closed
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

No branches or pull requests

4 participants
@butterflyhug @alburthoffman @maggiepint @erin-doyle

Footer

© 2024 GitHub, Inc.

玻璃钢生产厂家南通如东各种玻璃钢雕塑海南玻璃钢雕塑深圳小区玻璃钢雕塑供应厂家上海商场圣诞美陈官渡区玻璃钢雕塑定做厂家骑士马玻璃钢雕塑装饰性玻璃钢雕塑惠州联众玻璃钢花盆北京超市商场美陈价格成都创意玻璃钢雕塑批发暗黑色玻璃钢花盆批发玻璃钢桃子雕塑哪里好蒙城五一商场美陈安徽人物玻璃钢雕塑设计沈阳玻璃钢农耕人物雕塑汕尾玻璃钢雕塑公司山东装饰商场美陈生产厂家评价高的玻璃钢雕塑造型贴金舞阳玻璃钢雕塑厂家知名玻璃钢雕塑推荐云南抽象玻璃钢雕塑订做价格铁岭玻璃钢雕塑定制价格焦作玻璃钢卡通雕塑制作流程宁德玻璃钢马雕塑鹰潭定制玻璃钢雕塑多少钱海盐玻璃钢雕塑厂家山东超市商场美陈研发长沙专业不锈钢玻璃钢彩绘雕塑宿迁玻璃钢人物雕塑批发广场玻璃钢卡通雕塑哪里买香港通过《维护国家安全条例》两大学生合买彩票中奖一人不认账让美丽中国“从细节出发”19岁小伙救下5人后溺亡 多方发声单亲妈妈陷入热恋 14岁儿子报警汪小菲曝离婚始末遭遇山火的松茸之乡雅江山火三名扑火人员牺牲系谣言何赛飞追着代拍打萧美琴窜访捷克 外交部回应卫健委通报少年有偿捐血浆16次猝死手机成瘾是影响睡眠质量重要因素高校汽车撞人致3死16伤 司机系学生315晚会后胖东来又人满为患了小米汽车超级工厂正式揭幕中国拥有亿元资产的家庭达13.3万户周杰伦一审败诉网易男孩8年未见母亲被告知被遗忘许家印被限制高消费饲养员用铁锨驱打大熊猫被辞退男子被猫抓伤后确诊“猫抓病”特朗普无法缴纳4.54亿美元罚金倪萍分享减重40斤方法联合利华开始重组张家界的山上“长”满了韩国人?张立群任西安交通大学校长杨倩无缘巴黎奥运“重生之我在北大当嫡校长”黑马情侣提车了专访95后高颜值猪保姆考生莫言也上北大硕士复试名单了网友洛杉矶偶遇贾玲专家建议不必谈骨泥色变沉迷短剧的人就像掉进了杀猪盘奥巴马现身唐宁街 黑色着装引猜测七年后宇文玥被薅头发捞上岸事业单位女子向同事水杯投不明物质凯特王妃现身!外出购物视频曝光河南驻马店通报西平中学跳楼事件王树国卸任西安交大校长 师生送别恒大被罚41.75亿到底怎么缴男子被流浪猫绊倒 投喂者赔24万房客欠租失踪 房东直发愁西双版纳热带植物园回应蜉蝣大爆发钱人豪晒法院裁定实锤抄袭外国人感慨凌晨的中国很安全胖东来员工每周单休无小长假白宫:哈马斯三号人物被杀测试车高速逃费 小米:已补缴老人退休金被冒领16年 金额超20万

玻璃钢生产厂家 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化