Change Amazon Lex Chat bot Time zone - timezone

Now,I am integrating my amazon Lex chat bot to my web. I got the time zone issue. Time zone is in US East (N. Virginia). So if I say today, that is based on Virginia time. So I find how to change time zone and the suggestion is to set the x-amz-lex:time-zone request attribute to my region. but I donot know how to do and where to do. PLs help me!! Thanks.
I used simple Template "https://s3.amazonaws.com/aws-bigdata-blog/artifacts/aws-lex-web-ui/artifacts/templates/master.yaml".
I copied the codes from SnippetUrl and paste to my web page. The Chat Bot appear. So how should I pass these request attribute.
this this my chat bot in amazon lex
this is my cloud formation
These codes are from SnippetUrl in CodeBuildDeploy

There may be an option in the template you are using but I can't find it, so here is what you need to know about setting timezones in Lex.
First of all, the only way to change the timezone from the default East US is to use PostContent API or PostText API. They should really have a timezone setting in the Lex Console so you can set the default timezone at least, but they don't.
The correct way:
The AWS SDK is needed to use PostContent API or PostText API to pass the user's input to your Lex chat bot. When passing data to Lex this way, you can include requestAttributes with the user's input, unique ID and session attributes (optional). Here's an example of how you would set the timezone in requestAttributes to Singapore Time:
{
"inputText": "What the user said.",
"requestAttributes": {
"x-amz-lex:time-zone" : "Singapore"
},
"sessionAttributes": null
}
The workaround:
If you cannot use or cannot access the use of PostContent or PostText, then you need to work with what you have. Right now, it looks like you are only using a Lambda function for fulfillment, but you should really also use it for "initialization and validation" too.
This will pass a request to your Lambda function every time Lex processes an input and you can direct Lex with exactly how to reply. This gives you much greater control of your chat bot.
To understand the format of the Request (sometimes called "Event") and how to format the Response in that Lambda function, you will want to read these docs.
Now, Lex processes the date and time from the user's input...(In your example, the user says "today")...and Lex will fill the date or time slots with something like (date) 2018-11-02 (time) 13:00 which will be appropriate for Eastern Standard Time (UTC -5). But Singapore is UTC +8. So you will need to convert that date and time in your Lambda function and overwrite the slots to the equivalent Singaporean time then pass those slots back in your Lambda's response to Lex.
There are multiple ways to do that conversion depending on whether your Lambda is in Node.js or Python and plenty of answers and guides on timezone conversion.
Example:
User Input: "I want to book a meeting room from 1pm to 2pm for today"
To capture the values of this input, your Intent should be set up with something like:
3 slots: {date} {time_start} {time_end}
Intent Utterance: "I want to book a meeting room from {time_start} to {time_end} for {date}"
Lex will then parse the input and fill the slots (using timezone default: East US). Then Lex will pass the request to your "initialization and validation" Lambda Function. The request (or "event") will include:
{
"currentIntent": {
"name": "BookRoom",
"slots": {
"date": "2018-11-05",
"time_start": "13:00",
"time_end": "14:00",
},
},
...
}
Then in the Lambda Function you can take those values (Node.js):
var date = event['currentIntent']['slots']['date'];
var time_start = event['currentIntent']['slots']['time_start'];
var time_end = event['currentIntent']['slots']['time_end'];
Now for your conversion logic:
Since Singapore is 13 hours ahead of East US, just take those times and add 13 hours to them. If when doing that, it passes midnight, then also increase the date by 1 day.
This will work for inputs of "today", "tomorrow", "next tuesday", or even "25 Jan 2035", because Lex parses all of those the same way and simply delivers them to your Lambda in default East US time formatted as (date) yyyy-mm-dd and (time) hh:mm.
After you convert them, just set those slots as the new date and times, then pass the slots back to Lex in your response. Lex will then hold the slot values in Singapore time.

This is the solution image
Finally, I got the solution. If someone want to know the solution check in the photo. I just try to fix the codes from aws github. Thanks.

Related

How do I pull the month from text strings in this Twilio format 2019-08-22 06:12:58 MDT?

