RE: How to compare a date?

"Nicolas Lafaury" <[email protected]>
Newsgroups gmane.comp.cms.jahia.template
Message-ID <[email protected]>
You have two possibility
 
 
    public int displayContentFromDates(String startDate, String endDate){
      String objectDate = startDate;
      String objectStartDateStr = startDate;
      String objectEndDateStr = endDate;
      long objectStartDate = -1;
      long objectEndDate = -1;
      try {
          objectStartDate = Long.parseLong(objectStartDateStr);
      } catch (NumberFormatException nfe) {
          //System.out.println("box_new.jsp> " + nfe);
      }
      try {
          objectEndDate = Long.parseLong(objectEndDateStr);
      } catch (NumberFormatException nfe) {
          //System.out.println("box_new.jsp> " + nfe);
      }
      long now = (new Date()).getTime();
      int displayObject = -1;
      if (objectStartDate == -1){
          if (objectEndDate == -1){
              displayObject = 0;
          } else if (now <= objectEndDate) {
              displayObject = 0;
          }
      } else if (objectStartDate <= now){
          if (objectEndDate == -1){
              displayObject = 0;
          } else if (now <= objectEndDate) {
              displayObject = 0;
          }
      } else if (objectStartDate > now){
              displayObject = 1;//sera à afficher plus tard
      }
      return displayObject;
    }
 
This the first one then you print just the containers where the function return 0
 
The second method, and the best way I think is to use containerFilter
 
<%
  if (!jData.gui().isEditMode()) {
    Vector moncFilterBeans=new Vector();
    Calendar todayCalendar=Calendar.getInstance();
    ContainerFilterBean monContainerFilter = new ContainerFilterBean("startDate ",jData.params().getEntryLoadRequest());
    monContainerFilter.addClause(ContainerFilterBean.COMP_SMALLER_OR_EQUAL,""+todayCalendar.getTimeInMillis());
    moncFilterBeans.add(monContainerFilter);
    monContainerFilter=null;
    ContainerFilterBean monContainerFilterEnd = new ContainerFilterBean("endDate ",jData.params().getEntryLoadRequest());
    monContainerFilterEnd.addClause(ContainerFilterBean.COMP_BIGGER_OR_EQUAL,""+todayCalendar.getTimeInMillis());
    moncFilterBeans.add(monContainerFilterEnd);
    monContainerFilterEnd=null;
    ContainerFilters containerFilters = new ContainerFilters("agendaContainerList",jParams,moncFilterBeans);
    request.setAttribute("agendaContainerList_filter_handler",containerFilters);
  }
%>
 
 
Hope this can help you
 
Nicolas
  _____  

De : [email protected] [mailto:[email protected]] 
Envoyé : vendredi 28 octobre 2005 15:49
À : [email protected]
Objet : How to compare a date?
 
I have a container with a startDate and an endDate field.
I want to show the container if curent date is in between those dates.
 
How can I compare with current date? (System.currentTimeMillis())
 
I can find some java code doing by using java code (scriplet) (box_news.inc).
 
But how can we do this by using taglibs (jahia,jstl,struts)?
...
 <content:dateField ..../>
...
 <c:if test="${ ????? }">
  // Show container fields...
</c:if>
...
Regards
/Lars Hagrot
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.