简体   繁体   English

Luxon:根据地区设置按工作日开始对所有工作日进行排序

[英]Luxon: Get all weekdays sorted by start of week day depending on locale

Is there a easy way to get all week day names sorted depending on locale?有没有一种简单的方法可以根据语言环境对所有工作日名称进行排序?

Info.weekdays() seems to be pretty close to what I want, but the sorting is not how I would expect it. Info.weekdays()似乎非常接近我想要的,但排序不是我所期望的。

Example:例子:

const info = luxon.Info

console.log(info.weekdays('short', {locale: 'de'}));
// actual: ['Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So']

console.log(info.weekdays('short', {locale: 'en-US'}));
// actual: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
// expected: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']

Is there maybe a util function to get the start of week for a locale to resort this array or is there a more easy approach with the Intl API?是否可能有一个 util function 来获取一个区域设置的一周开始时间来使用这个数组,或者是否有更简单的方法使用Intl API?

Thanks in advance!提前致谢!

Based on tickets in luxon's repo #373 and #939 which are about similar cases and up to discussion - everything was blocked by browser API was not providing such information.基于 luxon 的回购#373#939中关于类似案例和讨论的票证 - 一切都被浏览器阻止 API 没有提供此类信息。

Nowadays, TC39 proposal has already been shipped( source: MDN ) to Chrome 99+, Safari 15.4+, Edge.如今, TC39 提案已经发布( 来源:MDN )到 Chrome 99+、Safari 15.4+、Edge。 Unfortunately, not to Firefox. Yet.不幸的是,Firefox 没有。然而。

Looks like luxon's team did not revisited this feature so far, I don't see any reference to weekInfo in their code, conditional or not.看起来 luxon 的团队到目前为止还没有重新访问这个功能,我没有在他们的代码中看到任何对weekInfo的引用,无论是否有条件。 So you probably better to implement your homebrew algo:所以你最好实现你的自制算法:

(new Intl.Locale('en-GB')).weekInfo.firstDay // 1
(new Intl.Locale('en-US')).weekInfo.firstDay // 7

and if weekInfo will not be available to FF, with fallback to either Sunday or Monday.如果weekInfo对 FF 不可用,则回退到星期日或星期一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM