JSF Need to refresh with another result Date+days - java

I have a JSF form with 2 dates. Start Date is required.
2 things I would need:
When the End date is filled in --> Then the Days should be calculated and filled in.
When the Days are filled in (example: 31) --> Then the End date should be filled in.
How can this be done in JSF?
You might seen the same case as me, but what I looking for how calculate Days If Start Date Is Filled can someone help me please

Related

How to get the update frequency of websites

I need to build a web service that analyzises SEO. The service will show how often the site was updated. I need to figure out how to get the posted date or update frequency from the HTML of the website.
For example on http://googletesting.blogspot.com/ I can get date from the tag <span>Wednesday, June 04, 2014</span>. Other websites don't use the same tags and date format so I can't us the same code to detect those dates.
(Dates can have very different formats in different locales. Also, month names can be written as text or as number. I need to match as much dates as possible.Sometime,date format isn't posted date but it's just words in articles.
My Algorithm about this
I attempt to get "posted date" from all posted then calculate update frequency.
Such as Fist posted at 30May 2012, Second posted at 29May2012, Third posted at 28May2012
So I will get result that this website was updated dairly
In the end, I want to know if each website updates:
Yearly
Monthly
Weekly
Daily
How do I reliably get this from any website?
Instead of parsing the dates in the page, you could download the home page and store it. Then you could come back every day and download the homepage again to see if it changed. This approach would work even for sites that don't publish any dates on their homepage. It would take longer to get your answer though.
Another approach would be to download the RSS feed for the site if it has one. The example site you give one has an XML feed: http://feeds.feedburner.com/blogspot/RLXA?format=xml RSS feeds are meant to be machine readable and the dates are in a consistent format.
You also say that you are using Java. I've found that Java's date parsing libraries are not very flexible. They force you to know the exact format of the date before you parse it. I have written a free, open source flexible date time parser in Java that you could try: http://ostermiller.org/utils/DateTimeParse.html Once you found dates on the page (maybe for looking at what comes after "posted on"), you could use my flexible parser to parse dates in a variety of formats.

Creating a unique date each time between calls

I am writing a Java program using selenium. I need a function that returns a unique date (mm/dd/yyyy) each time it is called. The conditions though are that
It can never return a date it returned before
Is must return a date between 01/01/2071 and 12/31/9999
The program will run many times so all program memory will be lost upon termination. It
must remember the dates it has returned before. See next item
The easiest way to do this is just keep incrementing the date by 1 day each time, so it
needs to remember only 1 date.
Unfortunately I cannot write the last date returned to a file in the system to read it
next time the program runs because I do not have that ability.
The program will be reading data from an Excel spreadsheet so could theoretically store
the latest date in a cell, but the spreadsheet will be open and it does not seem to
have the ability to write to an open file.
Any thoughts? One thing I thought about doing was using a base date like 1/1/2014 at 00:00:00 and then taking the current date, calculating the number of minutes between the two, and adding this as a number of days to 11/31/2070. Unfortunately this would work only a couple of years because then there would be more minutes between the two dates than there are days from 1/1/2017 to 12/31/9999
Any help is appreciated.
Thanks

Primefaces Calendar select week instead day

I am using primefaces calendar. I want to select a week instead of selecting a day.
I found out it was possible in primefaces 2.0 to have an array of days in backbean instead of one date object. I am using version 4 and it is not possible anymore. I was thinking if i could use the week number as the pattern and use the popup calendar it will show the week number in the text field. However it worked first time i tried, but second time i want to choose a date it will only display "w". Is the anyway to make this work?
i was thinking to use a converter which convert the week number to a date because my theory is that calendar cant convert the week number to date by it self. I am not familiar using converters? I will appreciate any help.
<p:calendar value="#{bean.date}" locale="en" pattern="w">

Change link to download every 7 days?

I'm downloading a certain website in html format to my device, so that I can display it in webview in offline mode. The only problem is that the link is dynamic, and it changes once a week. To keep the html item updated as much as possible, I want the app to download it once a week.
Let's say for example that this is the websites address:
www.mywebsite.com/1
Next week, the address will be:
www.mywebsite.com/2
And week after that, the website will be:
www.mywebsite.com/3
I already figured I would do this be declaring a variable that would be changing, something like
int week;
String urlToDownload = "www.mywebsite.com/" + week;
But how do I make it so that this variable will change everyday even if the app is not started, or is there a better way to do this?
You can maybe use AlarmManager class. That allows you to plan something on the background, when app is not even running.
I would use the most simple solution. Do you know what time does the URL change? You can always check the time of previous start of application and when next app is started check it and determine how many weeks is from that.
Use the java.util.Calendar
Calendar calender = Calendar.getInstance();
MyLog.d("Current Week:", "" + calender.get(Calendar.WEEK_OF_YEAR));
This prints "Current Week: 37"
With that maybe you can write code to get the appropriate page. The week nr are kind of static
You can update the variable during the onStart() phase. Make a constant that has the start date, and then get the current date and figure out the offset. This way even if the app hasnt been started in a long time, once it is started you will have the proper link.

Getting timezone offset with Joda Time

I got hopelessly stuck on this task. I get other-than-UTC future date input from user > I need to persist it as UTC time. I tried various ways, but it always ends up like this: (method names are irrelevant)
Could please anybody give me the right direction ?
It looks like you're already doing the right thing in the first line. With slight modification:
DateTime instant = getDeadLine(orderBean, localTz);
DateTime.getMillis() will give you the number of milliseconds since the UTC epoch... so that's what you need to persist. If you need to be able to convert back to local time, you'll need to know which time zone to convert back to of course - either using the same one every time, or storing it along with the UTC millis.
One thing to note is that local dates/times aren't always unambiguous - the same local date/time can occur twice due to daylight saving transitions. You'll need to think about whether that will ever be relevant to you.

Categories

Resources