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

Add TimeZone class #108

Merged
merged 6 commits into from
Mar 15, 2019
Merged

Add TimeZone class #108

merged 6 commits into from
Mar 15, 2019

Conversation

j-troc
Copy link

@j-troc j-troc commented Jan 14, 2019

This change is Reviewable

@j-troc
Copy link
Author

j-troc commented Jan 17, 2019

Could you share test failure details? Link is inaccessible.

@ermshiperete
Copy link
Member

Thanks for your contribution!

Sorry, I had intended to share the failed test, but didn't get around yet. Anyway, here it is:

Error Message

  Expected: 632
  But was:  621

Stacktrace

  at Icu.Tests.TimeZoneTests.GetTimeZonesTest () [0x00016] in <0ce791bf19c64c649fd393bc30a4276c>:0 

That's running the tests on Ubuntu 18.04; the tests succeed on Windows. I haven't looked yet if this is caused by Linux/Windows difference, or if it is caused by using a different ICU version.

@j-troc
Copy link
Author

j-troc commented Jan 18, 2019

I changed the test because number of timezones varies depending on ICU version.

Copy link

@wiertel wiertel left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r2.
Reviewable status: 1 of 4 files reviewed, 4 unresolved discussions (waiting on @j-troc)


source/icu.net/Timezone/Timezone.cs, line 15 at r2 (raw file):

		public string ID => zoneID;

		public TimeZone(string id)

missing documentation


source/icu.net/Timezone/Timezone.cs, line 37 at r2 (raw file):

			{
				string str = en.Next();
				while (str != null)

this List building from SafeEnumeratorHandle is used couple times, is there a utility method doing exactly that, maybe put this code into private method?


source/icu.net/Timezone/Timezone.cs, line 51 at r2 (raw file):

		/// <summary>
		/// Returns an enumeration over system TimeZones with the given filter conditions. 

space at the end of the line


source/icu.net/Timezone/USystemTimeZoneType.cs, line 4 at r2 (raw file):

using System.Collections.Generic;
using System.Linq;
using System.Text;

none of these namespaces is used

Copy link

@wiertel wiertel left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 4 files at r1.
Reviewable status: 2 of 4 files reviewed, 4 unresolved discussions (waiting on @j-troc)

Copy link

@wiertel wiertel left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 4 files at r1.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @j-troc)

@j-troc
Copy link
Author

j-troc commented Feb 1, 2019

These changes build on my machine. What is the build error?

@ermshiperete
Copy link
Member

Sorry, I was travelling. There was a hick-up on the server. I restarted the build and now it passed.

@j-troc
Copy link
Author

j-troc commented Mar 13, 2019

Does the code need changes?

Copy link
Member

@ermshiperete ermshiperete left a comment

Choose a reason for hiding this comment

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

Reviewed 4 of 4 files at r3.
Reviewable status: all files reviewed, 15 unresolved discussions (waiting on @j-troc)


source/icu.net/Timezone/Timezone.cs, line 14 at r3 (raw file):

		/// Returns TimeZone's ID.
		/// </summary>
		public string ID => zoneID;

I think I'd prefer to rename this to Id (lowercase d)


source/icu.net/Timezone/Timezone.cs, line 17 at r3 (raw file):

ID

nitpick: replace ID with <paramref name="id"/>


source/icu.net/Timezone/Timezone.cs, line 19 at r3 (raw file):

"id">IDthe

nitpick: Remove "ID" and tab character after it.


source/icu.net/Timezone/Timezone.cs, line 79 at r3 (raw file):

		}

		private static List<TimeZone> CreateTimeZoneList(Func<Tuple<SafeEnumeratorHandle, ErrorCode>> enumeratorSource)

This method could return IEnumerable<TimeZone> as well.


source/icu.net/Timezone/Timezone.cs, line 83 at r3 (raw file):

			List<TimeZone> timeZones = new List<TimeZone>();

			(SafeEnumeratorHandle en, ErrorCode ec) = enumeratorSource();

Please rename the variable names to something a bit less cryptic, e.g. enumerator and errorCode.


