Whats the best java date recurrence pattern calculator - java

Anyone know of a (reliable) date recurrence calculator, we're trying
to implement something in our app which would allow a schedule to be
created, similar to those for recurring meetings in Outlook. We have
tried chronos but discovered some cases where it breaks down, I'd
really appreciate knowing if anyone has successfully used any of the
other options out there.
Cheers,
Robin

This is a frequent question on the joda time mailing list and the usual answer is to try RFC 2445. Disclaimer: I have not used it myself.

Check out Lamma date (I wrote it recently), which is designed to generate dates based on a recurrence pattern.
For example:
import static io.lamma.LammaJavaImports.*;
Dates.from(2010, 1, 1).to(2019, 12, 31).byYears(3).on(Locators.nth(3, FRIDAY).of(FEBRUARY)).build();
will generate the third Friday of February for every 3 years in 2010s
Output:
List(2010-02-19, 2013-02-15, 2016-02-19, 2019-02-15)

Check out Quartz, it's a really handy tool:
http://www.quartz-scheduler.org/

Related

How to convert ISO code to localized measure unit in java?

I'm currently trying to convert ISOCODE measure units into the fulltext labels.
For example I'll receive a string such as "LTR" and try to convert it to "Liter". It's in german so I'm also looking for a possibility to do this localized.
Is there a library or so which is already doing this? Is there an enum somewhere, containing all these information?
Otherwise, I guess I'll just have to create one myself.
Thanks a lot.
JSR 363 deals with units of measurement and has been implemented in UOM . You can browse the javadoc to get an idea of what's in there.
There was a project called the JScience project, but it doesn't seem to have been updated for some time.

Implementing twitter and facebook like hashtags

This might look really silly.. and a question with no research, but trust me it is not. I have done some research on it. One of them would be the following link:
http://www.quora.com/Twitter-1/How-does-Twitter-implement-hashtags
Also I am not looking for a complete solution here.. I will do my hard work, but I just need some guidance regarding this, just want to know which way should I approach?
I want to implement twitter and now even facebook like hashtags for my application.. So that users can add messages with hashtags and others can search over them.. like what is trending and what is relevant.
We are using Mysql, mongo and elasticsearch in our storage tech stack. any ideas how could I start working to implement this? Would I need another storage? One way is that I can store my hastags in db and then do a text search for them in Elasticsearch.
What can people with more experience in this field suggest here?
A start with MongoDB would be to parse each message for hashtags the user used and put these into a sub-array of the document. Example status update:
Peter
April 29th 2014 12:28:34
Hello friends, I visited the #tradeshow in #washington and drank a delicious #coffee
This message would look like this in MongoDB:
{
author: "Peter",
date: ISODate("2014-04-29 12:28:34"),
text: "Hello friends, I visited the #tradeshow in #washington and drank a delicious #coffee",
hashtags: [
"tradeshow",
"washington",
"coffee"
]
}
When you then create an index on db.collection.hashtags you can quickly search for all messages which include one of these hashtags. You likely want to order and limit the results by date so the user sees the most recent results first. When you make it a compound index which also includes the date, you can also speed that up.
How to implement "trending" topics is a quite complex question. It is also very subjective depending on what you would consider "trending". The exact algorithms Twitter or Facebook use to determine which topics are trending or not is not public. According to various social media analysts they also change them frequently, so we can assume that they are quite complex by now.
That means we can not help you to come up with an algorithm on your own. But when you already have an algorithm in mind to calculate the "trendyness" of a hashtag, we could help you to find a good implementation.

Generic Date Parsing Library from unstructured text [duplicate]

This question already has answers here:
Natural Language date and time parser for java [closed]
(8 answers)
Closed 6 years ago.
Can somebody suggest any Library in Java which is capable of parsing Date/Time Calendar Event from Unstructured Data.
Example
Starts 10pm Tonight! Sunday feb 10th => 10/Feb/2013 10pm
tomorrow (feb 10th) => 10/Feb/2013
Sunday Feb 10\r\nwith daily screenings till Feb 16th
and so on
The input data comes from user, so he may enter data in any random format.
I started of identifying all the possible token and do a regex match to phrase all tokens.
I wonder if someone can suggest some Library in Java, which might actually help in parsing.
I ran through other post on SO, but they seem to suggest techniques, i wonder if somebody has a library.
Thanks
You could take some of the trunk source from Apache openLNP (natural language processing) at http://opennlp.apache.org/ or just set up a callable RESTful web service by implementing openNLP on your server. Benefit of implementing the OOB openNLP is you have entity extractors through the nameFinder interface for dates, times, organizations, locations, and people. You would also be able to build an example file of more typical context for the items of interest indicating their appropriate entity type and train the NLP model against it to gain a better hit rate for your context. I have a working example of a C# NLP in the apps section of my portfolio at http://www.augmentedintel.com/apps/csharpnlp/extract-names-from-text.aspx.
UTAH (https://github.com/sonalake/utah-parser) is able to handle generic parsing of unstructured text into maps. Once you've done that you should be able to throw that into a formatter.

Get the Next Date of the following Sunday (Not using Calendar)

I need a solution to get the next Sunday's date, please no "Calendar" I am using GWT and it does not compile.. too many errors. I need an alternate solution... I am kind of new to java and have spent two days "just" trying to programatically get the next Sundays date.. Please help me (No Calendar Class please)
Regards
You want a perpetual calendar algorithm. Several are outlined here: http://en.wikipedia.org/wiki/Calculating_the_day_of_the_week

Holidays - is there a java implementation?

I'd like to know if there is a jar-file out there that could do the following:
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.
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?)
I have written the Jollyday API 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 sdiedrichsen#yahoo.de if you like.
By the way. Jollyday is used just the way as the questioner requests it. Please look for yourself.
Cheers, Sven
P.S.: I found a free webservice from Ulrich Hilger which provides detailed worldwide holiday info. Look at api.daybase.eu
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.
Rather use a public webservice for that. E.g. 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.
And write a Java wrapper around that. Or look for existing Java API's which are in turn already backed by a webservice.
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/).
I found this interesting:
RESTful service provider - Holiday API
For Node projects - 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. ;)
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.
As for why there 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.
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.
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.
You can use my holiday api, there is also a docker container available to run the whole thing.
https://github.com/nager/Nager.Date
Webservice
Get the public holidays for Italy for the year 2000
https://date.nager.at/api/v2/PublicHolidays/2000/IT
More information about the available API methods you can found here
Java Example
//https://github.com/FasterXML/jackson-databind/
ObjectMapper mapper = new ObjectMapper();
MyValue value = mapper.readValue(new URL("https://date.nager.at/api/v2/PublicHolidays/2000/IT"), PublicHoliday[].class);
PublicHoliday.class
public class PublicHoliday
{
public String Date;
public String LocalName;
public String Name;
public String CountryCode;
public Boolean Fixed;
public Boolean Global;
public String[] Counties;
public String Type;
}
Example JSON data retrieved
[
{
"date": "2000-01-01",
"localName": "Capodanno",
"name": "New Year's Day",
"countryCode": "IT",
"fixed": true,
"global": true,
"counties": null,
"type": "Public"
},
...
]

Categories

Resources