on 2017 Feb 09 10:13 AM
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?
Request clarification before answering.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
22 | |
17 | |
4 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.