Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JA DateTimeV2] Merged refinements #2950

Merged
merged 3 commits into from
May 16, 2022
Merged

Conversation

aitelint
Copy link
Contributor

@aitelint aitelint commented May 13, 2022

All test cases pass.

Added support for the 30-hour clock form (commonly used in Japanese) and relative test cases in DateTimeParser, DateTimePeriodParser, MergedParser, TimeParser and TimePeriodParser.

Modified test cases:
In DateParser:

  • "私は今から2週間以内に戻ります" (I will be back within 2 weeks from now), moved to DatePeriodParser and replaced with "私は今から2週間でに戻ります" (I will be back in 2 weeks from now).

In MergedExtractor:

  • "これは2日です。" (This is 2 days), modified type from Duration to Date because it is more commonly interpreted as 2nd day of the month. Added new test case "これは2日間です。" which unambiguously indicates a duration.
  • "午前10時の予定を4.3時に変更します。" -> "午前10時の予定を4.3に変更します。" (I'll change the ten am appointment to 4.3), "4.3時" (4.3 o'clock) was used which is not a valid time expression in Japanese. Modified to remove "o'clock" (時).
  • Added extraction of time entities when missing:
    • "午前10時の予定を26時に変更します。" (I'll change the 10am appointment to 26 o'clock), 26時 is extracted (valid time in Japanese).
    • "午前10時の予定を25時に変更します。" (I'll change the 10am appointment to 25 o'clock), 25時 is extracted (valid time in Japanese).
    • "午前10時の予定を4時以降に変更します。" (I'll change the ten am appointment to 4 or later), "4時" (4 o'clock) is used which is extracted. Added new test case "午前10時の予定を4以降に変更します。" where "4" is not extracted.

swiftDay++;
}

var pastDate1 = pastDate.AddDays(swiftDay);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename to pastDateAlt as it's an alternative resolution?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Collaborator

@tellarin tellarin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly good. One minor comment and a request for future code for perf.

var start = timex.IndexOf(Constants.TimeTimexPrefix) + 1;
var end = timex.IndexOf(Constants.TimeTimexConnector);
end = end > 0 ? end : timex.Length;
var hourStr = timex.Substring(start, end - start);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From now on, let's try to write such functions using Spans, to avoid creating a lot of small string objects garbage collected all the time. Please open an issue to refactor existing Timex parsing code to do the same.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aitelint Please ACK this comment. Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tellarin, issue created

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tellarin, the problem is that net462 does not support parsing of spans, so we would need to convert the span back to string when passing it to int.TryParse

public static Tuple<int, int> ParseHoursFromTimePeriodTimex(string timex)
{
int hour1 = 0, hour2 = 0;
var timeList = timex.Split(Constants.TimexSeparator[0]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

@tellarin tellarin merged commit 8c899a7 into microsoft:master May 16, 2022
@aitelint aitelint deleted the Japanese_Merged branch May 16, 2022 03:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants