diff --git a/skills/src/csharp/calendarskill/calendarskill/Dialogs/CalendarSkillDialogBase.cs b/skills/src/csharp/calendarskill/calendarskill/Dialogs/CalendarSkillDialogBase.cs index 02b5971ae9..1cbc09e9f9 100644 --- a/skills/src/csharp/calendarskill/calendarskill/Dialogs/CalendarSkillDialogBase.cs +++ b/skills/src/csharp/calendarskill/calendarskill/Dialogs/CalendarSkillDialogBase.cs @@ -629,7 +629,7 @@ protected List GetFilteredEvents(CalendarSkillState state, string us showingCardTitle = null; // filter meetings with start time - var timeResult = RecognizeDateTime(userInput, locale, false); + var timeResult = RecognizeDateTime(userInput, locale, state.GetUserTimeZone(), false); if (filteredMeetingList.Count <= 0 && timeResult != null) { foreach (var result in timeResult) @@ -767,33 +767,6 @@ protected async Task GetUserPhotoUrlAsync(ITurnContext context, EventMod return string.Format(AdaptiveCardHelper.DefaultAvatarIconPathFormat, displayName); } - protected bool IsRelativeTime(string userInput, string resolverResult, string timex) - { - var userInputLower = userInput.ToLower(); - if (userInputLower.Contains(CalendarCommonStrings.Ago) || - userInputLower.Contains(CalendarCommonStrings.Before) || - userInputLower.Contains(CalendarCommonStrings.Later) || - userInputLower.Contains(CalendarCommonStrings.Next)) - { - return true; - } - - if (userInputLower.Contains(CalendarCommonStrings.TodayLower) || - userInputLower.Contains(CalendarCommonStrings.Now) || - userInputLower.Contains(CalendarCommonStrings.YesterdayLower) || - userInputLower.Contains(CalendarCommonStrings.TomorrowLower)) - { - return true; - } - - if (timex == "PRESENT_REF") - { - return true; - } - - return false; - } - protected async Task DigestCalendarLuisResult(DialogContext dc, CalendarLuis luisResult, General generalLuisResult, bool isBeginDialog) { try @@ -901,7 +874,7 @@ protected async Task DigestCalendarLuisResult(DialogContext dc, CalendarLuis lui if (entity.Duration != null) { - var duration = GetDurationFromEntity(entity, dc.Context.Activity.Locale); + var duration = GetDurationFromEntity(entity, dc.Context.Activity.Locale, state.GetUserTimeZone()); if (duration != -1) { state.MeetingInfor.CreateHasDetail = true; @@ -1047,12 +1020,12 @@ protected async Task DigestCalendarLuisResult(DialogContext dc, CalendarLuis lui if (entity.MoveEarlierTimeSpan != null) { - state.UpdateMeetingInfor.MoveTimeSpan = GetMoveTimeSpanFromEntity(entity.MoveEarlierTimeSpan[0], dc.Context.Activity.Locale, false); + state.UpdateMeetingInfor.MoveTimeSpan = GetMoveTimeSpanFromEntity(entity.MoveEarlierTimeSpan[0], dc.Context.Activity.Locale, false, state.GetUserTimeZone()); } if (entity.MoveLaterTimeSpan != null) { - state.UpdateMeetingInfor.MoveTimeSpan = GetMoveTimeSpanFromEntity(entity.MoveLaterTimeSpan[0], dc.Context.Activity.Locale, true); + state.UpdateMeetingInfor.MoveTimeSpan = GetMoveTimeSpanFromEntity(entity.MoveLaterTimeSpan[0], dc.Context.Activity.Locale, true, state.GetUserTimeZone()); } if (entity.datetime != null) @@ -1159,9 +1132,10 @@ protected async Task DigestCalendarLuisResult(DialogContext dc, CalendarLuis lui } } - protected List RecognizeDateTime(string dateTimeString, string culture, bool convertToDate = true) + protected List RecognizeDateTime(string dateTimeString, string culture, TimeZoneInfo userTimeZone, bool convertToDate = true) { - var results = DateTimeRecognizer.RecognizeDateTime(DateTimeHelper.ConvertNumberToDateTimeString(dateTimeString, convertToDate), culture, options: DateTimeOptions.CalendarMode); + var userNow = TimeConverter.ConvertUtcToUserTime(DateTime.UtcNow, userTimeZone); + var results = DateTimeRecognizer.RecognizeDateTime(DateTimeHelper.ConvertNumberToDateTimeString(dateTimeString, convertToDate), culture, DateTimeOptions.CalendarMode, userNow); if (results.Count > 0) { @@ -1529,10 +1503,10 @@ private async Task> GetMeetingCardListAsync(CalendarSkillState state, return eventItemList; } - private int GetDurationFromEntity(CalendarLuis._Entities entity, string local) + private int GetDurationFromEntity(CalendarLuis._Entities entity, string local, TimeZoneInfo userTimeZone) { var culture = local ?? English; - var result = RecognizeDateTime(entity.Duration[0], culture); + var result = RecognizeDateTime(entity.Duration[0], culture, userTimeZone); if (result != null) { if (result[0].Value != null) @@ -1544,10 +1518,10 @@ private int GetDurationFromEntity(CalendarLuis._Entities entity, string local) return -1; } - private int GetMoveTimeSpanFromEntity(string timeSpan, string local, bool later) + private int GetMoveTimeSpanFromEntity(string timeSpan, string local, bool later, TimeZoneInfo userTimeZone) { var culture = local ?? English; - var result = RecognizeDateTime(timeSpan, culture); + var result = RecognizeDateTime(timeSpan, culture, userTimeZone); if (result != null) { if (result[0].Value != null) @@ -1585,7 +1559,7 @@ private List GetDateFromDateTimeString(string date, string local, Time { // if isTargetTimeRange is true, will only parse the time range var culture = local ?? English; - var results = RecognizeDateTime(date, culture, true); + var results = RecognizeDateTime(date, culture, userTimeZone, true); var dateTimeResults = new List(); if (results != null) { @@ -1603,8 +1577,7 @@ private List GetDateFromDateTimeString(string date, string local, Time if (dateTime != null) { - var isRelativeTime = IsRelativeTime(date, result.Value, result.Timex); - dateTimeResults.Add(isRelativeTime ? TimeZoneInfo.ConvertTime(dateTime, TimeZoneInfo.Local, userTimeZone) : dateTime); + dateTimeResults.Add(dateTime); } } else @@ -1630,7 +1603,7 @@ private List GetTimeFromDateTimeString(string time, string local, Time { // if isTargetTimeRange is true, will only parse the time range var culture = local ?? English; - var results = RecognizeDateTime(time, culture, false); + var results = RecognizeDateTime(time, culture, userTimeZone, false); var dateTimeResults = new List(); if (results != null) { @@ -1648,8 +1621,7 @@ private List GetTimeFromDateTimeString(string time, string local, Time if (dateTime != null) { - var isRelativeTime = IsRelativeTime(time, result.Value, result.Timex); - dateTimeResults.Add(isRelativeTime ? TimeZoneInfo.ConvertTime(dateTime, TimeZoneInfo.Local, userTimeZone) : dateTime); + dateTimeResults.Add(dateTime); } } else diff --git a/skills/src/csharp/calendarskill/calendarskill/Dialogs/CreateEventDialog.cs b/skills/src/csharp/calendarskill/calendarskill/Dialogs/CreateEventDialog.cs index 9be5d9eb8c..6b907caa98 100644 --- a/skills/src/csharp/calendarskill/calendarskill/Dialogs/CreateEventDialog.cs +++ b/skills/src/csharp/calendarskill/calendarskill/Dialogs/CreateEventDialog.cs @@ -8,10 +8,12 @@ using CalendarSkill.Models.DialogOptions; using CalendarSkill.Options; using CalendarSkill.Prompts; +using CalendarSkill.Prompts.Options; using CalendarSkill.Responses.CreateEvent; using CalendarSkill.Responses.Shared; using CalendarSkill.Services; using CalendarSkill.Utilities; +using Google.Apis.People.v1.Data; using Microsoft.Bot.Builder; using Microsoft.Bot.Builder.Dialogs; using Microsoft.Bot.Builder.Skills; @@ -670,10 +672,11 @@ public CreateEventDialog( return await sc.NextAsync(cancellationToken: cancellationToken); } - return await sc.PromptAsync(Actions.DatePromptForCreate, new PromptOptions + return await sc.PromptAsync(Actions.DatePromptForCreate, new DatePromptOptions { Prompt = ResponseManager.GetResponse(CreateEventResponses.NoStartDate), RetryPrompt = ResponseManager.GetResponse(CreateEventResponses.NoStartDateRetry), + TimeZone = state.GetUserTimeZone() }, cancellationToken); } catch (Exception ex) @@ -718,25 +721,12 @@ public CreateEventDialog( if (dateTime != null) { - var isRelativeTime = IsRelativeTime(sc.Context.Activity.Text, dateTimeValue, dateTimeConvertType); if (CalendarCommonUtil.ContainsTime(dateTimeConvertType)) { - state.MeetingInfor.StartTime.Add(TimeZoneInfo.ConvertTime(dateTime, TimeZoneInfo.Local, state.GetUserTimeZone())); + state.MeetingInfor.StartTime.Add(dateTime); } - // Workaround as DateTimePrompt only return as local time - if (isRelativeTime) - { - dateTime = new DateTime( - dateTime.Year, - dateTime.Month, - dateTime.Day, - DateTime.Now.Hour, - DateTime.Now.Minute, - DateTime.Now.Second); - } - - state.MeetingInfor.StartDate.Add(isRelativeTime ? TimeZoneInfo.ConvertTime(dateTime, TimeZoneInfo.Local, state.GetUserTimeZone()) : dateTime); + state.MeetingInfor.StartDate.Add(dateTime); } } catch (FormatException ex) @@ -764,11 +754,12 @@ public CreateEventDialog( var state = await Accessor.GetAsync(sc.Context, cancellationToken: cancellationToken); if (!state.MeetingInfor.StartTime.Any()) { - return await sc.PromptAsync(Actions.TimePromptForCreate, new NoSkipPromptOptions + return await sc.PromptAsync(Actions.TimePromptForCreate, new TimePromptOptions { Prompt = ResponseManager.GetResponse(CreateEventResponses.NoStartTime), RetryPrompt = ResponseManager.GetResponse(CreateEventResponses.NoStartTimeRetry), NoSkipPrompt = ResponseManager.GetResponse(CreateEventResponses.NoStartTimeNoSkip), + TimeZone = state.GetUserTimeZone() }, cancellationToken); } else @@ -803,8 +794,7 @@ public CreateEventDialog( if (dateTime != null) { - var isRelativeTime = IsRelativeTime(sc.Context.Activity.Text, dateTimeValue, dateTimeConvertType); - state.MeetingInfor.StartTime.Add(isRelativeTime ? TimeZoneInfo.ConvertTime(dateTime, TimeZoneInfo.Local, state.GetUserTimeZone()) : dateTime); + state.MeetingInfor.StartTime.Add(dateTime); } } catch (FormatException ex) diff --git a/skills/src/csharp/calendarskill/calendarskill/Dialogs/UpdateEventDialog.cs b/skills/src/csharp/calendarskill/calendarskill/Dialogs/UpdateEventDialog.cs index 9ffcb0c175..c78eb09e5a 100644 --- a/skills/src/csharp/calendarskill/calendarskill/Dialogs/UpdateEventDialog.cs +++ b/skills/src/csharp/calendarskill/calendarskill/Dialogs/UpdateEventDialog.cs @@ -5,6 +5,8 @@ using System.Threading.Tasks; using CalendarSkill.Models; using CalendarSkill.Models.DialogOptions; +using CalendarSkill.Options; +using CalendarSkill.Prompts; using CalendarSkill.Prompts.Options; using CalendarSkill.Responses.Shared; using CalendarSkill.Responses.UpdateEvent; @@ -218,10 +220,11 @@ public UpdateEventDialog( return await sc.NextAsync(); } - return await sc.PromptAsync(Actions.TimePrompt, new PromptOptions + return await sc.PromptAsync(Actions.TimePrompt, new TimePromptOptions { Prompt = ResponseManager.GetResponse(UpdateEventResponses.NoNewTime), - RetryPrompt = ResponseManager.GetResponse(UpdateEventResponses.NoNewTimeRetry) + RetryPrompt = ResponseManager.GetResponse(UpdateEventResponses.NoNewTimeRetry), + TimeZone = state.GetUserTimeZone() }, cancellationToken); } catch (Exception ex) @@ -304,13 +307,6 @@ public UpdateEventDialog( continue; } - var isRelativeTime = IsRelativeTime(sc.Context.Activity.Text, resolution.Value, dateTimeConvertTypeString); - if (isRelativeTime) - { - dateTimeValue = DateTime.SpecifyKind(dateTimeValue, DateTimeKind.Local); - } - - dateTimeValue = isRelativeTime ? TimeZoneInfo.ConvertTime(dateTimeValue, TimeZoneInfo.Local, state.GetUserTimeZone()) : dateTimeValue; var originalStartDateTime = TimeConverter.ConvertUtcToUserTime(state.ShowMeetingInfor.FocusedEvents[0].StartTime, state.GetUserTimeZone()); if (dateTimeConvertType.Types.Contains(Constants.TimexTypes.Date) && !dateTimeConvertType.Types.Contains(Constants.TimexTypes.DateTime)) { diff --git a/skills/src/csharp/calendarskill/calendarskill/Prompts/DatePrompt.cs b/skills/src/csharp/calendarskill/calendarskill/Prompts/DatePrompt.cs index 87f1b0edd3..1aad06b8d3 100644 --- a/skills/src/csharp/calendarskill/calendarskill/Prompts/DatePrompt.cs +++ b/skills/src/csharp/calendarskill/calendarskill/Prompts/DatePrompt.cs @@ -41,7 +41,7 @@ public DatePrompt(string dialogId, PromptValidator> va if (!(options is DatePromptOptions)) { - throw new Exception(nameof(options) + " should be GetEventOptions"); + throw new Exception(nameof(options) + " should be DatePromptOptions"); } if (isRetry && options.RetryPrompt != null) diff --git a/skills/src/csharp/calendarskill/calendarskill/Prompts/GetEventPrompt.cs b/skills/src/csharp/calendarskill/calendarskill/Prompts/GetEventPrompt.cs index cdf4d34fb5..95b4226830 100644 --- a/skills/src/csharp/calendarskill/calendarskill/Prompts/GetEventPrompt.cs +++ b/skills/src/csharp/calendarskill/calendarskill/Prompts/GetEventPrompt.cs @@ -76,7 +76,7 @@ public GetEventPrompt(string dialogId, PromptValidator> valida { var message = turnContext.Activity.AsMessageActivity(); var culture = turnContext.Activity.Locale ?? DefaultLocale ?? English; - var date = GetTimeFromMessage(message.Text, culture); + var date = GetTimeFromMessage(message.Text, culture, userTimeZone); if (date.Count > 0) { // input is a time @@ -172,14 +172,14 @@ private async Task> GetEventsWithTitle(string title) return events; } - private IList GetTimeFromMessage(string message, string culture) + private IList GetTimeFromMessage(string message, string culture, TimeZoneInfo userTimeZone) { - IList results = RecognizeDateTime(message, culture); + IList results = RecognizeDateTime(message, culture, userTimeZone); return results; } - private List RecognizeDateTime(string dateTimeString, string culture) + private List RecognizeDateTime(string dateTimeString, string culture, TimeZoneInfo userTimeZone) { var userNow = TimeConverter.ConvertUtcToUserTime(DateTime.UtcNow, userTimeZone); var results = DateTimeRecognizer.RecognizeDateTime(dateTimeString, culture, DateTimeOptions.CalendarMode, userNow); diff --git a/skills/src/csharp/calendarskill/calendarskill/Prompts/TimePrompt.cs b/skills/src/csharp/calendarskill/calendarskill/Prompts/TimePrompt.cs index eae86a4835..6655bf5a9e 100644 --- a/skills/src/csharp/calendarskill/calendarskill/Prompts/TimePrompt.cs +++ b/skills/src/csharp/calendarskill/calendarskill/Prompts/TimePrompt.cs @@ -38,7 +38,7 @@ public TimePrompt(string dialogId, PromptValidator> va if (!(options is TimePromptOptions)) { - throw new Exception(nameof(options) + " should be GetEventOptions"); + throw new Exception(nameof(options) + " should be TimePromptOptions"); } if (isRetry && options.RetryPrompt != null) diff --git a/skills/src/csharp/calendarskill/calendarskilltest/Prompt/DatePromptTests.cs b/skills/src/csharp/calendarskill/calendarskilltest/Prompt/DatePromptTests.cs index 0b9348e58d..e55e09d2d6 100644 --- a/skills/src/csharp/calendarskill/calendarskilltest/Prompt/DatePromptTests.cs +++ b/skills/src/csharp/calendarskill/calendarskilltest/Prompt/DatePromptTests.cs @@ -1,16 +1,19 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Threading; using System.Threading.Tasks; +using CalendarSkill.Models; using CalendarSkill.Prompts; using CalendarSkill.Prompts.Options; +using CalendarSkillTest.Flow.Fakes; +using Microsoft.Bot.Builder; using Microsoft.Bot.Builder.Adapters; +using Microsoft.Bot.Builder.Dialogs; using Microsoft.Bot.Schema; using Microsoft.Recognizers.Text; using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace Microsoft.Bot.Builder.Dialogs.Tests +namespace CalendarSkillTest.Prompt { [TestClass] public class DatePromptTests diff --git a/skills/src/csharp/calendarskill/calendarskilltest/Flow/Prompt/GetEventPromptTests.cs b/skills/src/csharp/calendarskill/calendarskilltest/Prompt/GetEventPromptTests.cs similarity index 100% rename from skills/src/csharp/calendarskill/calendarskilltest/Flow/Prompt/GetEventPromptTests.cs rename to skills/src/csharp/calendarskill/calendarskilltest/Prompt/GetEventPromptTests.cs