WatchFromDate().sendKeys("2018-07-03");
// public WebElement WatchFromDate()
{
return driver.findElement(fromDate);
}
By fromDate= By.id("from");
the steps to send the system date in selenium could obtain the date with a specific format and then send this variable. Something like that:
public void WatchFromDate(){
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd");
LocalDate localDate = LocalDate.now();
driver.findElement(fromDate).sendKeys(dtf.format(localDate));
}
The dtf variable defines the format for the date (i.e. 2018/07/13)
The localDate variable obtain the current date, but this date has too much precision.
The dtf.format(localDate) sentence adjust the current date obtained in the localDate, to the defined format in dtf variable.
Related
I'm building a custom function for BW6 that should parse ISO 8601 formatted string to a dateTime object.
So far I have built this function:
#XPathFunction(helpText = "Parse a ISO 8601 datetime string",
parameters = {
#XPathFunctionParameter(name = "isoDateTimeString", optional = false)
},
returnType = "dateTime")
public Date parseIsoDateTime(String isoDateTimeString) throws ParseException {
StringBuilder dateFormatBuilder = new StringBuilder();
dateFormatBuilder.append("yyyy-MM-dd'T'HH:mm:ss");
if (isoDateTimeString.contains(".")) {
dateFormatBuilder.append(".SSS");
}
DateFormat dateFormat = new SimpleDateFormat(dateFormatBuilder.toString());
return dateFormat.parse(isoDateTimeString);
}
When I run this function an exception is thrown by BW
09:02:42.412 ERROR [bwEngThread:In-Memory Process Worker-1] com.tibco.bw.core - TIBCO-BW-CORE-500050: The BW process [demo.parse-datetime.module.Process] instance faulted, JobId [bw0a100], ProcessInstanceId [bw0a100], ParentProcessInstanceId [-], Module [demo.parse-datetime.module:1.0.0.qualifier], Application [demo.parse-datetime:1.0].
<CausedBy> TIBCO-BW-CORE-500058: Activity [SetDateTimeValue] XML related error.
<CausedBy> com.tibco.pvm.dataexch.xml.util.exceptions.PmxException: PVM-XML-106017: Expression Evaluation Error: 'bxcom:parseIsoDateTime($dateTimeAsString)'
<CausedBy> java.lang.ClassCastException: java.util.Date cannot be cast to com.tibco.xml.data.primitive.XmlAtomicValue
So how can I return an XML dateTime object from a custom xslt function in BW6.
You need to create a Plug-in Project to allow Custom XPath Function. (You will need the ActiveMatrix BusinessWorks™ Plug-in Development Kit)
Create Custom XPath Functions
If you want to use them Design time, you'll need to export the Plugin Project and include the jar as a dependency.
Using Custom XPath Function at Design Time and Run Time
Now that NHibernate 5 is out, I was wondering what's the recommended approach to load dates as local dates when they're persisted as datetime2 in a SQL Server 2016 database. Until now, dates were interpreted as local (so, the properties ended up with the correct values), but now, the behavior has changed and I'm unable to use the LocalDateTime.
Unfortunately, my donmain's behavior relies in getting those dates automatically loaded as local dates...
Any pointers on how to solve this?
Thanks,
Luis
Since I didn't found a way to disable this behavior, I've ended up creating a new type that will simply adjust the format of the data (considering always that it was saved in local format):
public class LocalDateTimeTypeNoThrow : LocalDateTimeType {
public LocalDateTimeTypeNoThrow() {
}
public LocalDateTimeTypeNoThrow(DateTimeSqlType sqlType) : base(sqlType) {
}
public override string Name => "LocalDateTimeNoThrow";
public override void Set(DbCommand st, object value, int index, ISessionImplementor session) {
var dateValue = (DateTime) value;
//removed throwing from here
st.Parameters[index].Value = AdjustDateTime(dateValue);
}
}
If there's a better way, please let me know.
Luis
I'm using SpringFox (Swagger) to document my REST APIs. One of the nice features in Swagger is to show example model and the data type format.
Now, I configured my APIs to produce and consume dates in milliseconds but when I'm looking at the sample JSON model the date format is following: "2015-09-21T00:51:32.617Z". See screenshot below. Is it possible to tell SpringFox (Swagger) how to format the date properly?
You could try:
Docket docket = new Docket(DocumentationType.SWAGGER_2)
.apiInfo(getApiInfo())
.directModelSubstitute(YourDateTimeClass.class, Integer.class);
Basically you are telling Swagger to replace the date class with an Integer which could represent the milliseconds.
This is related to the underlying Jackson serialiser. You have to set the correct date format for it otherwise by default it's using timestamps.
Here is an example configuration
#Configuration
public class WebConfiguration extends WebMvcConfigurerAdapter {
#Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
for (HttpMessageConverter<?> converter : converters) {
if (converter instanceof MappingJackson2HttpMessageConverter) {
MappingJackson2HttpMessageConverter jsonMessageConverter = (MappingJackson2HttpMessageConverter) converter;
ObjectMapper objectMapper = jsonMessageConverter.getObjectMapper();
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
break;
}
}
}
}
This way it will use an ISO-8601 date-time format. Here is another blog post that explains how to set your own preferred date format: http://yysource.com/2016/06/change-default-date-for-jackson-in-spring-boot-application/
I got a similar problem as yours, and I resolved it by adding the following config in my Spring Boot's application.properties file:
spring.jackson.date-format=com.fasterxml.jackson.databind.util.ISO8601DateFormat
I created a calendar event with all day selected (10/24/2013) . Then i tried to pull the e.EventStart and e.EventEnd. My expected result was EventStart =10/24/2013 12.00.00 am and
EventEnd= 10/25/2013 12.00.00 am. But what am getting is EventStart =10/24/2013 12.00.00 am and EventEnd= 10/24/2013 12.00.00 am.
The same works fine when I try with e.EventStartUtc and e.EventEndUtc. But I dont want the utc format as I am trying to pull out the ektron time for the users.
If you use the Framework API, the WebEventData class has a property called IsAllDay. You could use this to trigger the display change. For example, you might not want to display start/end times at all if it's an All Day event and just show the date.
If you do need to have particular start/end times for all day events, you can easily extend the Ektron WebEventData object with extension methods.
public static class WebEventExtensions
{
public static DateTime GetDisplayStartDate(this WebEventData webEvent)
{
if (!webEvent.IsAllDay)
return webEvent.EventStart;
return new DateTime(webEvent.EventStart.Year, webEvent.EventStart.Month, webEvent.EventStart.Day);
}
public static DateTime GetDisplayEndDate(this WebEventData webEvent)
{
if (!webEvent.IsAllDay)
return webEvent.EventEnd;
return new DateTime(webEvent.EventEnd.Year, webEvent.EventEnd.Month, webEvent.EventEnd.Day, 23, 59, 59);
}
}
Then those methods will appear on the object.
var eventManager = new WebEventManager();
WebEventData webEvent = eventManager.GetItem(730);
if (webEvent.IsAllDay)
{
// do all-day stuff...
}
var start = webEvent.GetDisplayStartDate();
var end = webEvent.GetDisplayEndDate();
I have a problem in my DateTextField in Wicket. I want to set it by default to nothing, null, so date can be choosed after someone picks it. But by default it sets value to current day. How to "clear" it so nothing is in this datetextfield? Here is my Datefield code:
DateField date_insert_date_from = new DateField("insert_date_from", new PropertyModel(this, "date")) {
/**
* Format date to yyyy-MM-dd pattern.
*/
#Override
protected DateTextField newDateTextField(String id, PropertyModel dateFieldModel) {
return DateTextField.forDatePattern(id, dateFieldModel, "yyyy-MM-dd");
}
};
form.add(date_insert_date_from);
As #kan says, you need to make sure the modelobject for the datefield is null.
Simple way to do so is:
DateField date_insert_date_from = new DateField("insert_date_from", new Model<Date>(null));
Now, if anyone enters a date into the datefield and submits the form, the Model will contain the chosen date and you can retrieve it by writing:
Date chosenDate = date_insert_date_from.getModelObject();
If you want to use a propertymodel, as you do, you need to make sure the object on which the propertymodel acts (this in your case) has a field capable of holding a date and getter/setter methods for that field.
In your case, this.date should be initialized with null and this should have
public Date getDate()
and
public void setDate(Date date)
methods.