I'm processing Excel files with ExcelExplorer based on Stringtemplate4 (ST).
The files contain several columns with dates.
By default, the dates are rendered following the "MM/dd/yy" date format.
Is there a way to render the dates as "dd/MM/yyyy"?
I've tried it in several ways:
I've tried defining it via the command line, without success.
Defining LC_ALL=fr_FR doesn't work.
Defining LC_TIME="dd/MM/yyyy" doesn't work.
See Setting java locale settings
Calling java with the following command line options doesn't work.
java -Duser.language=fr -Duser.country=FR -Duser.variant=UTF-8 ...
I've tried the following templates without success:
renderRow(row) ::= <<
<row.MyDate; format="dd/MM/yyyy">
>>
Although attribute MyDate is defined as a Date type, the above doesn't work. I don't want to define MyDate as a Date type in Java as proposed in Format date in String Template email
NB: After checking, I found out that ExcelExporter/ST defines attribute MyDate as a Date type!
The following template doesn't work either :
renderRow(row; format="dd/MM/yyyy") ::= <<
<row.MyDate>
>>
You need to add a renderer to your STGroup for each class you want to format:
dir = STGroupDir(templateDirectory, '$', '$')
dir.registerRenderer(Number.class, NumberRenderer())
dir.registerRenderer(Date.class, DateRenderer())
Now, in my templates, I can use
<row.MyDate; format="dd/MM/yyyy"> format string is used with java.text.SimpleDateFormat
or
<row.MyNumber; format="%,d"> format string is used with java.util.Formatter
If you need a custom formatter, take a look at the DateRenderer, it would be pretty straightforward to create your own.
Here's the documentation:
https://github.com/antlr/stringtemplate4/blob/master/doc/renderers.md
Related
I'm using Hibernate Validation (JSR 303) and I'm trying to tame the Eclipse formatter to have nested annotations on seperate lines. Example:
#DefinedParametersMatchesResultPresence.List( {
#DefinedParametersMatchesResultPresence( measurement = Measurement.penetrationLength ),
#DefinedParametersMatchesResultPresence( measurement = Measurement.coneResistance ), #DefinedParametersMatchesResultPresence( measurement = Measurement.depth ),
#DefinedParametersMatchesResultPresence( measurement = Measurement.electricalConductivity ),
} )
However.. I can't get the annotations in the DefinedParametersMatchesResultPresence.List on a new line when running format. Additionally, the formatter does not comply to my max line length and wrap to a new line.
I'm using:
Version: Neon.2 Release (4.6.2)
Build id: 20161208-0600
Although the formatting concerns annotations, the array formatting also applies. After setting array formatting correctly it works as expected.
Next: its also possible to use the #Repeatable annotation when using your own annotations which lead to a nicer
I am using Thymeleaf #dates.format() function for format date in view layer. I create one internatinalization properties file for pic the date format. i am using #dates.format(date, (#{app.dateformat})) function like this. but Thymeleaf throw an parse exception. Because thymeleaf now resolve the app.dateformat. How i use date format internationalization way in thymeleaf. Following is an exception:
org.springframework.expression.spel.SpelParseException: EL1043E:(pos 37): Unexpected token. Expected 'identifier' but was 'lcurly({)'
You should use this syntax instead :
${#dates.format(date, #messages.msg('app.dateformat'))}
#messages : utility methods for obtaining externalized messages inside variables expressions, in the same way as they would be obtained using #{...} syntax.
Source
I made a Oracle Package like below.
And I will pass parameter String like '2014-11-05'.
--SEARCH 2014 11 04
FUNCTION SEARCHMYPAGE(v_created_after IN DATE, v_created_before IN DATE)
return CURSORTYPE is rtn_cursor CURSORTYPE;
BEGIN
OPEN
rtn_cursor FOR
select
news_id
from
(
select
news_id,
news_title, news_desc,
created, news_cd
from
news
)
where
1=1
AND (created BETWEEN decode(v_created_after, '', to_date('2000-01-01', 'YYYY-MM-DD'), to_date(v_created_after, 'YYYY-MM-DD'))
AND (decode(v_created_before, '', sysdate, to_date(v_created_before, 'YYYY-MM-DD')) + 0.999999));
return rtn_cursor ;
END SEARCHMYPAGE;
I confirmed my parameter in Eclipse console Message, since I am working on Eclipse IDE.
I got contents, which are made in 2014-10-29 ~ 2014-10-31.
when I pass '2014-11-01' as created_after, It returns 0 records.(But I expected all contents, since every contents are made between 10-29 and 10-31)
Would you find anything wrong with my Function?
Thanks :D
create function search_my_page(p_created_after in date, p_created_before in date)
return cursortype
is rtn_cursor cursortype;
begin
open rtn_cursor for
select news_id
from news
where created between
nvl(v_created_after, date '1234-01-01')
and
nvl(v_created_before, sysdate) + interval '1' day - interval '1' second;
return rtn_cursor;
end search_my_page;
/
Changes:
Re-wrote predicates - there was a misplaced parentheses changing the meaning.
Replaced to_date with date literals and variables. Since you're already using ANSI date format, might as well use literals. And date variables do not need to be cast to dates.
Replace DECODE with simpler NVL.
Removed extra parentheses.
Renamed v_ to p_. It's typical to use p_ to mean "parameter" and v for "(local) variable".
Removed extra inline view. Normally inline views are underused, in this case it doesn't seem to help much.
Removed unnecessary 1=1.
Replaced 0.99999 with date intervals, to make the math clearer.
Changed to lower case (this ain't COBOL), added underscores to function name.
Changed 2000-01-01 to 1234-01-01. If you use a magic value it should look unusual - don't try to hide it.
I am using display tag for table details i want to change date & time to user's local browser setting, Data in DB is UMT. IF user is from india then it will add +5:30 etc. How can i do this. I am stuck in this. Please help me.
Have you tried like this ??
Locale cLoc=request.getLocale();
Calendar cCal=Calendar.getInstance(cLoc);
TimeZone tz=cCal.getTimeZone();
//......
A bit late to the party, but still answer here in case anyone else needs it.
Display.tag uses MessageFormatColumnDecorator internally to apply MessageFormat formatter to all columns that have "format" parameter set.
So, your options are:
Create your own custom MessageFormatColumnDecorator. Unfortunatelly it is inined in the ColumnTag code and cannot be very easily replaced (decorators are chained), so you will have to compile your own copy of Display.Tag jar, with your custom decorator in it.
In your custom decorator use the following sample code to change MessageFormat's timezone:
TimeZone tz = //get your timezone here
Object [] formats = format.getFormats(); //'format' is MessageFormat instance
for (int i = 0; i < formats.length; i++) {
if (formats[i] instanceof SimpleDateFormat) {
((SimpleDateFormat)formats[i]).setTimeZone(tz);
}
}
Second option is to use the <fmt:formatDate> within Display.tag column tags to format the output.
Sample Code:
<display:table name="dateList" id="object">
<display:column title="Date">
<fmt:formatDate value="${object.date}" type="both" dateStyle="long" timeStyle="long"/>
</display:column>
</display:table>
You can set default request locale for <fmt:formatDate> or wrap them in <fmt:timeZone> tag to set a timezone for them to use.
The date field is like a calendar and I'm not able to input the date using sendKeys of Selenium WebDriver.
But "type" in the date field was working fine before with Selenium RC.
I tried using "clear()" before "sendKeys()" but this gave the error:
Caught Exception: Element is read-only and so may not be used for actions
Command duration or timeout: 10.11 seconds
sendKeys() is working fine for other text input fields.
I tried isDisplayed() to check for the element and it comes as true. Even in the browser, when running the test, the cursor goes to the date fields but doesnt type any text into them.
Use Following Code for this...
((JavascriptExecutor)driver).executeScript ("document.getElementById('dateofbirth').removeAttribute('readonly',0);");
WebElement BirthDate= driver.findElement(By.id("dateofbirth"));
BirthDate.clear();
BirthDate.sendKeys("20-Aug-1985"); //Enter this date details with valid date format
I also faced the same issue.This is what the solution I found.This worked fine for me.
Just remove the read only attribute of the input field and then do just as other input fields.
((JavascriptExecutor) driver).executeScript("document.getElementsByName('date'[0].removeAttribute('readonly');");
WebElement dateFld = driver.findElement(By.id("date_completed"));
dateFld.clear();
dateFld.sendKeys("date Completed");
For future readers of this thread, the solution posted by #Flaburgan for issue
https://github.com/mozilla/geckodriver/issues/1070
was found to work with Firefox 63 on Win7-64
"For the record, it looks like send_keys with a correctly formatted ISO date (yyyy-mm-dd) works. So for your example, can you please try to call send_keys with (like) 2012-11-02?"
If You are using a jQuery date picker object, the field should be read-only and date have to be selected from calendar object. In that case You can use 'Select' class methods of Selenium Web Driver to choose a date.
Select date = new Select(driver.findElement(By.linkText("the date want to select")));
date.click();
I have done this and works great. Take care of the format. By this you can even get the value from the control.
var dob = element(by.id('dateOfBirth'))
dob.sendKeys('20-08-1985');
expect(element(by.id('dateOfBirth')).getAttribute('value')).toBe('2015-20-08');
Hope it helps.