Skip to content
This repository was archived by the owner on Jun 30, 2022. It is now read-only.

Commit cf1a54d

Browse files
committed
merged in calendar changes
2 parents 956861b + 3ffe738 commit cf1a54d

File tree

8 files changed

+63
-79
lines changed

8 files changed

+63
-79
lines changed

skills/src/csharp/calendarskill/calendarskill/Dialogs/CalendarSkillDialogBase.cs

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ protected List<EventModel> GetFilteredEvents(CalendarSkillState state, string us
629629
showingCardTitle = null;
630630

631631
// filter meetings with start time
632-
var timeResult = RecognizeDateTime(userInput, locale, false);
632+
var timeResult = RecognizeDateTime(userInput, locale, state.GetUserTimeZone(), false);
633633
if (filteredMeetingList.Count <= 0 && timeResult != null)
634634
{
635635
foreach (var result in timeResult)
@@ -767,33 +767,6 @@ protected async Task<string> GetUserPhotoUrlAsync(ITurnContext context, EventMod
767767
return string.Format(AdaptiveCardHelper.DefaultAvatarIconPathFormat, displayName);
768768
}
769769

770-
protected bool IsRelativeTime(string userInput, string resolverResult, string timex)
771-
{
772-
var userInputLower = userInput.ToLower();
773-
if (userInputLower.Contains(CalendarCommonStrings.Ago) ||
774-
userInputLower.Contains(CalendarCommonStrings.Before) ||
775-
userInputLower.Contains(CalendarCommonStrings.Later) ||
776-
userInputLower.Contains(CalendarCommonStrings.Next))
777-
{
778-
return true;
779-
}
780-
781-
if (userInputLower.Contains(CalendarCommonStrings.TodayLower) ||
782-
userInputLower.Contains(CalendarCommonStrings.Now) ||
783-
userInputLower.Contains(CalendarCommonStrings.YesterdayLower) ||
784-
userInputLower.Contains(CalendarCommonStrings.TomorrowLower))
785-
{
786-
return true;
787-
}
788-
789-
if (timex == "PRESENT_REF")
790-
{
791-
return true;
792-
}
793-
794-
return false;
795-
}
796-
797770
protected async Task DigestCalendarLuisResult(DialogContext dc, CalendarLuis luisResult, General generalLuisResult, bool isBeginDialog)
798771
{
799772
try
@@ -900,7 +873,7 @@ protected async Task DigestCalendarLuisResult(DialogContext dc, CalendarLuis lui
900873

901874
if (entity.Duration != null)
902875
{
903-
var duration = GetDurationFromEntity(entity, dc.Context.Activity.Locale);
876+
var duration = GetDurationFromEntity(entity, dc.Context.Activity.Locale, state.GetUserTimeZone());
904877
if (duration != -1)
905878
{
906879
state.MeetingInfor.CreateHasDetail = true;
@@ -1040,12 +1013,12 @@ protected async Task DigestCalendarLuisResult(DialogContext dc, CalendarLuis lui
10401013

10411014
if (entity.MoveEarlierTimeSpan != null)
10421015
{
1043-
state.UpdateMeetingInfor.MoveTimeSpan = GetMoveTimeSpanFromEntity(entity.MoveEarlierTimeSpan[0], dc.Context.Activity.Locale, false);
1016+
state.UpdateMeetingInfor.MoveTimeSpan = GetMoveTimeSpanFromEntity(entity.MoveEarlierTimeSpan[0], dc.Context.Activity.Locale, false, state.GetUserTimeZone());
10441017
}
10451018

10461019
if (entity.MoveLaterTimeSpan != null)
10471020
{
1048-
state.UpdateMeetingInfor.MoveTimeSpan = GetMoveTimeSpanFromEntity(entity.MoveLaterTimeSpan[0], dc.Context.Activity.Locale, true);
1021+
state.UpdateMeetingInfor.MoveTimeSpan = GetMoveTimeSpanFromEntity(entity.MoveLaterTimeSpan[0], dc.Context.Activity.Locale, true, state.GetUserTimeZone());
10491022
}
10501023

10511024
if (entity.datetime != null)
@@ -1152,9 +1125,10 @@ protected async Task DigestCalendarLuisResult(DialogContext dc, CalendarLuis lui
11521125
}
11531126
}
11541127

1155-
protected List<DateTimeResolution> RecognizeDateTime(string dateTimeString, string culture, bool convertToDate = true)
1128+
protected List<DateTimeResolution> RecognizeDateTime(string dateTimeString, string culture, TimeZoneInfo userTimeZone, bool convertToDate = true)
11561129
{
1157-
var results = DateTimeRecognizer.RecognizeDateTime(DateTimeHelper.ConvertNumberToDateTimeString(dateTimeString, convertToDate), culture, options: DateTimeOptions.CalendarMode);
1130+
var userNow = TimeConverter.ConvertUtcToUserTime(DateTime.UtcNow, userTimeZone);
1131+
var results = DateTimeRecognizer.RecognizeDateTime(DateTimeHelper.ConvertNumberToDateTimeString(dateTimeString, convertToDate), culture, DateTimeOptions.CalendarMode, userNow);
11581132

11591133
if (results.Count > 0)
11601134
{
@@ -1522,10 +1496,10 @@ private async Task<List<Card>> GetMeetingCardListAsync(CalendarSkillState state,
15221496
return eventItemList;
15231497
}
15241498

1525-
private int GetDurationFromEntity(CalendarLuis._Entities entity, string local)
1499+
private int GetDurationFromEntity(CalendarLuis._Entities entity, string local, TimeZoneInfo userTimeZone)
15261500
{
15271501
var culture = local ?? English;
1528-
var result = RecognizeDateTime(entity.Duration[0], culture);
1502+
var result = RecognizeDateTime(entity.Duration[0], culture, userTimeZone);
15291503
if (result != null)
15301504
{
15311505
if (result[0].Value != null)
@@ -1537,10 +1511,10 @@ private int GetDurationFromEntity(CalendarLuis._Entities entity, string local)
15371511
return -1;
15381512
}
15391513

1540-
private int GetMoveTimeSpanFromEntity(string timeSpan, string local, bool later)
1514+
private int GetMoveTimeSpanFromEntity(string timeSpan, string local, bool later, TimeZoneInfo userTimeZone)
15411515
{
15421516
var culture = local ?? English;
1543-
var result = RecognizeDateTime(timeSpan, culture);
1517+
var result = RecognizeDateTime(timeSpan, culture, userTimeZone);
15441518
if (result != null)
15451519
{
15461520
if (result[0].Value != null)
@@ -1577,7 +1551,7 @@ private string GetDateTimeStringFromInstanceData(string inputString, InstanceDat
15771551
private List<DateTime> GetDateFromDateTimeString(string date, string local, TimeZoneInfo userTimeZone, bool isStart = true)
15781552
{
15791553
var culture = local ?? English;
1580-
var results = RecognizeDateTime(date, culture, true);
1554+
var results = RecognizeDateTime(date, culture, userTimeZone, true);
15811555
var dateTimeResults = new List<DateTime>();
15821556
if (results != null)
15831557
{
@@ -1595,8 +1569,7 @@ private List<DateTime> GetDateFromDateTimeString(string date, string local, Time
15951569

15961570
if (dateTime != null)
15971571
{
1598-
var isRelativeTime = IsRelativeTime(date, result.Value, result.Timex);
1599-
dateTimeResults.Add(isRelativeTime ? TimeZoneInfo.ConvertTime(dateTime, TimeZoneInfo.Local, userTimeZone) : dateTime);
1572+
dateTimeResults.Add(dateTime);
16001573
}
16011574
}
16021575
else
@@ -1622,7 +1595,7 @@ private List<DateTime> GetTimeFromDateTimeString(string time, string local, Time
16221595
{
16231596
// if isStart is false, will only get the end time of a timerange
16241597
var culture = local ?? English;
1625-
var results = RecognizeDateTime(time, culture, false);
1598+
var results = RecognizeDateTime(time, culture, userTimeZone, false);
16261599
var dateTimeResults = new List<DateTime>();
16271600
if (results != null)
16281601
{
@@ -1640,8 +1613,7 @@ private List<DateTime> GetTimeFromDateTimeString(string time, string local, Time
16401613

16411614
if (dateTime != null)
16421615
{
1643-
var isRelativeTime = IsRelativeTime(time, result.Value, result.Timex);
1644-
dateTimeResults.Add(isRelativeTime ? TimeZoneInfo.ConvertTime(dateTime, TimeZoneInfo.Local, userTimeZone) : dateTime);
1616+
dateTimeResults.Add(dateTime);
16451617
}
16461618
}
16471619
else

skills/src/csharp/calendarskill/calendarskill/Dialogs/CreateEventDialog.cs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
using CalendarSkill.Models.DialogOptions;
99
using CalendarSkill.Options;
1010
using CalendarSkill.Prompts;
11+
using CalendarSkill.Prompts.Options;
1112
using CalendarSkill.Responses.CreateEvent;
1213
using CalendarSkill.Responses.Shared;
1314
using CalendarSkill.Services;
1415
using CalendarSkill.Utilities;
16+
using Google.Apis.People.v1.Data;
1517
using Microsoft.Bot.Builder;
1618
using Microsoft.Bot.Builder.Dialogs;
1719
using Microsoft.Bot.Builder.Skills;
@@ -670,10 +672,11 @@ public CreateEventDialog(
670672
return await sc.NextAsync(cancellationToken: cancellationToken);
671673
}
672674

673-
return await sc.PromptAsync(Actions.DatePromptForCreate, new PromptOptions
675+
return await sc.PromptAsync(Actions.DatePromptForCreate, new DatePromptOptions
674676
{
675677
Prompt = ResponseManager.GetResponse(CreateEventResponses.NoStartDate),
676678
RetryPrompt = ResponseManager.GetResponse(CreateEventResponses.NoStartDateRetry),
679+
TimeZone = state.GetUserTimeZone()
677680
}, cancellationToken);
678681
}
679682
catch (Exception ex)
@@ -718,25 +721,12 @@ public CreateEventDialog(
718721

719722
if (dateTime != null)
720723
{
721-
var isRelativeTime = IsRelativeTime(sc.Context.Activity.Text, dateTimeValue, dateTimeConvertType);
722724
if (CalendarCommonUtil.ContainsTime(dateTimeConvertType))
723725
{
724-
state.MeetingInfor.StartTime.Add(TimeZoneInfo.ConvertTime(dateTime, TimeZoneInfo.Local, state.GetUserTimeZone()));
726+
state.MeetingInfor.StartTime.Add(dateTime);
725727
}
726728

727-
// Workaround as DateTimePrompt only return as local time
728-
if (isRelativeTime)
729-
{
730-
dateTime = new DateTime(
731-
dateTime.Year,
732-
dateTime.Month,
733-
dateTime.Day,
734-
DateTime.Now.Hour,
735-
DateTime.Now.Minute,
736-
DateTime.Now.Second);
737-
}
738-
739-
state.MeetingInfor.StartDate.Add(isRelativeTime ? TimeZoneInfo.ConvertTime(dateTime, TimeZoneInfo.Local, state.GetUserTimeZone()) : dateTime);
729+
state.MeetingInfor.StartDate.Add(dateTime);
740730
}
741731
}
742732
catch (FormatException ex)
@@ -764,11 +754,12 @@ public CreateEventDialog(
764754
var state = await Accessor.GetAsync(sc.Context, cancellationToken: cancellationToken);
765755
if (!state.MeetingInfor.StartTime.Any())
766756
{
767-
return await sc.PromptAsync(Actions.TimePromptForCreate, new NoSkipPromptOptions
757+
return await sc.PromptAsync(Actions.TimePromptForCreate, new TimePromptOptions
768758
{
769759
Prompt = ResponseManager.GetResponse(CreateEventResponses.NoStartTime),
770760
RetryPrompt = ResponseManager.GetResponse(CreateEventResponses.NoStartTimeRetry),
771761
NoSkipPrompt = ResponseManager.GetResponse(CreateEventResponses.NoStartTimeNoSkip),
762+
TimeZone = state.GetUserTimeZone()
772763
}, cancellationToken);
773764
}
774765
else
@@ -803,8 +794,7 @@ public CreateEventDialog(
803794

804795
if (dateTime != null)
805796
{
806-
var isRelativeTime = IsRelativeTime(sc.Context.Activity.Text, dateTimeValue, dateTimeConvertType);
807-
state.MeetingInfor.StartTime.Add(isRelativeTime ? TimeZoneInfo.ConvertTime(dateTime, TimeZoneInfo.Local, state.GetUserTimeZone()) : dateTime);
797+
state.MeetingInfor.StartTime.Add(dateTime);
808798
}
809799
}
810800
catch (FormatException ex)

skills/src/csharp/calendarskill/calendarskill/Dialogs/UpdateEventDialog.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
using System.Threading.Tasks;
66
using CalendarSkill.Models;
77
using CalendarSkill.Models.DialogOptions;
8+
using CalendarSkill.Options;
9+
using CalendarSkill.Prompts;
810
using CalendarSkill.Prompts.Options;
911
using CalendarSkill.Responses.Shared;
1012
using CalendarSkill.Responses.UpdateEvent;
@@ -218,10 +220,11 @@ public UpdateEventDialog(
218220
return await sc.NextAsync();
219221
}
220222

221-
return await sc.PromptAsync(Actions.TimePrompt, new PromptOptions
223+
return await sc.PromptAsync(Actions.TimePrompt, new TimePromptOptions
222224
{
223225
Prompt = ResponseManager.GetResponse(UpdateEventResponses.NoNewTime),
224-
RetryPrompt = ResponseManager.GetResponse(UpdateEventResponses.NoNewTimeRetry)
226+
RetryPrompt = ResponseManager.GetResponse(UpdateEventResponses.NoNewTimeRetry),
227+
TimeZone = state.GetUserTimeZone()
225228
}, cancellationToken);
226229
}
227230
catch (Exception ex)
@@ -304,13 +307,6 @@ public UpdateEventDialog(
304307
continue;
305308
}
306309

307-
var isRelativeTime = IsRelativeTime(sc.Context.Activity.Text, resolution.Value, dateTimeConvertTypeString);
308-
if (isRelativeTime)
309-
{
310-
dateTimeValue = DateTime.SpecifyKind(dateTimeValue, DateTimeKind.Local);
311-
}
312-
313-
dateTimeValue = isRelativeTime ? TimeZoneInfo.ConvertTime(dateTimeValue, TimeZoneInfo.Local, state.GetUserTimeZone()) : dateTimeValue;
314310
var originalStartDateTime = TimeConverter.ConvertUtcToUserTime(state.ShowMeetingInfor.FocusedEvents[0].StartTime, state.GetUserTimeZone());
315311
if (dateTimeConvertType.Types.Contains(Constants.TimexTypes.Date) && !dateTimeConvertType.Types.Contains(Constants.TimexTypes.DateTime))
316312
{

skills/src/csharp/calendarskill/calendarskill/Prompts/DatePrompt.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Threading;
44
using System.Threading.Tasks;
5+
using CalendarSkill.Prompts.Options;
56
using CalendarSkill.Responses.Shared;
67
using CalendarSkill.Utilities;
78
using Microsoft.Bot.Builder;
@@ -14,6 +15,8 @@ namespace CalendarSkill.Prompts
1415
{
1516
public class DatePrompt : Prompt<IList<DateTimeResolution>>
1617
{
18+
private static TimeZoneInfo userTimeZone = null;
19+
1720
public DatePrompt(string dialogId, PromptValidator<IList<DateTimeResolution>> validator = null, string defaultLocale = null)
1821
: base(dialogId, validator)
1922
{
@@ -36,6 +39,11 @@ public DatePrompt(string dialogId, PromptValidator<IList<DateTimeResolution>> va
3639
throw new ArgumentNullException(nameof(options));
3740
}
3841

42+
if (!(options is DatePromptOptions))
43+
{
44+
throw new Exception(nameof(options) + " should be DatePromptOptions");
45+
}
46+
3947
if (isRetry && options.RetryPrompt != null)
4048
{
4149
await turnContext.SendActivityAsync(options.RetryPrompt, cancellationToken).ConfigureAwait(false);
@@ -44,6 +52,8 @@ public DatePrompt(string dialogId, PromptValidator<IList<DateTimeResolution>> va
4452
{
4553
await turnContext.SendActivityAsync(options.Prompt, cancellationToken).ConfigureAwait(false);
4654
}
55+
56+
userTimeZone = ((DatePromptOptions)options).TimeZone;
4757
}
4858

4959
protected override async Task<PromptRecognizerResult<IList<DateTimeResolution>>> OnRecognizeAsync(ITurnContext turnContext, IDictionary<string, object> state, PromptOptions options, CancellationToken cancellationToken = default(CancellationToken))
@@ -87,7 +97,8 @@ private IList<DateTimeResolution> GetDateFromMessage(string message, string cult
8797

8898
private List<DateTimeResolution> RecognizeDateTime(string dateTimeString, string culture)
8999
{
90-
var results = DateTimeRecognizer.RecognizeDateTime(DateTimeHelper.ConvertNumberToDateTimeString(dateTimeString, true), culture, options: DateTimeOptions.CalendarMode);
100+
var userNow = TimeConverter.ConvertUtcToUserTime(DateTime.UtcNow, userTimeZone);
101+
var results = DateTimeRecognizer.RecognizeDateTime(DateTimeHelper.ConvertNumberToDateTimeString(dateTimeString, true), culture, DateTimeOptions.CalendarMode, userNow);
91102
if (results.Count > 0)
92103
{
93104
// Return list of resolutions from first match

skills/src/csharp/calendarskill/calendarskill/Prompts/GetEventPrompt.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public GetEventPrompt(string dialogId, PromptValidator<IList<EventModel>> valida
7676
{
7777
var message = turnContext.Activity.AsMessageActivity();
7878
var culture = turnContext.Activity.Locale ?? DefaultLocale ?? English;
79-
var date = GetTimeFromMessage(message.Text, culture);
79+
var date = GetTimeFromMessage(message.Text, culture, userTimeZone);
8080
if (date.Count > 0)
8181
{
8282
// input is a time
@@ -172,14 +172,14 @@ private async Task<IList<EventModel>> GetEventsWithTitle(string title)
172172
return events;
173173
}
174174

175-
private IList<DateTimeResolution> GetTimeFromMessage(string message, string culture)
175+
private IList<DateTimeResolution> GetTimeFromMessage(string message, string culture, TimeZoneInfo userTimeZone)
176176
{
177-
IList<DateTimeResolution> results = RecognizeDateTime(message, culture);
177+
IList<DateTimeResolution> results = RecognizeDateTime(message, culture, userTimeZone);
178178

179179
return results;
180180
}
181181

182-
private List<DateTimeResolution> RecognizeDateTime(string dateTimeString, string culture)
182+
private List<DateTimeResolution> RecognizeDateTime(string dateTimeString, string culture, TimeZoneInfo userTimeZone)
183183
{
184184
var userNow = TimeConverter.ConvertUtcToUserTime(DateTime.UtcNow, userTimeZone);
185185
var results = DateTimeRecognizer.RecognizeDateTime(dateTimeString, culture, DateTimeOptions.CalendarMode, userNow);

0 commit comments

Comments
 (0)