-
Notifications
You must be signed in to change notification settings - Fork 430
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -569,6 +569,30 @@ public static float ParseNumberFromDurationTimex(string timex) | |
return float.Parse(numberStr); | ||
} | ||
|
||
public static int ParseHourFromTimeTimex(string timex) | ||
{ | ||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @aitelint Please ACK this comment. Thanks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tellarin, issue created There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
int.TryParse(hourStr, out int hour); | ||
|
||
return hour; | ||
} | ||
|
||
public static Tuple<int, int> ParseHoursFromTimePeriodTimex(string timex) | ||
{ | ||
int hour1 = 0, hour2 = 0; | ||
var timeList = timex.Split(Constants.TimexSeparator[0]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same. |
||
if (timeList.Length > 2) | ||
{ | ||
hour1 = ParseHourFromTimeTimex(timeList[0]); | ||
hour2 = ParseHourFromTimeTimex(timeList[1]); | ||
} | ||
|
||
return new Tuple<int, int>(hour1, hour2); | ||
} | ||
|
||
private static bool IsTimeDurationTimex(string timex) | ||
{ | ||
return timex.StartsWith($"{Constants.GeneralPeriodPrefix}{Constants.TimeTimexPrefix}", StringComparison.Ordinal); | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done