Watson Conversation System Entity sys-date is giving different results if I change '/' with '-'
As per documentation:
Note: - For English locale only, the default system behavior for date
input is MM/DD/YYYY. This will change to DD/MM/YYYY only if the first
two numbers are greater than 12. The value stored will still be in the
format "yyyy-MM-dd".
However when i am testing with '-' its taking DD/MM/YYYY
12/01/2017 => 2017-12-01 (Correct)
12-01-2017 => 2017-01-12 (incorrect)
Ideally Watson should interpret both as same dates as this '/', '-' will confuse the users. Is there anyway to make it interpret as same dates.
Date Sample Screenshot
AFAIK it is not possible to change the way the dates are interpreted in the shared version of IBM Watson Conversation Service (WCS). The date which you labeled as incorrect is actually correct when looking at ISO date formats.
What you could do for your customization issue is to assess the metadata provided by WCS. You have access to the location information about where in a string the data was detected and also what exactly the user typed. You could use that to interpret date values in the desired form.
Related
I have a school practical where users enter their date of birth in a TEdit on a TForm. The user will most likely enter the date according to their custom date settings, but I want to be able to convert any or at least most date formats to the one I have stored in a .mdb Access database. How do I get an accurate and valid date from the GUI as user input?
I know of the decodedate(Date, year, month, day) procedure, but what if the user enters the date differently than system settings or as is displayed in the TDBGrid connected to the .mdb database via an ADOConnection and ADOTable? Then the procedure will crash.
Be a help to the user instead of a pain:
Is "contains" meant literally, so the user can actually also enter dates with leading and/or trailing spaces? Such things occur, especially when copying texts from elsewhere. Trimming off such whitespaces is easy, so allow this. See trim()
Avoid generic error messages but instead make them as precise as possible:
Wrong length? Tell what you expect and what you got instead, i.e.: "Expected length: 10, but got 8 instead."
No delimiter at expected position? Tell so, i.e.: "Expected delimiter "/" as 5th letter, but got "3" instead."
Illegal month? Tell so, i.e: "Expected "1" or "01" thru "12" as month, but got "23" instead."
Try to collect multiple error messages at once, so the user can see all of his mistakes and fix them in one go, instead of being penalized again and again with just one message per take.
Detect patterns and make them restrictive:
Pos #1 is in ['0'.. '2'] and pos #2 thru #4 is in ['0'.. '9']? Looks like a year from which we can proceed:
Pos #5 is in ['/', '-', '.']?
Pos #6 is '0' and pos #7 is in ['1'.. '9']? Or pos #6 is '1' and pos #7 is in ['0'.. '2']?
...and so on. That way you can much better recognize which format has been chosen and you can give much more precise error messages. It will also lead to ambiguous input, such as 4/10/2016 from which you don't know if 4 is a day or a month.
Check against illegal dates: which months cannot have a 31th day? For February 29th see IsLeapYear()
Display the date according to what you recognized - this helps you and your user to make sure the recognition was correct. Ideally you have your three Integers of year, month and date and then convert them to text again, along with delimiters - the outcome should be in general the input you had to deal with.
Regular expressions are great in recognizing patterns and then accessing the found parts. However, it's a topic on its own and should only be used when known on its own. A regex for the format I used in this example would be /([0-2][0-9]{3})[/.-](0?[1-9]|1[0-2])[/.-](0?[1-9]|[12][0-9]|3[01])/ where you can easily access $1 as year, $2 as one or two digit month and $3 as one or two digit day. You "only" have to check against illegal dates.
As #AndreasReijbrand pointed out, a TDateTimePicker would be the correct method to receive a date as user input on a GUI. The TDateTimePicker does all the validation work for you. After much debate, we were eventually allowed to use it. I post this new answer with some important insights to the TDateTimePicker component:
The TDateTimePicker automatically changes to the local set date format of the pc. So validation of that is unnecessary.
Conversion of date display format (yyyy/mm/dd or yyyy-mm-dd) from the .mdb Access database to the TDateTimePicker and vice versa is unnecessary. This is also done automatically. (Starting to see why there was so much criticism for the original lack of use of this component.)
The DateTimePicker does not allow negative values or non-sensical values such as (0030/09/08 or 2003/89/89).
I have a date which is being fed into my script in the following format:
dateTime = "Fri Oct 18 10:08:02 UTC 2019"
Is there a way to reformat this so that I can quickly call each element as I like without explicitly splitting out using string.sub (for example)?
E.g. So that I can:
Subtract one date from another to find out age (using current time and birth/established date)
Add hours dependant on the timezone (given that I have a timezone in the format "+3")
Find if the time was between a range (e.g. the request was sent between 9am and 5pm GMT)
Lua does not have a built-in date or time type like other languages.
Lua 5.3 Reference Manual 2.1 Values and Types
There are eight basic types in Lua: nil, boolean, number, string,
function, userdata, thread, and table.
Lua 5.3 Reference Manual 6 Standard Libraries
Either implement them yourself or find existing modules that suit your needs.
A simple way would be to parse your date time string using captures
Checkout http://lua-users.org/wiki/DateAndTime for suggestions.
Suppose my system date is 2014-02-10 & I have published my app on Internet Information System. Now Using DateTime.Now.ToShortDateString method I can get date like 2014-02-10, but how can get pattern/style/structure (e.g yyyy-MM-dd) for date? It should be irrespective of current culture.
IF I change date to 10-Feb-2014, then I should get dd-MMM-yyyy.
What's the solution? Thanks in adv..
Ah, I see. I thought you were saying that you wanted to format a date value but it seems that you're saying that you actually want the format string. In that case, you need to use get an appropriate DateTimeFormatInfo object and get its ShortDatePattern property. You can use System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat or System.Globalization.CultureInfo.InvariantCulture.DateTimeFormat to get that DateTimeFormatInfo.
I am using xdmp:document-filter(doc(uri)) to fetch the metadata from the documents. When I run this command on one of the documents I get the following result:-
xdmp:document-filter(doc("/Vision.doc"))//*:meta[#name eq "Creation_Date"]/#content
<?xml version="1.0" encoding="UTF-8"?>
<results warning="attribute node">
<warning warning="attributes cannot be root nodes" content="17-05-2012 00:48:00"/>
</results>
And when I run this command on another document then I get this:-
<?xml version="1.0" encoding="UTF-8"?>
<results warning="attribute node">
<warning warning="attributes cannot be root nodes" content="2012-06-03T13:45:00Z"/>
</results>
You can see that date format is different in both the outputs. There may be different date formats in documents uploaded in Marklogic Server. But I want to show the creation date of documents in some fixed format (e.g. May 16, 2012). How can I convert the different date formats to a fixed date format ? And also I want to compare these dates to the date entered by the user. The documents matching the search criteria should get returned by the search query. So I have two questions here:-
How to convert creation date of particular documents to some fixed format and to display it in the UI.
How to compare this creation date to the date entered by the user(which is in "mm/dd/yyyy" format) so that I can get the correct result.
You will have to parse the dateTime value. For example:
let $dt := "17-05-2012 00:48:00"
return
if ($dt castable as xs:dateTime)
then xs:dateTime($dt)
else xdmp:parse-dateTime("[Y01]-[M01]-[D01] [h01]:[m01]:[s01]", $dt)
This will return an xs:dateTime atomic value, which can be compared and displayed in the UI. If you want to support additional formats, you will need to create additional parse "picture" strings so they can also be converted to xs:dateTime. See the documentation on xdmp:parse-dateTime() for more information.
As a part of a larger open source project I cooked up a date parsing library that handles at least 20 different formats in 6 different languages. You can also supply your own formats if one is not already defined. It works by feeding it a date as a string in any of the defined formats and returning an xs:dateTime if it was able to successfully parse it. You can find the library here:
https://github.com/marklogic/Corona/blob/master/corona/lib/date-parser.xqy
To use it:
import module namespace dateparser="http://marklogic.com/dateparser" at "date-parser.xqy";
dateparser:parse($filteredDocument//*:meta[#name eq "Creation_Date"]/#content)
This will allow you to normalize the various date formats that binary documents can have. I will note that different binary formats (Word, PDF, JPEG, etc) will use different names for the creation date. So just looking for the "Creation_Date" metadata could leave some holes depending on what formats you're storing in MarkLogic.
Also note, that if you just want the date information without the time portion, you can cast the xs:dateTime to an xs:date. Doing so will retain the timezone information which is likely a good thing.
As for your second question…
There is a number of different ways to do this and reading some of the MarkLogic documentation is a good place to start. I'd recommend taking a look at:
http://docs.marklogic.com/guide/search-dev/rangequery
Hopefully that will shed a bit of light on what your query needs to look like. In simplest form you will probably have to first parse the date that the user provided. This can also be done with the date parsing library so users can enter tons of different date formats (eg: November 13th, 2012 or even in Spanish Noviembre 13th, 2012). Then use that parsed date to construct date range queries in MarkLogic.
If that doesn't help I'd post another question here with the specifics of where you're getting hung up.
I have been reading all about converting TEXT fields into date formats and ways to use Python to create date objects but my question remains.
My table has a dateTime column that is specified as TEXT, I would like to build a constraint that forces input to be in dateTime format, but as SQLite doesn't do dates (as I would like) I haven't worked out how to do it.
My current ideas: 1. Limit number of characters
2. Set separate attributes for day, month and year and constrain their domains
3. It is silly to do this on the database side just do it in the user interface
I would appreciate your opinions on these or other options.
Thanks :)
I've been trying to solve the same issue and the method I came up with was to use the date/time functions to parse the value and check that it hasn't changed. Essentially the following:
CREATE TABLE dts_test (
dts TEXT CHECK (dts IS datetime(dts))
);
If the default format is not what you want you can use the strftime or similar to design whatever format you want, but it must be something that the built-in date and time functions can parse.