JSTL Date Compare Question

I am using JSTL to parse an xml feed (news articles) and need to restrict the articles I get back in the xml to todays date. On another page I am working on I have to restrict the articles to todays date - 7 days (one week). I understand how to parse and format dates with jstl, but am stuck on doing date compares like this. The date I have to restrict on in the xml feed is called <pubDate>. If anyone could help me out with using JSTL to parse and handle these date ranges that would be great. Here is a portion of the xml I am dealing with:
- <!-- Item 1 of todays_free_feature
-->
- <item>
<title>Building an Online Library</title>
<link>http://online.wsj.com/public/article/0,,SB113111987803688478-VNpw62xi_JA4avE8cxOZf0pf_nM_20061109,00.html?mod=rss_free</link>
<description>Liz Ridolfo is one of several foot soldiers engaged in an ambitious effort to digitize the world's libraries, one volume at a time.</description>
<pubDate>Tue, 08 Nov 2005 20:22:00 EST</pubDate>
</item>
- <!-- Item 2 of todays_free_feature
-->
- <item>
<title>Guest-Worker Proposals Prove Divisive</title>
<link>http://online.wsj.com/public/article/0,,SB113149831207391770-V6OGF4bCCsOhJlj0ZAPd1jKIMUg_20061109,00.html?mod=rss_free</link>
<description>Bush is proposing a guest worker program that business loves and the Senate seems eager to pass, but the issue splits Republicans eager to help business from those concerned about border security, job losses and the nation's identity.</description>
<pubDate>Tue, 08 Nov 2005 23:02:00 EST</pubDate>
</item>
- <!-- Item 3 of todays_free_feature
-->
- <item>
<title>Changing Times at the Fed</title>
<link>http://online.wsj.com/public/article/0,,SB113136589127989951-biMkDwuEVMUvrmqav2YE8OCApTk_20061109,00.html?mod=rss_free</link>
<description>Alan Greenspan will soon step down as Federal Reserve chairman and hand the reins to Ben Bernanke. But that's not the only change likely to be in store at the U.S. central bank. William Polley and Tim Duy to explore what the future might hold for the seat of U.S. monetary policy.</description>
<pubDate>Tue, 08 Nov 2005 20:46:00 EST</pubDate>
</item>
- <!-- Item 4 of todays_free_feature
-->
- <item>
<title>Protecting Ideas Is Crucial for U.S. Business</title>
<link>http://online.wsj.com/public/article/0,,SB113149228287891613-mKwE4jbbsNWEvRsGvadhQNc6tGI_20061109,00.html?mod=rss_free</link>
<description>Intellectual property is one of the thorniest problems facing modern capitalism. The challenge is to protect creators' right to profit while still ensuring that the benefits of their creations are widely spread.</description>
<pubDate>Tue, 08 Nov 2005 22:50:00 EST</pubDate>
</item>

I had problems following your advice, hence I used a different formatter
<fmt:formatDate var="nextRunStr" value="${reminder.nextRunDateTime}" pattern="yyyyMMddHHmmss"/>
                              <fmt:formatDate var="nowStr" value="${now}" pattern="yyyyMMddHHmmss"/>
and then
${nextRunStr ge nowStr}"
seems to work OK.

