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

Commit 3ffe738

Browse files
KayMKMlauren-mills
authored andcommitted
[Calendar] fix merge issue (#2370)
* merge timezone issue fix from master * fix error
1 parent 34877f7 commit 3ffe738

File tree

8 files changed

+40
-79
lines changed

8 files changed

+40
-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
@@ -901,7 +874,7 @@ protected async Task DigestCalendarLuisResult(DialogContext dc, CalendarLuis lui
901874

902875
if (entity.Duration != null)
903876
{
904-
var duration = GetDurationFromEntity(entity, dc.Context.Activity.Locale);
877+
var duration = GetDurationFromEntity(entity, dc.Context.Activity.Locale, state.GetUserTimeZone());
905878
if (duration != -1)
906879
{
907880
state.MeetingInfor.CreateHasDetail = true;
@@ -1047,12 +1020,12 @@ protected async Task DigestCalendarLuisResult(DialogContext dc, CalendarLuis lui
10471020

10481021
if (entity.MoveEarlierTimeSpan != null)
10491022
{
1050-
state.UpdateMeetingInfor.MoveTimeSpan = GetMoveTimeSpanFromEntity(entity.MoveEarlierTimeSpan[0], dc.Context.Activity.Locale, false);
1023+
state.UpdateMeetingInfor.MoveTimeSpan = GetMoveTimeSpanFromEntity(entity.MoveEarlierTimeSpan[0], dc.Context.Activity.Locale, false, state.GetUserTimeZone());
10511024
}
10521025

10531026
if (entity.MoveLaterTimeSpan != null)
10541027
{
1055-
state.UpdateMeetingInfor.MoveTimeSpan = GetMoveTimeSpanFromEntity(entity.MoveLaterTimeSpan[0], dc.Context.Activity.Locale, true);
1028+
state.UpdateMeetingInfor.MoveTimeSpan = GetMoveTimeSpanFromEntity(entity.MoveLaterTimeSpan[0], dc.Context.Activity.Locale, true, state.GetUserTimeZone());
10561029
}
10571030

10581031
if (entity.datetime != null)
@@ -1159,9 +1132,10 @@ protected async Task DigestCalendarLuisResult(DialogContext dc, CalendarLuis lui
11591132
}
11601133
}
11611134

1162-
protected List<DateTimeResolution> RecognizeDateTime(string dateTimeString, string culture, bool convertToDate = true)
1135+
protected List<DateTimeResolution> RecognizeDateTime(string dateTimeString, string culture, TimeZoneInfo userTimeZone, bool convertToDate = true)
11631136
{
1164-
var results = DateTimeRecognizer.RecognizeDateTime(DateTimeHelper.ConvertNumberToDateTimeString(dateTimeString, convertToDate), culture, options: DateTimeOptions.CalendarMode);
1137+
var userNow = TimeConverter.ConvertUtcToUserTime(DateTime.UtcNow, userTimeZone);
1138+
var results = DateTimeRecognizer.RecognizeDateTime(DateTimeHelper.ConvertNumberToDateTimeString(dateTimeString, convertToDate), culture, DateTimeOptions.CalendarMode, userNow);
11651139

11661140
if (results.Count > 0)
11671141
{
@@ -1529,10 +1503,10 @@ private async Task<List<Card>> GetMeetingCardListAsync(CalendarSkillState state,
15291503
return eventItemList;
15301504
}
15311505

1532-
private int GetDurationFromEntity(CalendarLuis._Entities entity, string local)
1506+
private int GetDurationFromEntity(CalendarLuis._Entities entity, string local, TimeZoneInfo userTimeZone)
15331507
{
15341508
var culture = local ?? English;
1535-
var result = RecognizeDateTime(entity.Duration[0], culture);
1509+
var result = RecognizeDateTime(entity.Duration[0], culture, userTimeZone);
15361510
if (result != null)
15371511
{
15381512
if (result[0].Value != null)
@@ -1544,10 +1518,10 @@ private int GetDurationFromEntity(CalendarLuis._Entities entity, string local)
15441518
return -1;
15451519
}
15461520

1547-
private int GetMoveTimeSpanFromEntity(string timeSpan, string local, bool later)
1521+
private int GetMoveTimeSpanFromEntity(string timeSpan, string local, bool later, TimeZoneInfo userTimeZone)
15481522
{
15491523
var culture = local ?? English;
1550-
var result = RecognizeDateTime(timeSpan, culture);
1524+
var result = RecognizeDateTime(timeSpan, culture, userTimeZone);
15511525
if (result != null)
15521526
{
15531527
if (result[0].Value != null)
@@ -1585,7 +1559,7 @@ private List<DateTime> GetDateFromDateTimeString(string date, string local, Time
15851559
{
15861560
// if isTargetTimeRange is true, will only parse the time range
15871561
var culture = local ?? English;
1588-
var results = RecognizeDateTime(date, culture, true);
1562+
var results = RecognizeDateTime(date, culture, userTimeZone, true);
15891563
var dateTimeResults = new List<DateTime>();
15901564
if (results != null)
15911565
{
@@ -1603,8 +1577,7 @@ private List<DateTime> GetDateFromDateTimeString(string date, string local, Time
16031577

16041578
if (dateTime != null)
16051579
{
1606-
var isRelativeTime = IsRelativeTime(date, result.Value, result.Timex);
1607-
dateTimeResults.Add(isRelativeTime ? TimeZoneInfo.ConvertTime(dateTime, TimeZoneInfo.Local, userTimeZone) : dateTime);
1580+
dateTimeResults.Add(dateTime);
16081581
}
16091582
}
16101583
else
@@ -1630,7 +1603,7 @@ private List<DateTime> GetTimeFromDateTimeString(string time, string local, Time
16301603
{
16311604
// if isTargetTimeRange is true, will only parse the time range
16321605
var culture = local ?? English;
1633-
var results = RecognizeDateTime(time, culture, false);
1606+
var results = RecognizeDateTime(time, culture, userTimeZone, false);
16341607
var dateTimeResults = new List<DateTime>();
16351608
if (results != null)
16361609
{
@@ -1648,8 +1621,7 @@ private List<DateTime> GetTimeFromDateTimeString(string time, string local, Time
16481621

16491622
if (dateTime != null)
16501623
{
1651-
var isRelativeTime = IsRelativeTime(time, result.Value, result.Timex);
1652-
dateTimeResults.Add(isRelativeTime ? TimeZoneInfo.ConvertTime(dateTime, TimeZoneInfo.Local, userTimeZone) : dateTime);
1624+
dateTimeResults.Add(dateTime);
16531625
}
16541626
}
16551627
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public DatePrompt(string dialogId, PromptValidator<IList<DateTimeResolution>> va
4141

4242
if (!(options is DatePromptOptions))
4343
{
44-
throw new Exception(nameof(options) + " should be GetEventOptions");
44+
throw new Exception(nameof(options) + " should be DatePromptOptions");
4545
}
4646

4747
if (isRetry && options.RetryPrompt != null)

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);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public TimePrompt(string dialogId, PromptValidator<IList<DateTimeResolution>> va
3838

3939
if (!(options is TimePromptOptions))
4040
{
41-
throw new Exception(nameof(options) + " should be GetEventOptions");
41+
throw new Exception(nameof(options) + " should be TimePromptOptions");
4242
}
4343

4444
if (isRetry && options.RetryPrompt != null)

skills/src/csharp/calendarskill/calendarskilltest/Prompt/DatePromptTests.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using System.Threading;
54
using System.Threading.Tasks;
5+
using CalendarSkill.Models;
66
using CalendarSkill.Prompts;
77
using CalendarSkill.Prompts.Options;
8+
using CalendarSkillTest.Flow.Fakes;
9+
using Microsoft.Bot.Builder;
810
using Microsoft.Bot.Builder.Adapters;
11+
using Microsoft.Bot.Builder.Dialogs;
912
using Microsoft.Bot.Schema;
1013
using Microsoft.Recognizers.Text;
1114
using Microsoft.VisualStudio.TestTools.UnitTesting;
1215

13-
namespace Microsoft.Bot.Builder.Dialogs.Tests
16+
namespace CalendarSkillTest.Prompt
1417
{
1518
[TestClass]
1619
public class DatePromptTests

0 commit comments

Comments
 (0)