根据文化寻找周末
有没有办法使用 .NET 框架根据不同的文化找到构成周末或工作周的日子?例如,一些穆斯林国家的工作周从周日到周四。
Is there a way to find the days that constitute a weekend or workweek based on different cultures using the .NET framework? For example, some Muslim countries have a workweek from Sunday through Thursday.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
没有人能解决这个问题,所以我写了一个。这使用国家/地区来确定一天是工作日、周末还是 1/2 工作日(某些国家/地区为星期六)。这其中存在一些含糊之处,因为在墨西哥,周六的 1/2 天是“惯例”,但不是官方的。对于这样的情况,我将其设置为工作时间。
这涵盖了马来西亚除 3 个省份之外的所有地区,这三个省份与马来西亚其他地区不同。 AFAIK,CultureInfo.Name 对于这 3 个省份没有明显的值。最有趣的国家是文莱,周末是周五和周日。周日,周六为工作日。
代码可以作为项目下载,网址为 现在是周末吗< /a>?主要代码如下:
No one had a solution for this so I wrote one. This uses the country to determine if a day is a workday, weekend, or 1/2 workday (Saturday in some countries). There is some ambiguity in this as in Mexico a 1/2 day on Saturday is "customary" but not official. For cases like this, I set it as work time.
This covers everything except 3 provinces in Malaysia, which are different from the rest of Malaysia. AFAIK, CultureInfo.Name does not have a distinct value for those 3 provinces. Most interesting country, Brunei where the weekend is Friday & Sunday, with Saturday a workday.
Code is downloadable as a project at Is it the weekend? Main code below:
我唯一知道的是如何获得一周的开始日期。也许这会有所帮助:
从
System.Globalization
,也许您会在这个包中找到一些东西。有几个日历类,例如 JulianCalendar、HebrewCalendar 等。在那里也许能找到你想要的东西。
The only thing i know is how to get the day the week starts. Perhaps this can help:
from
System.Globalization
, perhaps you find in this package something.There are several Calendar-Classses like
JulianCalendar, HebrewCalendar
and so on. It could be possible to find there what you want.我不会给你一个 .NET 答案,但我会说你不会以“文化”为基础,而是以国家为基础。
您可以从 IP 获取国家/地区,准确度较高(但永远不会 100%)。之后,我建议您进行大量谷歌搜索,因为我怀疑您是否会找到已经编写的代码。
(您还可以研究一些开源日历/约会程序,尤其是广泛使用的程序,例如 Linux 上的程序,或者可能是 Lightning、Thunderbird 插件。如果您深入研究他们的代码,您可能会找到这方面的数据)
幸运的是不过,你面临的只是磨难,而不是难以实施的事情。
祝你好运!
I won't give you a .NET answer, but I will say that you won't base it on "culture", but rather on country.
You can get country from IP with a fir degree of accuracy (but it will never be 100%). After that, I would suggest a lot of googling, because I doubt that you are going to find the code already written.
(you might also look into some open source calendar/appointment programs, especially widely-used ones, like on Linux, or maybe Lightning, the Thunderbird plug-in. If you wade through their code, you might find the data for this)
Fortunately, though, you just face a grind, rather than something difficult to implement.
Good luck!
发现这个问题很有趣 - 我自己没有答案..但找到了一个有趣的资源 - 也讨论了日历。
日历转换器
found the question interesting - did not have an answer myself.. but located an interesting resource - also discussing calendars.
Calendar converter
以下代码将一直有效,直到最后 2 天在文化中被视为周末。
:)
阿米特·唐克
The below code will work till the time last 2 days are considered as weekends in cultures.
:)
Amit Tonk