假期 - 有 Java 实现吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3388673/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 22:51:29  来源:igfitidea点击:

Holidays - is there a java implementation?

javadate

提问by Espen Schulstad

I'd like to know if there is a jar-file out there that could do the following:

我想知道是否有一个 jar 文件可以执行以下操作:

DateMidnight dateInQuestion = new DateMidnight(12,12,2000);
DateChecker.isNationalHoliday(dateInQuestion, Locale.ITALY);

If there isn't, why? Surely there are lots of properly based rules for the holidays in 99% of the times.

如果没有,为什么?当然,在 99% 的情况下,假期都有许多适当的规则。

Right now we're mainting a table in our database, with the countries + we have some implementation when it comes to holidays that aren't on the same date every year. We have to add to our implementation for every new country we get new customers.

现在我们在我们的数据库中维护一个表格,国家+我们在每年不同日期的假期方面有一些实施。我们必须为我们获得新客户的每个新国家添加我们的实施。

Could we do this an easier way?

我们能不能用更简单的方法来做到这一点?

(If there is no such thing in the java sphere, can I port it from some other language?)

(如果java领域没有这样的东西,我可以从其他语言移植它吗?)

采纳答案by BalusC

Nothing robust exist in Java as far as I know. It also makes sense, this kind of information is namely extremely sensitive to changes. Hardcoding it would make your code potentially break on every Java update which may lead to lot of maintenance and compatibility troubles. Currently at hightest the timezones are hardcoded/maintained in Java SE and even alone that has already lead to many bugs.

据我所知,Java 中不存在任何健壮的东西。这也是有道理的,这种信息对变化极其敏感。对它进行硬编码会使您的代码在每次 Java 更新时可能会中断,这可能会导致大量维护和兼容性问题。目前最高时区是在 Java SE 中硬编码/维护的,甚至单独存在已经导致许多错误

Rather use a public webservice for that. E.g. http://www.bank-holidays.com

而是为此使用公共网络服务。例如http://www.bank-holidays.com

This site informs you of all the days when banks (as well as stock exchange & school holidays in a number of countries) are closed due to religious or public events. Major events (elections, announced strikes, trade fairs, festivals, sports events...) are also listed.

Our FREE SERVICE allows you to view the current calendar year (view only). For 2 euros/country/year, our PAY SERVICE (click on credit card icon) gives you access to calendar years 2000-2070.

本网站会通知您银行(以及一些国家的证券交易所和学校假期)因宗教或公共活动而关闭的所有日子。还列出了重大事件(选举、宣布的罢工、贸易展览会、节日、体育赛事......)。

我们的免费服务允许您查看当前日历年(仅查看)。对于 2 欧元/国家/年,我们的 PAY SERVICE(点击信用卡图标)让您可以访问 2000-2070 日历年。

And write a Java wrapper around that. Or look for existing Java API's which are in turn already backed by a webservice.

并围绕它编写一个 Java 包装器。或者寻找现有的 Java API,这些 API 反过来已经由网络服务支持。

回答by Willem van Rumpt

I think you'll have to do the work yourself.

我想你必须自己做这项工作。

National holidays are determined by, well, nations. They can change, and are, by definition, not universal, and can thus not be captured by some algorithm.

国定假日是由国家决定的。它们可以改变,并且,根据定义,不是通用的,因此不能被某些算法捕获。

The only way to keep track of them, is to maintain them on a per-nation basis.

跟踪它们的唯一方法是在每个国家的基础上维护它们。

Perhaps someone actually already does that (maybe a webservice of sorts), but I doubt it, to be honest.

也许有人实际上已经这样做了(也许是某种网络服务),但老实说,我对此表示怀疑。

回答by C_Rance

So far I haven seen any. But what I could suggest for u is to try to link with google calendar api, which from there try to get the holiday calendar through the calendar feed or whatever u call it. From there, process the data and if u want, save it into your database. Afterall, as long as you have a active internet connection, you can use java to connect to the relevant data Even for other languages, I dont think that such direct methods are available.

到目前为止,我还没有看到任何。但是我可以为您建议的是尝试与谷歌日历 api 链接,从那里尝试通过日历提要或您称之为的任何内容获取假期日历。从那里,处理数据,如果需要,将其保存到您的数据库中。毕竟,只要你有一个活跃的互联网连接,你就可以使用java连接到相关数据即使对于其他语言,我也不认为这样直接的方法可用。

回答by Pops

My searching has brought up two results (in addition to what I listed in the comments). The first, the Holiday Client API, seems to be a dead project. The second, Jollyday, looks like a very rough, but active, work in progress.

我的搜索带来了两个结果(除了我在评论中列出的结果)。第一个,Holiday Client API,似乎是一个死项目。第二个,Jollyday,看起来很粗糙,但很活跃,正在进行中。

As for whythere is no good library, I'm with Tom. I suspect that your premise "Surely there are lots of properly based rules for the holidays in 99% of the times" is incorrect.

至于为什么没有好的图书馆,我和汤姆在一起。我怀疑您的前提“在 99% 的情况下,假期肯定有很多基于适当的规则”是不正确的。

回答by Sven

I have written the JollydayAPI and I'm interested to know what is so 'rough' about it. How can I improve it? Would be great to hear from you. Send me an email to [email protected] if you like.

我已经编写了JollydayAPI,我很想知道它的“粗糙”之处是什么。我该如何改进?很高兴收到你的来信。如果您愿意,请给我发送电子邮件至 [email protected]

By the way. Jollyday is used just the way as the questioner requests it. Please look for yourself.

顺便一提。Jollyday 按照提问者的要求使用。请自行寻找。

Cheers, Sven

干杯,斯文

P.S.: I found a free webservice from Ulrich Hilger which provides detailed worldwide holiday info. Look at api.daybase.eu

PS:我从 Ulrich Hilger 找到了一个免费的网络服务,它提供了详细的全球假期信息。看看 api.daybase.eu

回答by Guy

I also wrote a java wrapper around the Ruby Holidays Gem (. It's available on Github: https://github.com/gdepourtales/holidays. It works similar to Jollyday (http://sourceforge.net/projects/jollyday/).

我还围绕 Ruby Holidays Gem 编写了一个 Java 包装器(。它可以在 Github 上找到:https: //github.com/gdepourtales/holidays。它的工作原理类似于 Jollyday(http://sourceforge.net/projects/jollyday/)。

回答by Ashok M A

I found this interesting:

我发现这很有趣:

RESTful service provider - Holiday API

RESTful 服务提供者 - Holiday API

For Node projects - node-holidayapi

对于 Node 项目 - node-holidayapi

I know it is not relevent to the question asked for Java implementation. But if your project is RESTful (like most of the projects nowadays) then this would give you a place to start. ;)

我知道这与针对 Java 实现提出的问题无关。但是,如果您的项目是 RESTful(就像现在的大多数项目一样),那么这将为您提供一个起点。;)