I am using the Twilio log file to crunch some data and need to convert the Twilio format for dates into something that Google Sheets can recognize as a date so I can then extract what month the date is referring to. I think that first, the text string has to be converted to be a better format and then I can use one of Google Sheets functions to extra the month. Currently, this is the format in the log file:
"2019-08-22 06:12:58 MDT"
I used GoogleSheets TIMEVALUE and TEXT functions.
=TIMEVALUE(I2)
and
=text(I2,”mmmm”)
I get "Formula Parse Error"
The timezone stamp is messing up the Google formulas for you.
So you may want to try getting rid of that with something like this:
=text(index(split(I2," "),,1),"mmmm")
The split function breaks up the logged time stamp into 2019-08-22 | 06:12:58 | MDT across three columns.
And the index function then gets the just the first column - the date bit from there.
And then the text function gets the month name out of the date.
you can use:
=TEXT(LEFT(A1, 10), "mmmm")
and in array it would be:
=ARRAYFORMULA(TEXT(LEFT(A1:A, 10), "mmmm"))

grails ORM , how to search Date without time

I am using postrges db.
My domain has a date field:
java.util.Date requestedDate;
I am trying to search by date in my controller:
eq ("requestedDate", requestedDate)
This works fine, but the problem is that date and time has to be exactly matching for this. But in application the user will only enter the date to search items (like give me all requests which are made on 2014-02-05 and the browser application will add the current time to the request). So the comparison fails because the user entered time is different from the time during creation of the request.
I tried 'like' but it throws error.
How to compare only date part ?
You could do something like this:
Date now = new Date()
now.clearTime()
def results = Meeting.withCriteria {
between('date', now, now+1)
}
So this strips off the time portion of the current date, and then does a 'between' query (between midnight just gone and midnight 24 hours later).
Still it looks like there is no convenient way to realize this.
You need a small detour by computing the start of the day and the end of the day and use the between operator.
EDIT
I just saw now rcgeorge23 gave you the right example for doing this.

evaluate difference between 2 dates to make a transition possible

Is this possible to evaluate the duration between a specified date on a form of a workflow, and the system date ? that what I want to do, in order to show (if this possible too) a short message if 1 day occurs since the specified date above, forbidding the transition of the status Closed to Reopened...
Thanks a lot,
Christophe
I think the Script Runner has a validator that does something like this but I can't find it. Then you could write a post function with the Script Runner. Otherwise it's back to creating a custom validator, as described in my book Practical JIRA Plugins (O'Reilly)
You can use the ScriptRunner plugin in addition with the following script in the validator section for the Reopened transition:
Date now = new Date()
Date cfDate = new Date(cfValues['YourCustomField'].getTime())
new Date(now.getYear(), now.getMonth(), now.getDate()).compareTo(cfDate) <= 0
Replace YourCustomField with the name of your custom field. This will ensure that the transition will check whether the current date is beyond the date set in the custom field, and blocks it if it is.
First of all, thank you for your answer.
It works to allow transition when dates are similar, but my purpose was modified by my responsible. He would like to allow the transition if dates are similar or if the duration between them is only 1 day or less.
Example :
System date is 09/07/2013 (Paris)
My date (dd/mm/yyyy format) Transition allowed Why
07/07/2013 NO my date is former to system date
08/07/2013 NO my date is former to system date
09/07/2013 YES my date and system date equals
10/07/2013 YES only 1 day occur between 2 dates
11/07/2013 NO 2 days occur between 2 dates
Here is the code I wrote in order to do that, but it does'nt work (maybe a Java syntax error?) :
Date now = new Date()
Date cfDate = new Date(cfValues['Date de clôture réelle de la demande'].getTime())
new Boolean(((now.getTime() - cfDate) / 86400000) <= 1) && (now.getTime() >= cfDate ))
Excuse me for my english. I'm french, and I try to improve my English.
Thanks a lot.

get time of Different Timezone

