0

In order to invoke various instance methods of goog.i18n.TimeZone, I've tried pretty good number of combinations of goog.require() and goog.inherits() but still didn't reach the goal. Please can someone let me know what should be the correct way to do that?

Already done with Google Closure Library documentations. So it would be helpful if a demonstration with "Example.js" is shown.

rds
  • 26,253
  • 19
  • 107
  • 134

1 Answers1

0

I've found one of the best ways to learn the closure library is to look at the unit tests with-in the library itself. If you haven't already done so, clone "https://github.com/google/closure-library/". You can then look in: "https://github.com/google/closure-library/blob/master/closure/goog/i18n/timezone_test.js". Look for any of the unit test methods in the test class that match your use-case. For example, simple time zone:

function testSimpleTimeZoneZero() { 
  var date = new Date(); 
  var simpleTimeZone = goog.i18n.TimeZone.createTimeZone(0); 
  assertEquals(0, simpleTimeZone.getOffset(date)); 
  assertEquals('GMT+00:00', simpleTimeZone.getGMTString(date)); 
  assertEquals('Etc/GMT', simpleTimeZone.getTimeZoneId()); 
  assertEquals('UTC', simpleTimeZone.getLongName(date)); 
  assertEquals('UTC', simpleTimeZone.getShortName(date)); 
  assertEquals('+0000', simpleTimeZone.getRFCTimeZoneString(date)); 
  assertEquals(false, simpleTimeZone.isDaylightTime(date)); 

}

The other aspect of the timezone class you must be aware of is that it required "data" to operate. from the documentation "https://google.github.io/closure-library/api/goog.i18n.TimeZone.html":

i18n.TimeZone Extends TimeZone class implemented a time zone resolution and name information source for client applications. The time zone object is initiated from a time zone information object. Application can initiate a time zone statically, or it may choose to initiate from a data obtained from server. Each time zone information array is small, but the whole set of data is too much for client application to download. If end user is allowed to change time zone setting, dynamic retrieval should be the method to use. In case only time zone offset is known, there is a decent fallback that only use the time zone offset to create a TimeZone object. A whole set of time zone information array was available under http://go/js_locale_data. It is generated based on CLDR/ICU and Olson time zone data base, and will be updated timely.

The unit test shows a mechanism to "load" this data statically (at the top of the file).

Biggert
  • 278
  • 4
  • 21
Grady G Cooper
  • 1,044
  • 8
  • 19