Watson assistant putting the day of the week in a variable based on user input of #sys-date - ibm-cloud

I'm making a bot that can take dinner reservations. When it asks for the users reservation time, I'd like the bot to populate my variable $dayoftheweek with the day of the week based on the date the user inputs. How would I be able to do that?
here is my slot "If Found".
Basically I'd like to know what "value" I could put in to get the day of the week populated.

The easiest would be to use the new system entities (currently in beta). Enable the beta in your skills options. Then, in your dialog node, assign the following:
Check for: #sys-data.day_of_week
save as: mydayofweek
Note that the day names are lower case.

You can use the method reformatDateTime of the expession language to get the day from #sys-date.
For example setting $dayofweek to
<? #sys-date.reformatDateTime('u') ?>
will set $dayofweek to a value between "1" (Monday) and "7" (Sunday)
or setting $dayofweek to
<? #sys-date.reformatDateTime('E') ?>
will set $dayofweek to a value between "Mo" and "Su"

The value of #sys-date is stored as a string format "yyyy-MM-dd" e.g. "2016-11-21".
If you want to know what day of the week that date is, you can use the method reformatDateTime:
"<? #sys-date.reformatDateTime('EEEE') ?>"
Here all the posibles values of the method
So your node would look something like this.
Or in JSON format:
{
"context": {
"dayoftheweek": "<? #sys-date.reformatDateTime('EEEE') ?>"
}
}
And here a small test of what would be stored in $dayoftheweek:
Watson: Hello. How can I help you?
User: Day of the week test
Watson: Tell me a date
User: September 13, 2019
Watson: Friday
Here is the JSON Skill for the test.

Related

IBM Watson Assistant: user input time frame validation

I am using IBM Watson Assistant and try to validate user input against time frames / spans. What function should I use?
I was using #sys-date.before(now()) method to validate the time frame between past and present of a user input, but it does now work for me. If I input now or today Watson Assistant still thinks it is a past...
#sys-date.before(now()):
Looks "like you're trying to make a reservation in the past. Try again."
true $day it is
I expect if user inputs now or today to make reservations work, and if user inputs time in the past to response as
"like you're trying to make a reservation in the past. Try again."
The code snippet in question looks like this:
{ "context":
{ "day": "#sys-date" } }
{ "context":
{ "time": "<? #sys-time.reformatDateTime('h:mm a') ?>" } }
I solved it! What I did is I put (today) for here #sys-date.before(today()) and now for here #sys-time.before(now())
With IBM Watson Assistant you can use systen entities #sys-date and #sys-time to turn user input into data / time values. And you can use expression language functions for date and time to evaluate and transform those values. It seems that you are already using both. Now it is up to the logic...
There are functions before and after, but also sameMoment or sameOrAfter and more for comparisons. If the user inputs today, it is not before now because both would refer to the same day and date. Are you looking for the time value to be before the current timestamp or before the current date? You would need to compare time to time or date to date. You can reformat the values to snip off the time component and turn them into dates.
For more fancy validations you could even use java.util.Date functionality.
This should be true if it is a past moment:
now.after(yourInput)

Formatting a date retrieved from Wikidata

So let's say I have an Infobox template in Wikipedia that retrieves a company foundation date from Wikidata. It contains the following code:
|label7 = Year founded
|text7 = {{wikidata|p571|{{{founded|}}}}}
My problem is that what's retrieved is formatted as 31 January 2010 and it looks weird next to "Year founded' since it is not a year but the whole date. Of course I could rename the label from "Year founded" to "Date founded" and voila, problem solved, right? But I do want to just get the year from Wikidata, not the whole date.
What would be the code for this? I imagine something like {{wikidata|p571[year]|{{{founded|}}}}} or {{wikidata|p571[0]|{{{founded|}}}}} or {{wikidata|p571[YYYY]|{{{founded|}}}}}.
Thanks in advance!
This doesn't sound like a programming question, but it looks like you can request a specific date format as the third parameter to wikidata
https://en.wikipedia.org/wiki/Module:Wikidata#Testing_getValue.2C_getRawValue_and_getDateValue
{{#invoke:Wikidata|getDateValue|P569|FETCH_WIKIDATA|y}}
I highly recomend you to filter the year from date using RegularExpression instead of trying to get only the year.

Grails Date variable will not set the time

I make a simple domain class
class Meetings {
Date when
String where
}
Then I run 'generate-all' on Meetings. I then start the app 'RunApp'.
In the app I'm able to to choose the month, day, and year for the when variable, however I can't choose the time as in hours:minutes (example 7:30). I wouldn't expect to be able to do this, but if I save the date it formats it as month, day, year, and then -00:00:00. How do I set the time using the date variable? or is there another way?
If you are using the datepicker tag in grails, it is pretty straight forward.
In the views folder under a domain class folder there is _form.gsp. Inside _form.gsp is a date picker tag.
<g:datePicker name="dateTimeVariableName" value="${dateTimeValue}"
default="${new Date().clearTime()}" precision="minute"/>
The keyword here is precision.
You should check the documentation. Its always a good idea. Hope this helps.

How to get the last day of the current month in DataStage?

I have explored all the functions avialable in the trasformer, but could not found the exact function to get the last day of current month by passing date in same default format i.e. yyyy-mm-dd.Please help me in this regard.
Field("31|28|31|30|31|30|31|31|30|31|30|31", "|", MonthFromDate(InLink.dateVar))
It is more precise to establish the first day of next month then use DateFromDaysSince function to establish the day before. I created an integer(6) stage variable which contained century and month+1 from source link e.g. 201410
DateFromDaysSince(-1, StringToDate(svIHBKPR, "%yyyy%mm") : "%yyyy-%mm-%dd")
There is a transformer function called DaysInMonth.
Example: DaysInMonth(“2017-01-23”)= 31

Facebook-like "time since" calculation algorithm

On Facebook, each comment or other user event has a timestamp. But it is not listed as a simple date, but presented in a form of a human-friendly string. For example if right now it is 08:38 and the comment was made at 08:31, Facebook doesn't just tell you the time, but says "7 minutes ago".
Is there an open source implementation of Facebook algorithm (or similar) that takes a data of event, a current date and tells in a human-friendly form how long has it been since?
Pretty date http://ejohn.org/projects/javascript-pretty-date/ is a good javascript library for this
You could dig into timeago jQuery plugin's source code to study.
What I think that should be the best is this :
Store the timestamp when the comment is made (eg- 3:45 12-10-2012)
Get the current system time
Get the differnce between the two .i.e (current time -comment time ) .
Most of the languages provide the datediff method . Like in PHP you can use it like this