Similar Messages

  • Comparable question

    I'm having some trouble implementing the Comparable interface with the code I'm writing, but basically the idea in general.
    For example, I'm builing a BSTree class, with a BTNode (with left, right BTNodes, and a Comparable data object). Of course, in order to use some of the methods in a BSTree, you must compare two objects, to decide whether to traverse left or right, etc...
    Anyway, how would I implement the compareTo() method with the BSTree class? And should I create a compareTo() method in the BSTree class, and define the body such as:
    public int compareTo(Comparable c){
    if(c instanceof BSTree)
                   BSTree other = (BSTree)c;
                   return this - other;
              else throw new IllegalArgumentException();
         }//compareTo()
    from this calling code, let's say: int c = target.compareTo(root.data);
    where target is the Comparable object I'm searching for, root is the BTNode pointer, and data the Comparable object in the node.
    And another question: If I use define a class that uses BSTree instances, would I have to have that class implement Comparable as well? Or would it just inherit that quality from the BSTree class?
    Thanks.

    I instead want to compare the data in a binary search
    tree, as to insert a new element in the right
    position.
    I'm confused as to which class to implement the
    Comparable interface.
    If you want to compare the data, you should make the data comparable.
    You could also consider making the node class comparable to shorten code. If you did that you could write     node1.compareTo(node2)instead of having to go the long way    node1.getData().compareTo(node2.getData())> Say in my BTNode class, I have a left and right
    pointer. For the data element, should I just use an
    Object instance? I believe you cannot instantiate
    Comparable, so I guess I can't do : Comparable data.
    You can do that. What you can't do is actually instantiate it using "new Comparable()" so the code will end up looking somewhat like    Comparable c;
        // integer implements comparable:
        c = new Integer(42);Often it makes sense to do this; in many projects I've found it useful to define variables with the most general possible supertype. Like if I find that I I need a Map (an interface just like Comparable) I can declare it as "Map myMap;" and assign specific implementation to it as in "myMap = new HashMap();" If later I find that TreeMap or some custom Map implementation would be more appropriate I only need to change one line and nothing else.
    And I send in a Comparable as an insert() parameter.
    My question is, would I implement the Comparable
    interface from the calling class, or the BTNode class,
    or the BSTree class (class using BTNode to construct a
    Binary search tree). And would I have to override the
    compareTo() method in one of the classes, to see if
    it's an instance of the other, etc.
    When you write "class X implements Comparable" you are saying that instances of class X can be compared to each other so that it's possible to sort them in an unambiguous way. What you want to compare is up to you, but I don't think it would be meaningful to compare full binary search trees to each other.

  • SQL Server Data Compare doesn't retrieve table list

    I'm trying to do a data compare in Visual Studio 2013.  I have chosen my source and targets and successfully tested the connection to each of them in the connections dialog. 
    When I choose next, there's a few seconds delay as though the compare tool is checking with the source and target and then it shows a dialog with what to compare.  There is a checkbox next to Tables and next to Views.  Those are the only two options
    shown. 
    What should be in this dialog, left of Tables and Views, is an arrow to expand them and show the list of tables and views in the source database.  The arrow is missing and I cannot expand any list of tables or views.  There's just nothing shown
    to compare.
    When I click Next again, the compare appears to run but when complete it reports that zero tables or views were compared - under the circumstances this is as expected because the previous dialog did not allow me to check any tables to compare.
    Why am I not getting the arrow to expand the list of tables?  What's wrong with Data Compare?
    Thanks,
    Dale

    Hi Dale,
    >>In your image you show a primary key value in comparison key but my tables did not have a primary key assigned
    >>Is the comparison key requirement by design? 
    I repro it, I get the same issue as yours, if no key, we couldn't compare the tables.
    Like the document here:
    https://msdn.microsoft.com/en-us/library/dn266029%28v=vs.103%29.aspx?f=255&MSPPError=-2147217396
    https://msdn.microsoft.com/en-us/library/aa833428(v=vs.100).aspx
    Requirements
    When you compare data in a table or view, the table or view in the source database must share several attributes with a table or view in the target database. Tables and views that do not meet the following criteria are not compared and do not appear
    on the second page of the      New Data Comparison   wizard:
    Tables must have matching column names that have compatible data types.
    Names of tables, views, and owners are case-sensitive.
    Tables must have the same primary key, unique index, or unique constraint.
    Views must have the same unique, clustered index.
    You can compare a table with a view only if they have the same name.
    Each object has a key or an index that determines the other objects to which it corresponds. However, each table or view can have more than one primary key, unique index, or unique constraint. Therefore, you might want to specify which key, index,
    or constraint to use.
    As my understanding, it would have the specific requirements.
    Best Regards,
    Jack
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • VS2012 SQL Data compare

    Dear Sirs,
    Concerning the tools comparing data in VS2012(SQL - Data compare ) it is possible to run this comparison by timer  for example :" each two minutes comparing the database if not equal update the target".
    Best Regards
    Nicolas Chami

    Hi Nicolas. It sounds like what you want is to enable replication on your database.
    Here is the main help page
    for replication. This should have the right links to get you started. Regards,
    Kevin

  • Where's Data Compare?

    I've been away from the Microsoft stack for a few years doing Java but I have kept up my MSDN subscription and still have all the tools. 
    Somewhere, while I wasn't looking, it appears that Data Dude (the Database Pro version/tools in Visual Studio, has disappeared.  Now I find myself trying to do a data compare between two tables in the same database, even tried duplicating the problem
    across two different databases, and I can't get a data compare to work.
    I downloaded the SQL Server Data Tools - both editions: SQL Server and Visual Studio - and I find the data compare on the Visual Studio version - but not at all like the current VS2013 blogs and instructions present it.  I was able to add the two connections
    I need and run the compare but there are no results.  The compare window says there were 0 tables or views compared.
    What gives?  What do I need to do to get a data compare, either in two separate databases or two tables in the same database, to work?  Please Help!

    Thanks, Joe.  I found the menu item; it's not where it was in earlier versions where there was a Data menu.  You're right about the same-DB compare.  I had to do just as you said, create a new DB and copy one table there.
    The other change between the early, red-gate-based, data compare in Visual Studio is that now you must have a primary key defined on both tables.  My tables were throwaway tables just for purposes of this test and didn't have primary keys assigned. 
    I didn't get a compare until I added the primary keys.
    Right, you must have a primary key so that Data Compare knows which rows to compare. If you don't have a primary key the table name will not come up in the list of tables available for comparison.

  • The DATA CAP MEGA THREAD....post data cap questions or comments here.

    In the interest of keeping things orderly....This is the DATA CAP MEGA THREAD....post data cap questions or comments here.
    Please keep it civil.
    Comcast is testing usage plans (AKA "data caps") in certain markets.
    The markets that are currently testing usage plans are:
    Nashville, Tennessee market: 300 GB per month and additional gigabytes in increments/blocks ( e.g., $10.00 per 50 GB ). 
    Tucson, Arizona market: Economy Plus through Performance tiers receive 300 GB. Those customers subscribed to the Blast! Internet tier receive 350 GB; Extreme 50 customers receive 450 GB; Extreme 105 customers receive 600 GB. Additional gigabytes in increments/blocks of 50 GB for $10.00 each in the event the customer exceeds their included data amount. 
    Huntsville and Mobile, Alabama; Atlanta, Augusta and Savannah, Georgia; Central Kentucky; Maine; Jackson, Mississippi; Knoxville and Memphis, Tennessee and Charleston, South Carolina: 300 GB per month and additional gigabytes in increments/blocks ( e.g., $10.00 per 50 GB ) Economy Plus customers have the option of enrolling in the Flexible-Data plan.
    Fresno, California, Economy Plus customers also have the option of enrolling in the Flexible-Data plan.
    - If you live outside of these markets you ARE NOT currently subject to a data plan.
    - Comcast DOES NOT THROTTLE your speed if you exceed your usage limits.
    - You can check out the Data Usage Plan FAQ for more information.
     

    I just got a call today that I reached my 300GB limit for the month.  I called and got a pretty rude response from the security and data usage department.  The guy told me in so many words that if I do not like or agree with the policy that I should feel free to find another service provider.!!! I tried to explain that we watch Netflix and XFinity on-demand alot and I was told that that can not be anywhere close to the data usage. I checked my router and watching a "super HD, dolby 5.1" TV show on Netflix will average about 5-6 GB per hour (1.6MB/s) ... sp this means that I can only watch no more than 1-2 Super HD TV shows a day via Netflix before I run out of my data usage.    This seems a bit redicilous doesn't it? Maybe the TV ads about the higher speed than the competition should be accompanied with "as long as you don't use it too often"   Not a good experience ... 

  • Data archieving  questioner required

    Dear All,
    We have been approched by one of our cleint for DATA ARCHIVING from R/3 system.
    Management has pushed my name in this.
    Requirement is to prepare DATA ARCHIVING QUESTIONER template.
    Can please anybody help me out in this regard from MM point of view.
    Thanking you in advance.
    Regards
    Nasir Chapparband.

    Hi,
    Refer following link;
    [http://itmanagement.earthweb.com/datbus/article.php/3109221]
    SAP Data Archiving
    1.0 Introduction to Enterprise Data Archiving
    Currently, a large number of enterprises use SAP R/3 as a platform for integration of business processes. The continuous usage of SAP results in huge amounts of enterprise data, which is stored in SAP R/3. With passage of time, the new and updated data is entered into the system while the old data still resides in the SAP enterprise system.
    Since some of the old data is critical, it cannot be deleted. The difficulty is keeping the data you want, and deleting the data you do not want. Hence, a SAP database keeps on expanding rapidly and enterprise systems, which have limited data retention abilities for a few years, suffer from problems such as data overflow, longer transaction processing times, and performance degradation.
    The solution of this problem has led to the concept of Data Archiving in SAP. Data Archiving removes out-of-date data from the SAP database that the R/3 system does not need online, but can be retrieved on a later date, if required. This data is known as archived data and is stored at an offline location. Data Archiving not only consistently removes data from the database but also ensures data availability for future business requirements.
    One rule of thumb is that in a typical SAP enterprise system, the ratio of data required to be online and instantly accessible to old data, which could be archived, and stored offline is 1:6. For example, if an enterprise has 2100 GB of SAP database, the online data, which is frequently used by SAP users will be 300 MB and the rest (1800 MB) will be scarcely used and hence can be archived.
    1.1 Data Archiving u2013 Features
    It provides a protection layer to the SAP database and resolves underperformance problems caused by huge volumes of data. It is important that SAP users should keep only minimal data to efficiently work with database and servers. Data archiving ensures that the SAP database contains only relevant and up-to-date data that meet your requirements.
    Data archiving uses hardware components such as hard disks and memory. For efficient data archiving, minimum number of disks and disk space should be used.
    It also reduces the system maintenance costs associated with the SAP database. In the SAP database there are various procedures such as, data backup, data recovery, and data upgrade.
    SAP data archiving complies with statutory data retention rules that are common and well-proven techniques.
    SAP data archiving can be implemented in two ways. In the next section both options will be discussed in detail.
    Also refer following link;
    [SAP Data Archiving Tutorial|http://www.thespot4sap.com/articles/SAP_Data_Archiving_Overview.asp]

  • JSTL Date Parse and Format

    Dear Friends,
    I have been trying for the last few days to run the below code but unfortunately I am getting the same error message. I have wasted a lot of time.
    I am using below jar files comes that with JSP(tm) Standard Tag Library 1.1 implementation downloaded from apache.org
    ( I have put the below jar files in Tomcat 5.5\webapps/projectname/WEB-INF\lib)
    1) jstl.jar
    2) standard.jar
    The JSP container I am using is Tomcat 5.5.9. The JDK version using is 6.0
    Please kindly help. Thanks in advance.
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
    <html>
    <head><title>JSTL Date</title></head><body>
    <fmt:parseDate value='10/25/2007 14:00' var='parsedDate' pattern='MM/dd/yyyy kk:mm' />
    Formatted Date :
    <fmt:setTimeZone value='America/New_York' />
    <fmt:formatDate value='${parsedDate}' type='both' timeStyle='full' />
    </body>
    </html>
    ===================================================
    output
    ===================================================
    HTTP Status 500 -
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException: jsp.error.beans.property.conversion
         org.apache.jasper.runtime.JspRuntimeLibrary.getValueFromPropertyEditorManager(JspRuntimeLibrary.java:885)
         org.apache.jsp.count_005fdown_005ftest_jsp._jspx_meth_fmt_formatDate_0(org.apache.jsp.count_005fdown_005ftest_jsp:132)
         org.apache.jsp.count_005fdown_005ftest_jsp._jspService(org.apache.jsp.count_005fdown_005ftest_jsp:73)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    note The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.
    Apache Tomcat/5.5.9
    ===================================================================
    If I change the kk for the hour to hh as below
    <fmt:parseDate value="10/25/2007 14:00" var="${parsedDate}" pattern="MM/dd/yyyy hh:mm" />
    Formatted Date :
    <fmt:setTimeZone value="America/New_York" />
    <fmt:formatDate value="${parsedDate}" type="both" timeStyle="full" />
    I am getting the below error message
    ============================================================
    HTTP Status 500 -
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    javax.servlet.ServletException: javax.servlet.jsp.JspException: In <parseDate>, value attribute can not be parsed: "10/25/2007 14:00"
         org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:844)
         org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
         org.apache.jsp.count_005fdown_005ftest_jsp._jspService(org.apache.jsp.count_005fdown_005ftest_jsp:83)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    root cause
    java.text.ParseException: Unparseable date: "10/25/2007 14:00"
         java.text.DateFormat.parse(Unknown Source)
         org.apache.taglibs.standard.tag.common.fmt.ParseDateSupport.doEndTag(ParseDateSupport.java:178)
         org.apache.jsp.count_005fdown_005ftest_jsp._jspx_meth_fmt_parseDate_0(org.apache.jsp.count_005fdown_005ftest_jsp:102)
         org.apache.jsp.count_005fdown_005ftest_jsp._jspService(org.apache.jsp.count_005fdown_005ftest_jsp:64)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    note The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.
    Apache Tomcat/5.5.9

    You are calling format with a long parameter. The only format that matches that signature that I can see would be Format.format(Object) assuming autoboxing is changing the long to a Long.
    Format.format(Object) eventually calls DateFormat.format(Object, StringBuffer, FieldPosition). I have never used this method so I am not sure what it does.
    Was your intention to actually call this method?
    See the following example:
    System.out.println("Test 1: " + frm.format(new Long(0l), new StringBuffer(), new FieldPosition(0)));  
    System.out.println("Test 2: " + frm.format(new Long(-62167392000000l), new StringBuffer(), new FieldPosition(0)));  
    Test 1: 19700101000000
    Test 2: 00010101000000Edited by: jbish on Apr 26, 2013 12:43 PM
    Edited by: jbish on Apr 26, 2013 1:09 PM

  • Best Practice Question for Date Compares

    Hello,
    I'm far from an expert on Oracle and PL/SQL, so I may have this all wrong.  I'm working on some selection scripts, and the guy that wrote these before me likes to convert parts of dates to numbers in order to do a compare.  It seems to me a trunc(date, part) would be much more efficient.  Can anyone confirm my thoughts here?
    I'm seeing this a lot:
    AND    TO_NUMBER (TO_CHAR (scheduleddate, 'YYYY')) = TO_NUMBER (TO_CHAR (SYSDATE - 1, 'YYYY'))
    Seems to me that I'd be better off just doing:
    trunc(scheduleddate, 'YEAR') = trunc(SysDate, 'YEAR').
    Does that make sense?
    Thanks!
    Chad

    CSchrieber wrote:
    Hello,
    I'm far from an expert on Oracle and PL/SQL, so I may have this all wrong.  I'm working on some selection scripts, and the guy that wrote these before me likes to convert parts of dates to numbers in order to do a compare.  It seems to me a trunc(date, part) would be much more efficient.  Can anyone confirm my thoughts here?
    I'm seeing this a lot:
    AND    TO_NUMBER (TO_CHAR (scheduleddate, 'YYYY')) = TO_NUMBER (TO_CHAR (SYSDATE - 1, 'YYYY'))
    Seems to me that I'd be better off just doing:
    trunc(scheduleddate, 'YEAR') = trunc(SysDate, 'YEAR').
    Does that make sense?
    Thanks!
    Chad
    however , you might want to play around with it a bit to confirm you get the behavior you want in your context.  I've not had much reason to use trunc, and in testing a few things just now to reply to admin1, I got some results that surprised me.  Another little learning project for me now.
    But I stand behind the essence of my original reply.  The guy that wrote your original code was jumping through too many hoops (transform functions).

  • J2EE, JSTL and JSF questions

    I am trying to learn J2EE/JSTL/JSF and have quite a few general questions. Any help on any of these is appreciated.
    1) Is there a way, just by using J2EE/Java to "manipulate" an XML file. Not just parse and read it's data but actually add nodes to the file?
    2) I've been reading quite a bit on JSTL and JSF recently. Is JSF supposed to be an alternative to Struts and JSTL an alternative to scriptlet coding?
    3) I am also working on creating a message board but throwing around a couple of ways to implement it. Either (a) using a database to store posts and a JSP interface or (b) using an XML document to store postings. Which of these two seem best or is there a better option?
    4) Is there an easy way to call Php from a Java program? I need to invoke a php program when a user clicks on a link on a JSP page I have.

    1) The SDK provides JAXP (Java API for XML Processing) in javax.xml package.
    2) I wouldn't call it 'alternative'.
    3) Your choice. I'd to use a RDBMS. Less overhead, better suited, (much) more functions and better performance.
    4) If that program is available on the web, then just invoke a HTTP request. If not, I'd rather to rewrite it to Java.

  • Another Unlimited Data Upgrade Question

    (Yes, it's another one of those questions.  I'm sorry, but searching - on here, or on Google - only left me with conflicting information.)
    Here's my question:
    A friend of mine is interested in selling me his Galaxy Nexus phone.  Would I be able to keep my single-line, grandfathered, unlimited data plan if I buy his phone and switch to it, or is that only possible if I were to buy the phone new, directly from Verizon?
    Here's my story:
    I have an HTC Thunderbolt that I purchased when it launched.  A few months after buying it, it turned into the HTC Bad Dream, and now it's the HTC Nightmare.  Random heat issues, battery draining, random reboots... It's the same song and dance we've heard before.  These are design issues with the phone; not something a replacement or a repair would fix.
    The real annoyance, though, is the mobile hotspot.  I pay $30/month to use the hotspot legitimately, unlike the users who root their phones to use it without paying for the option, but ever since Verizon started blocking the third-party wireless tethering apps, I've had to choose between using the stock mobile hotspot app and unleashing the above-mentioned Phonemageddon, or simply going without.  I could drop the option from my plan, but seeing as the unlimited data plan no longer exists, I wouldn't be able to get it back without switching to a tiered or shared plan.
    Switching to a more stable phone would alleviate my issues, hopefully, but the difference between Verizon's retail prices and other retailers is hundreds of dollars.  Giving up my unlimited plan, however, wouldn't make the venture worth it.  A definite answer to the question of buying used - either from a Verizon representative, or a customer who's been in the same scenario before - would be very helpful.
    Thank you very much.

    Hi,
    If you provide your own equipment (your friend's Nexus or from ebay etc) then YES you can keep unlimited data. Another wayto keep unlimited would be to pay full retail for a new phone. But I'm sure your friend will give you a better deal than that
    Hope that helps!

  • Simple java date related question

    Hi Friends,
    I have written this custom date class that compares two dates. The user can enter any number of days,and it should calculate the next date,is that possible???
    public class Date implements Comparable {
         private int month, day, year;
         public Date(int m, int d, int y) {
              month = m;
              day = d;
              year = y;
         public int compareTo(Object o) {
              Date a = this;
              Date b = (Date) o;
              if (a.year < b.year) return -1;
              if (a.year > b.year) return 1;
              if (a.month < b.month) return -1;
              if (a.month > b.month) return 1;
              if (a.day < b.day) return -1;
              if (a.day > b.day) return 1;
              return 0;
         public String toString() {
              return month + "/" + day + "/" + year;
         public static void main(String[] args) {
              Date d1 = new Date(21, 03, 2007);
              int days = Integer.parseInt(args[0]);
              System.out.println("New date is:"); // Need to print new date
    Expected output:
    java Date 30
    New date is: 04/20/2007If this is not possible with this class,how can we do this, any ideas.
    Your help would be appreciated.
    Thanks

    Hi,
    Try this code out:
    import java.text.DateFormat;
    import java.util.*;
    import javax.swing.JOptionPane;
    public class SimpleDate {
         private int month, day, year;
         public SimpleDate() {
              Date date = new Date();
             String myString = DateFormat.getDateInstance().format(date);
             StringTokenizer tokens = new StringTokenizer(myString, "/");
             day = Integer.parseInt(tokens.nextToken());
             month = Integer.parseInt(tokens.nextToken());
             year = Integer.parseInt(tokens.nextToken());
         public SimpleDate(String stdate) {
              try {
                   StringTokenizer tokens = new StringTokenizer(stdate, "/");
                   day = Integer.parseInt(tokens.nextToken());
                   month = Integer.parseInt(tokens.nextToken());
                   year = Integer.parseInt(tokens.nextToken());
              catch(Exception e) {
                   Date date = new Date();
                  String myString = DateFormat.getDateInstance().format(date);
                  StringTokenizer tokens = new StringTokenizer(myString, "/");
                  day = Integer.parseInt(tokens.nextToken());
                  month = Integer.parseInt(tokens.nextToken());
                  year = Integer.parseInt(tokens.nextToken());
                   JOptionPane.showMessageDialog(null, "Invalid String,\nDate set to current", "Invalid String", JOptionPane.ERROR_MESSAGE);
         public SimpleDate(int d, int m, int y) {
              month = m;
              day = d;
              year = y;
         public int compareTo(Object o) {
              SimpleDate a = this;
              SimpleDate b = (SimpleDate) o;
              if (a.year < b.year) return -1;
              if (a.year > b.year) return 1;
              if (a.month < b.month) return -1;
              if (a.month > b.month) return 1;
              if (a.day < b.day) return -1;
              if (a.day > b.day) return 1;
              return 0;
         private int getNumOfDaysInMonth() {
              boolean leap = false;
              int days = 30;
              if (year % 4 == 0) leap = true;
              if ((month == 1) | (month == 3) | (month == 5) | (month == 7) |
                        (month == 8) | (month == 10) | (month == 12)) {
                   days = 31;
              if ((month == 4) | (month == 6) | (month == 9) | (month == 11)) {
                   days = 30;
              if (month == 2) {
                   if (leap) {
                        days = 29;
                   else days = 28;
              return days;
         public void addDays(int nums) {
              while (nums > getNumOfDaysInMonth()) {
                   nums = nums - getNumOfDaysInMonth();
                   addMonths(1);
              day = day + nums;
              while (day > getNumOfDaysInMonth()) {
                   day = day - getNumOfDaysInMonth();
                   addMonths(1);
         public void addMonths(int nums) {
              while (nums > 12) {
                   nums = nums - 12;
                   addYears(1);
              month = month + nums;
              while (month > 12) {
                   month = month - 12;
                   addYears(1);
         public void addYears(int nums) {
              year = year + 1;
         public int getDay() {
              return day;
         public int getMonth() {
              return month;
         public int getYear() {
              return year;
         public String toString() {
              return day + "/" + month + "/" + year;
    }I have swapped the day and month around from mm/dd/yyyy to dd/mm/yyyy
    but otherwise its still the same basic code

  • [CS5.5/6] - XML / Data Merge questions & Best practice.

    Fellow Countrymen (and women),
    I work as a graphic designer for a large outlet chain retailer which is constantly growing our base of centers.  This growth has brought a workload that used to be manageable with but two people to a never ending sprint with five.  Much of what we do is print, which is not my forte, but is also generally a disorganized, ad-hoc affair into which I am wading to try to help reduce overall strain.
    Upon picking up InDesign I noted the power of the simple Data Merge function and have added it to our repetoire in mass merging data sources.  There are some critical failures I see in this as a tool going forward for our purposes, however:
    1) Data Merge cannot handle information stored and categorized in a singular column well.  As an example we have centers in many cities, and each center has its own list of specific stores.  Data merge cannot handle a single column, or even multiple column list of these stores very easily and has forced us into some manual operations to concatenate the data into one cell and then, using delimiter characters, find and replace hard returns to seperate them.
    2) Data Merge offers no method of alternate alignment of data, or selection by ranges.  That is to say:  I cannot tell Data merge to start at Cell1 in one column, and in another column select say... Cell 42 as the starting point.
    3) Data merge only accepts data organized in a very specific, and generally inflexible pattern.
    These are just a few limitations.
    ON TO MY ACTUAL DILEMMA aka Convert to XML or not?
    Recently my coworker has suggested we move toward using XML as a repository / delivery system that helps us quickly get data from our SQL database into a usable form in InDesign. 
    I've watched some tutorials on Lynda.com and havent yet seen a clear answer to a very simple question:
    "Can XML help to 'merge' large, dynamic, data sets like a list of 200 stores per center over 40 centers based off of a single template file?"
    What I've seen is that I would need to manually duplicate pages, linking the correct XML entry as I go rather than the program generating a set of merged pages like that from Data Merge with very little effort on my part.  Perhaps setting up a master page would allow for easy drag and drop fields for my XML data?
    I'm not an idiot, I'm simply green with this -- and it's kind of scary because I genuinely want us to proceed forward with the most flexible, reliable, trainable and sustainable solution.  A tall order, I know.  Correct me if I'm wrong, but XML is that beast, no?
    Formatting the XML
    Currently I'm afraid our XML feed for our centers isnt formatted correctly with the current format looking as such:
    <BRANDS>
         <BRAND>
              • BrandID = xxxx
              [Brand Name]
              [Description]
              [WebMoniker]
              <CATEGORIES>
                   <CATEGORY>
                        • xmlns = URL
                        • WebMoniker = category_type
              <STORES>
                   <STORE>
                        • StoreID = ID#
                        • CenterID = ID#
    I dont think this is currently usable because if I wanted to create a list of stores from a particular center, that information is stored as an attribute of the <Store> tag, buried deep within the data, making it impossible to 'drag-n-drop'. 
    Not to mention much of the important data is held in attributes rather than text fields which are children of the tag.
    Im thinking of proposing the following organizational layout:
    <CENTERS>
         <CENTER>
         [Center_name]
         [Center_location]
              <CATEGORIES>
                   <CATEGORY>
                        [Category_Type]
                        <BRANDS>
                             <BRAND>
                                  [Brand_name]
    My thought is that if I have the <CENTER> tag then I can simply drag that into a frame and it will auto populate all of the brands by Category (as organized in the XML) for that center into the frame.
    Why is this important?
    This is used on multiple documents in different layout styles, and since our store list is ever changes as leases end or begin, over 40 centers this becomes a big hairy monster.  We want this to be as automated as possible, but I'd settle for a significant amount of dragging and dropping as long as it is simple and straightforward.  I have a high tollerance for druding through code and creating work arounds but my co-workers do not.  This needs to be a system that is repeatable and understandable and needs to be able to function whether I'm here or not -- Mainly because I would like to step away from the responsibility of setting it up every time
    I'd love to hear your raw, unadulterated thoughts on the subject of Data merge and XML usage to accomplish these sorts of tasks.  What are your best practices and how would you / do you accomplish these operations?
    Regards-
    Robert

    From what I've gleaned through watching Lynda tutorials on the subject is that what I'm hoping to do is indeed possible.
    Peter, I dont disagree with you that there is a steep learning curve for me as the instigator / designer of this method for our team, but in terms of my teammates and end-users that will be softened considerably.  Even so I'm used to steep learning curves and the associated frustrations -- but I cope well with new learning and am self taught in many tools and programs.
    Flow based XML structures:
    It seems as though as long as the initial page is set up correctly using imported XML, individual data records that cascade in a logical fashion can be flowed automatically into new pages.  Basically what you do is to create an XML based layout with the dynamic portion you wish to flow in a single frame, apply paragraph styles to the different tags appropriately and then after deleting unused records, reimport the XML with some specific boxes checked (depending on how you wish to proceed).
    From there simply dragging the data root into the frame will cause overset text as it imports all the XML information into the frame.  Assuming that everything is cascaded correctly using auto-flow will cause new pages to be automatically generated with the tags correctly placed in a similar fashion to datamerge -- but far more powerful and flexible. 
    The issue then again comes down to data organization in the XML file.  In order to use this method the data must be organized in the same order in which it will be displayed.  For example if I had a Lastname field, and a Firstname field in that order, I could not call the Firstname first without faulting the document using the flow method.  I could, however, still drag and drop content from each tag into the frame and it would populate correctly regardless of the order of appearance in the XML.
    Honestly either method would be fantastic for our current set of projects, however the flow method may be particularly useful in jobs that would require more than 40 spreads or simple layouts with huge amounts of data to be merged.

  • Current year data compare with pervious year

    Hi Experts,
    I have created report1 with display the default date data. And we have Date between filter, based on the filter the reports data is changeing.
    My Question is we have another report2 below the report1 but report2 should display exact date of last year.
    i.e. if default date is 29/03/2010 and 30/03/2010 for report1 and
    the report2 should be display the data for exact 29/03/2009 and 30/03/2009 and if date filter may change the report2 also change.
    Note : Both reports are created from same table.
    Thanks,
    Balaa...

    Hi Balaa,
    you can creat a filter like this:
    TIMESTAMPADD(SQL_TSI_YEAR,-1,date)
    This retuns the date of the last year.
    I hope it helps.
    Regards,
    Gianluca

  • Oracle.jbo.domain.Number / Date comparable ?

    Hello,
    I'd like to know whether there was a plan to make the oracle.jbo.domain.Number and oracle.jbo.domain.Date classes implement the Comparable interface?
    That would save some unnecessary wrapping code...
    Thanks in advance,
    Remi

    I just want to push this Idea, since it is hard to understand, why such a simple interface is not implemented for such a basic class. It would make a lot of things much easier.

Maybe you are looking for

  • URGENT:problem with memory using swing component

    We use Java SDK 1.4.0-b92 on a Sun Blade Machine with Solaris 8 Operating System. We developed a software with a GUI (JFame, JInternalFrame) which have to be refreshed in precise moments and any time we do it there is a big loss of memory(not the Jav

  • Can muliple DVD scene paths be created in a template

    Hello all, I am trying to edit some of the DVD menu templates. Is there a way to have a Scene button, then have like an Extras button and have them point to different second level menus? I know the typical Scene button will create or enable additiona

  • Deleted emails still on my server - where do they go?

    Sorry if this is an old topic; I read a buttload of threads about deleting and still have barely scratched the surface but am too impatient to read any more, and still haven't found my exact issue. When I manually delete an email (which moves it to m

  • Derivation rule in easy cost planning

    Hi everyone, I have the following problem. I have created one characteristic and I linked it at one template. In this template, I have 2 position, A and B, and I must insert a new position,C, linked at one of their. This new position must have the fo

  • Vbscript runtime error 429 activex component can't create object

    hi i am writing a VB Script where it runs a batch files but when the batch file is called from the script its giving error as  runtime error 429 activex component can't create object my script is as follows strcmd = "utility.bat" Set wshSystemEnv = w