My task: I am going to run a contest world wide at my website. A problem setter will set problems from a specific area of the world setting a time and date of starting time of the contest. I have to show that time correctly all over the world so the the contest starts at a time everywhere of the world.
My Idea : I planed to get the time from the problem setter of his time zone using server site language like php time(), & will store to database converting to timezone= zero (0). And who are going to attend the contest I'll just add hour(s) of that time zone with my database time.
Need help: I have no Idea how to convert that timestamps to timezone 'zero', even how can I get the ±hour(s) of current timezone?
Thank you...
Step 1:
Let the user choose his timezone. You could fill a dropdown with values from this site: http://php.net/manual/en/timezones.php
Step 2:
Convert the timezone to servertime
$timezone_client = new DateTimeZone('America/Denver');
$timezone_server = new DateTimeZone('Pacific/Nauru');
$datetime = new DateTime('2013-01-25 12:00:00', timezone_client);
$datetime->setTimezone($timezone_server);
echo $datetime->format('Y-m-d H:i:s');
Timezone 0 = "UTC" (sometimes called GMT)
Your system / language will have a Timezone class, which provides difference to GMT/UTC

OData: Date "Greater Than" filter

Is there a way to return a series of records in OData by specifying a "Date greater than xxxxx" filter...but using a Date that was previously obtained form an OData feed?
Use Case: Pretend that I want to build a web page that displays a list of the most recently completed online orders. This is what I'm aiming for:
Load the page
Hit my OData service asynchronously, returning the last 100 orders (ordering by date descending so that the most recently completed order shows up first)
Build the HTML on the page using the OData data
Store the MAX date into a global variable (looks like this: /Date(1338336000000)/)
Hit the OData service on a 30 second interval but this time specify a filter to only return records where the order date is greater than the previous MAX Date. In this case: /Date(1338336000000)/
If any records are returned, build the HTML for those records and prepend the items to the previously loaded items.
Where I am struggling is in specifying the Date "greater than" filter. For some reason, the date filters in OData do not seem to play very nice with OData's own native date format. Do I need to convert the date originally obtained into a different format that can be used for filtering?
I want to do something like this:
http://mydomain/Services/v001.svc/Orders?$filter=close_dt%20gt%201338336000000
FYI: I'm using V2
Figured this out.
OData V2 out-of-the-box returns dates out of SQL in JSON Date format like so:
/Date(1338282808000)/
However, in order to use a date as a filter within an OData call, your date has to be in EDM format, looking like this:
2012-05-29T09:13:28
So, I needed to get the date from my initial OData call, then convert it to the EDM format for use in my subsequent OData calls, which look like this:
/Services/v001.svc/Orders?$filter=close_dt gt DateTime'2012-05-29T09:13:28'
I ended up creating a javascript function that does the formatting switcharoo:
function convertJSONDate(jsonDate, returnFormat) {
var myDate = new Date(jsonDate.match(/\d+/)[0] * 1);
myDate.add(4).hours(); //using {date.format.js} to add time to compensate for timezone offset
return myDate.format(returnFormat); //using {date.format.js} plugin to format :: EDM FORMAT='yyyy-MM-ddTHH:mm:ss'
}
A couple of notes:
The JSON format does not seem to adjust for timezone, so the date returned does not match the date I see in my database. So I had to add time manually to compensate (someone please explain this).
I am using the date.format.js plugin which you can download here for formatting the date and adding time.
In OData V4 date filtering format has changed to $filter=close_dt gt 2006-12-30T23:59:59.99Z
For example
http://services.odata.org/V4/OData/OData.svc/Products?$filter=ReleaseDate%20gt%202006-12-30T23:59:59.99Z
For previous versions of OData see previous answers
If you use the datetime logic, you can do lt or gt.
e.g.
...mydomain/Services/v001.svc/Orders?$filter=close_dt gt datetime'20141231'
Just an FYI: in V3 of the protocol the non-tick-based datetime format is now the default:
http://services.odata.org/Experimental/OData/OData.svc/Products%280%29?$format=application/json;odata=verbose&$select=ReleaseDate
..."ReleaseDate":"1992-01-01T00:00:00"...
I will just try to make the answer of #avitenberg more clear:
var date= DateTime.Now;
//Convert time to UTC format
$"filter={close_dt} gt {date:yyyy-MM-ddTHH:mm:ss.FFFZ}";
See Microsoft:

Resources