source/icu.net/Timezone/Timezone.cs, line 87 at r3 (raw file):

			try
			{
				string str = en.Next();

Rename to something less cryptic, e.g. timezoneId


source/icu.net/Timezone/Timezone.cs, line 109 at r3 (raw file):

			var timeZoneName = NativeMethods.GetUnicodeString((ptr, length) =>
			{
				length = NativeMethods.ucal_getDefaultTimeZone(ptr, length, out ErrorCode err);

Shouldn't we check the error code? I.e. add the line ExceptionFromErrorCode.ThrowIfError(ec) ?


source/icu.net/Timezone/Timezone.cs, line 159 at r3 (raw file):

			return NativeMethods.GetUnicodeString((ptr, length) =>
			{
				length = NativeMethods.ucal_getWindowsTimeZoneId(id, ptr, length, out ErrorCode err);

Shouldn't we check the error code? I.e. add the line ExceptionFromErrorCode.ThrowIfError(ec) ?


source/icu.net/Timezone/Timezone.cs, line 176 at r3 (raw file):

			return NativeMethods.GetUnicodeString((ptr, length) =>
			{
				length = NativeMethods.ucal_getTimeZoneIDForWindowsId(winId, region, ptr, length, out ErrorCode err);

Shouldn't we check the error code? I.e. add the line ExceptionFromErrorCode.ThrowIfError(ec) ?


source/icu.net.tests/TimeZoneTests.cs, line 71 at r3 (raw file):

			Assert.GreaterOrEqual(timezones.Count(), 4);
			Assert.AreEqual(1, timezones.Count(tz => tz.ID == "Atlantic/Azores"));
			Assert.AreEqual(1, timezones.Count(tz => tz.ID == "America/Scoresbysund"));

It might make sense to check the other two zones as well.


source/icu.net.tests/TimeZoneTests.cs, line 78 at r3 (raw file):

		{
			var expected = new TimeZone("AST");
			TimeZone.SetDefault(expected);

This test is identical to DefaultTimeoneTest() above. You could change it to use the .NET TimeZoneInfo class for getting the expected timezone:

var expected = TimeZoneInfo.Local;

Copy link
Member

@ermshiperete ermshiperete left a comment

Choose a reason for hiding this comment

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

Thanks for the reminder. A few small suggestions.

Reviewable status: all files reviewed, 15 unresolved discussions (waiting on @j-troc)

Copy link
Author

@j-troc j-troc left a comment

Choose a reason for hiding this comment

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

Reviewable status: 2 of 4 files reviewed, 11 unresolved discussions (waiting on @ermshiperete and @wiertel)


source/icu.net/Timezone/Timezone.cs, line 15 at r2 (raw file):

Previously, wiertel (Piotr Szydełko) wrote…

missing documentation

Done.


source/icu.net/Timezone/Timezone.cs, line 37 at r2 (raw file):

Previously, wiertel (Piotr Szydełko) wrote…

this List building from SafeEnumeratorHandle is used couple times, is there a utility method doing exactly that, maybe put this code into private method?

Done.


source/icu.net/Timezone/Timezone.cs, line 51 at r2 (raw file):

Previously, wiertel (Piotr Szydełko) wrote…

space at the end of the line

Done.


source/icu.net/Timezone/Timezone.cs, line 14 at r3 (raw file):

Previously, ermshiperete (Eberhard Beilharz) wrote…

I think I'd prefer to rename this to Id (lowercase d)

Done.


source/icu.net/Timezone/Timezone.cs, line 79 at r3 (raw file):

Previously, ermshiperete (Eberhard Beilharz) wrote…

This method could return IEnumerable<TimeZone> as well.

Done.


source/icu.net/Timezone/Timezone.cs, line 109 at r3 (raw file):

Previously, ermshiperete (Eberhard Beilharz) wrote…

Shouldn't we check the error code? I.e. add the line ExceptionFromErrorCode.ThrowIfError(ec) ?

Errors are chcecked inside GetUnicodeString method so there's no need to duplicate that.


source/icu.net/Timezone/Timezone.cs, line 159 at r3 (raw file):

Previously, ermshiperete (Eberhard Beilharz) wrote…

Shouldn't we check the error code? I.e. add the line ExceptionFromErrorCode.ThrowIfError(ec) ?

Errors are chcecked inside GetUnicodeString method so there's no need to duplicate that.


source/icu.net/Timezone/Timezone.cs, line 176 at r3 (raw file):

Previously, ermshiperete (Eberhard Beilharz) wrote…

Shouldn't we check the error code? I.e. add the line ExceptionFromErrorCode.ThrowIfError(ec) ?

Errors are chcecked inside GetUnicodeString method so there's no need to duplicate that.


source/icu.net/Timezone/USystemTimeZoneType.cs, line 4 at r2 (raw file):

Previously, wiertel (Piotr Szydełko) wrote…

none of these namespaces is used

Done.


source/icu.net.tests/TimeZoneTests.cs, line 71 at r3 (raw file):

Previously, ermshiperete (Eberhard Beilharz) wrote…

It might make sense to check the other two zones as well.

Done.


source/icu.net.tests/TimeZoneTests.cs, line 78 at r3 (raw file):

Previously, ermshiperete (Eberhard Beilharz) wrote…

This test is identical to DefaultTimeoneTest() above. You could change it to use the .NET TimeZoneInfo class for getting the expected timezone:

var expected = TimeZoneInfo.Local;

Value returned by TimeZoneInfo.Local will be different based on

Copy link
Member

@ermshiperete ermshiperete left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 2 of 2 files at r4.
Dismissed @wiertel from 4 discussions.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

Copy link
Member

@ermshiperete ermshiperete left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r5.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

Copy link
Member

@ermshiperete ermshiperete left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@ermshiperete ermshiperete merged commit 2e74ff2 into sillsdev:master Mar 15, 2019
@ermshiperete
Copy link
Member

Thanks @j-troc !

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.

3 participants