cancel
Showing results for 
Search instead for 
Did you mean: 

Backoffice: search by date

Former Member
0 Kudos
835

I've looked through quite some database documentation and mappings already and it seems there is no way to define a cross db DATE type. So dates seem to be saved as DATETIME/TIMESTAMP only.

We've got a requirement to only record and search (backoffice) by date and not time. This makes it ofc impossible to use an equal comparison since dates don't match if their time differs.

Any idea how to properly implement this using a date without time?

Accepted Solutions (0)

Answers (4)

Answers (4)

former_member625836
Active Contributor
0 Kudos

Hi Mohamed,

I've only one solution for now - you might write your own custom editor by extending com.hybris.cockpitng.editor.defaultdate.DefaultDateEditor and overriding two methods. Please try a code below - not tested, but should more or less do what expected:

 protected Date truncateRawValue(final C viewComponent, final Date rawValue)
     {
         final String format = viewComponent.getFormat();
         final SimpleDateFormat dateFormat = new SimpleDateFormat(format);
         final String formattedValue = dateFormat.format(rawValue);
         try
         {
             return dateFormat.parse(formattedValue);
         }
         catch (final ParseException e)
         {
             LOG.error(e.getLocalizedMessage(), e);
 
             return rawValue;
         }
     }
 
     @Override
     protected void setRawValue(final InputElement viewComponent, final Date rawValue)
     {
         final Date truncatedValue = truncateRawValue((C) viewComponent, rawValue);
         viewComponent.setRawValue(truncatedValue);
     }
 
     @Override
     protected Date getRawValue(final InputElement viewComponent)
     {
         final C box = (C) viewComponent;
         final Date truncatedValue = truncateRawValue((C) viewComponent, (Date) box.getRawValue());
         return truncatedValue;
     }

Best regards, Jacek

former_member625836
Active Contributor
0 Kudos

Hi Bernhard,

In Advanced search you might always change settings of editor setting dateFormat to short. Please take look at advanced search and default date editor documentations for details.

All best, Jacek

Former Member
0 Kudos

Hi Jacek,

Sure, did that, however this is only for rendering it seems. It still uses the current date and current time for filtering which obviously wont work.

Example: I type in 12.03.2016 and it will search for 12.03.2016 12:00:01

My guess is that a java Date is instantiated from the request and will be used for filtering which ofc always holds a time

Former Member
0 Kudos

Yeah, I'm currently storing it as DATE (mysql) however in the advanced search area things are initialized with the current date and time which obviously doesnt work when searching since all dates are stored with 00:00:00

former_member632755
Active Contributor
0 Kudos

Hi,

would it be possible to ignore the time by setting it to a default, fixed value. For example to the noon? I think that it should solve the issue.

I think that you can achieve that by using an interceptor for the interesting fields. Another option might be to alter the column definition used to store the fields but I'm not sure what will be the side effects of such declaration.

Cheers, Wojtek

former_member632755
Active Contributor
0 Kudos

Another option would be to change the search condition to a range embracing the whole day. But that option would require some additional work on the query construcion.