How does autoComplete work with Options for commands? - java

I want the user to be able to auto complete the finishDate value with "MM/dd/yyyy HH"
But i cannot find it anywhere on how to set it up.
This is what the command looks like rn:
jda.getGuildById(guild.getId()).upsertCommand("lottery", "Creates a lottery in the current or selected channel.")
.addOption(OptionType.STRING, "reward", "The reward for the lottey winners", true)
.addOption(OptionType.STRING, "finishDate", "Use format MM/dd/yyyy HH", true, true);

Related

Issue with selecting date from calendar in Selenium

I'm trying to select current date from the calendar on this website "www.makemytrip.com".
Using these 2 lines of code:
driver.findElement(By.xpath("//label[#for='departure']")).click();
To open the calendar and to select date:
driver.findElement(By.cssSelector(".DayPicker-Day.DayPicker-Day--selected.DayPicker-Day--today")).click();
The first one is working fine as it opens up the calendar but cssSelector is not responding. I've tried various variations but still it remains unresponsive.
Try this xpath strategy:
//div[#class='DayPicker-Day DayPicker-Day--today']
Now, i write in python, so you may translate my code to Java, since most of it remains same.
time.sleep (Thread.sleep in Java) here is optional Ideally you should use WebdriverWait instead of Thread.sleep. But just to show you, I used it.
driver.get('https://www.makemytrip.com/')
time.sleep(3)
driver.find_element(By.XPATH, "//label[#for='departure']").click()
time.sleep(1)
dx = driver.find_element(By.XPATH, "//div[#class='DayPicker-Day DayPicker-Day--today']")
print(dx.text)
dx.click()
Here is the output:
17 is the date and the other value is currency.
17
₹ 9,418
Process finished with exit code 0

Formatting cells (to type Duration) with the Google Sheets API (v4)

I'm using the Google Sheets API (v4) to create/update spreadsheets programmatically and have run into the following issue:
I have seen via the JavaDoc that to set the cell to a NumberFormat of say, CURRENCY, I can set the NumberFormat type and pattern to:
"cell": {
"userEnteredFormat": {
"numberFormat": {
"type": "CURRENCY",
"pattern": "[$¥-411]#,##0.00" // <--- Added
}
}
},
"fields": "userEnteredFormat.numberFormat" // or "fields": "userEnteredFormat"
However, I do not see an option to set the NumberFormat type to DURATION. The acceptable enums I have found include: NUMBER_FORMAT_TYPE_UNSPECIFIED, TEXT, NUMBER, PERCENT, CURRENCY, DATE, TIME, DATE_TIME, SCIENTIFIC. Is there any way to set a cell format to a type Duration mimicking what you can do via UI?
This shows what is seen on the UI for setting a cell's format type
You need to obtain the format token of duration and use it as pattern in your request body.
To do that:
Highlight any cell and change its cell format to Duration
In the same cell, Navigate to Number -> More formats -> Custom number format.
Copy the existing format token. For duration it should be [h]:mm:ss.
Replace the value of pattern in your request body with [h]:mm:ss
Replace the value of type to DATE_TIME
Your request body should look like this:
"cell":{
"userEnteredFormat":{
"numberFormat":{
"pattern": "[h]:mm:ss",
"type": "DATE_TIME"
}
}
}
Before:
After:
Reference:
Date and time format tokens

Stringtemplate - How to set date format to locale format

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

Display tag show user's local time in browser Jsp

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.

Not able to input date using sendKeys in Selenium WebDriver

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.

Categories