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)
Related
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.
This has been giving me trouble for a long time now, and I wouldn't think this would be so hard. I have a model with some dates, and date data coming from the API like so:
{
...
tollgate1: '2016-04-15',
tollgate2: '2017-01-01',
projectClose: '2016-10-21',
}
I created a format-date helper (which uses moment.js) to format the dates in view mode, like so:
And that's shows it correctly. However, when I switch to edit mode, the input elements are still referencing the same values, but now they all go one day earlier!
This has been maddening for some time. I've thought it might be due to a like of time zone information in the data, but since I can't change the data that's fed to my app, how can I get it to just display the date in the data, regardless of timezone? For example, with the Tollgate 1 date, I would want it to show April 15 no matter where the user is in the world.
Okay, so as with many things, this isn't an Ember thing so much as just a JavaScript thing. It's really hard learning both at once!
Since my dates coming down from the API don't have a time zone, they're assumed to be GMT, and so my EST timezone of -4 hours makes it show as the day before. Apparently moment.js has some built-in handling so that's why the format-date helper works fine.
What I did to solve is to just add computed properties on my model for each date, and create a new Date object by pulling out the parts from the input date, like so:
function convertDateToUtc(d) {
if(d) {
return new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate());
} else {
return null;
}
}
export default DS.Model.extend({
...
tollgate1Date: Ember.computed('tollgate1', function() {
return convertDateToUtc(this.get('tollgate1'));
})
});
I need to:
Set the form to "Not accepting responses" every weekday at 7:16 am
Then set the form to “Accepting responses” every weekday at 5:30 am
Clear all responses from the form and the form spreadsheet on Friday at 2:00 pm
I have no experience with writing scripts. This is for a teacher sign-in sheet for a public high school.
Any help is greatly appreciated!
Unfortunately, StackOverflow isn't here to write your code for you, so you won't receive an answer that you can copy/paste and get to work. The community will instead assist you with any specific roadblocks that you encounter with your code (If they can).
However, you'll be able to achieve this with the Form Service, specifically, the '.setAcceptingResponses()' method. You'll also need the Spreadsheet service with the '.clear()' method to empty the sheet.
You'll find the time triggers are the easiest way to set when the form becomes active and inactive again, however, you've mention very specific times that this needs to go offline and online again (7:16 am and 5:30 am, but only on weekdays, and 2PM to clear the sheet on Fridays), but Google Apps script time triggers can't be set down to the minute (Note the triggers explanation about the time being randomized).
An alternative would be to write a function that checks the time, have that function run every minute, and if the time = 2PM on a Friday then clear the sheet etc.
have you checked out formLimiter by New Visions Cloud Lab?
http://cloudlab.newvisions.org/add-ons/formlimiter
The description is:
formLimiter automatically sets Google Forms to stop accepting responses after a maximum number of responses, at a specific date and time, or when a spreadsheet cell contains a specified value.
Great for time-bound assignments, event registrations with limited seats, or other first-come, first-served signup scenarios.
I was able to write a short script and set a trigger, I named my form "Play"
Here is the script:
function limitDays() {
var form = FormApp.getActiveForm();
var lastDay = 21;
var currDate = new Date();
var dayOfMonth = currDate.getDate();
if (dayOfMonth > lastDay) {
form.setAcceptingResponses(false);
} else {
form.setAcceptingResponses(true);
}
}
I am creating a google calendar will contain birthdays in it. To make it automatically, I created a form and a script that would automatically create the vent and repeat it every year.
I get a problem that I just can't understand: the day and the month get inversed in the calendar.
The code is made by 2 files, one that contains the function that creates the event and the other is triggered when the form is submitted. The dates are also saved in a google spreadsheet. Here is the code:
Create the event:
function createBirthdays_ ( namedValues ) {
var cEvent = CalendarApp.getCalendarsByName( "Anniversaires CA" )[0].createAllDayEventSeries(namedValues.Nom, new Date ( namedValues.Date ), CalendarApp.newRecurrence().addYearlyRule());
}
The function that gets triggered when the form is submitted:
function onFormSubmit(e) {
createBirthdays_ ( e.namedValues );
}
I am sure it is something really simple, but I can't find it.
Might it be that in one of them you get European date format and in the other the US? There the month and day are in different order. So you might want to try to process namedValues.
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