Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

info.js 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. import DateTime from "./datetime.js";
  2. import Settings from "./settings.js";
  3. import Locale from "./impl/locale.js";
  4. import IANAZone from "./zones/IANAZone.js";
  5. import { normalizeZone } from "./impl/zoneUtil.js";
  6. import { hasFormatToParts, hasIntl, hasRelative } from "./impl/util.js";
  7. /**
  8. * The Info class contains static methods for retrieving general time and date related data. For example, it has methods for finding out if a time zone has a DST, for listing the months in any supported locale, and for discovering which of Luxon features are available in the current environment.
  9. */
  10. export default class Info {
  11. /**
  12. * Return whether the specified zone contains a DST.
  13. * @param {string|Zone} [zone='local'] - Zone to check. Defaults to the environment's local zone.
  14. * @return {boolean}
  15. */
  16. static hasDST(zone = Settings.defaultZone) {
  17. const proto = DateTime.now()
  18. .setZone(zone)
  19. .set({ month: 12 });
  20. return !zone.universal && proto.offset !== proto.set({ month: 6 }).offset;
  21. }
  22. /**
  23. * Return whether the specified zone is a valid IANA specifier.
  24. * @param {string} zone - Zone to check
  25. * @return {boolean}
  26. */
  27. static isValidIANAZone(zone) {
  28. return IANAZone.isValidSpecifier(zone) && IANAZone.isValidZone(zone);
  29. }
  30. /**
  31. * Converts the input into a {@link Zone} instance.
  32. *
  33. * * If `input` is already a Zone instance, it is returned unchanged.
  34. * * If `input` is a string containing a valid time zone name, a Zone instance
  35. * with that name is returned.
  36. * * If `input` is a string that doesn't refer to a known time zone, a Zone
  37. * instance with {@link Zone.isValid} == false is returned.
  38. * * If `input is a number, a Zone instance with the specified fixed offset
  39. * in minutes is returned.
  40. * * If `input` is `null` or `undefined`, the default zone is returned.
  41. * @param {string|Zone|number} [input] - the value to be converted
  42. * @return {Zone}
  43. */
  44. static normalizeZone(input) {
  45. return normalizeZone(input, Settings.defaultZone);
  46. }
  47. /**
  48. * Return an array of standalone month names.
  49. * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
  50. * @param {string} [length='long'] - the length of the month representation, such as "numeric", "2-digit", "narrow", "short", "long"
  51. * @param {Object} opts - options
  52. * @param {string} [opts.locale] - the locale code
  53. * @param {string} [opts.numberingSystem=null] - the numbering system
  54. * @param {string} [opts.locObj=null] - an existing locale object to use
  55. * @param {string} [opts.outputCalendar='gregory'] - the calendar
  56. * @example Info.months()[0] //=> 'January'
  57. * @example Info.months('short')[0] //=> 'Jan'
  58. * @example Info.months('numeric')[0] //=> '1'
  59. * @example Info.months('short', { locale: 'fr-CA' } )[0] //=> 'janv.'
  60. * @example Info.months('numeric', { locale: 'ar' })[0] //=> '١'
  61. * @example Info.months('long', { outputCalendar: 'islamic' })[0] //=> 'Rabiʻ I'
  62. * @return {[string]}
  63. */
  64. static months(
  65. length = "long",
  66. { locale = null, numberingSystem = null, locObj = null, outputCalendar = "gregory" } = {}
  67. ) {
  68. return (locObj || Locale.create(locale, numberingSystem, outputCalendar)).months(length);
  69. }
  70. /**
  71. * Return an array of format month names.
  72. * Format months differ from standalone months in that they're meant to appear next to the day of the month. In some languages, that
  73. * changes the string.
  74. * See {@link months}
  75. * @param {string} [length='long'] - the length of the month representation, such as "numeric", "2-digit", "narrow", "short", "long"
  76. * @param {Object} opts - options
  77. * @param {string} [opts.locale] - the locale code
  78. * @param {string} [opts.numberingSystem=null] - the numbering system
  79. * @param {string} [opts.locObj=null] - an existing locale object to use
  80. * @param {string} [opts.outputCalendar='gregory'] - the calendar
  81. * @return {[string]}
  82. */
  83. static monthsFormat(
  84. length = "long",
  85. { locale = null, numberingSystem = null, locObj = null, outputCalendar = "gregory" } = {}
  86. ) {
  87. return (locObj || Locale.create(locale, numberingSystem, outputCalendar)).months(length, true);
  88. }
  89. /**
  90. * Return an array of standalone week names.
  91. * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
  92. * @param {string} [length='long'] - the length of the weekday representation, such as "narrow", "short", "long".
  93. * @param {Object} opts - options
  94. * @param {string} [opts.locale] - the locale code
  95. * @param {string} [opts.numberingSystem=null] - the numbering system
  96. * @param {string} [opts.locObj=null] - an existing locale object to use
  97. * @example Info.weekdays()[0] //=> 'Monday'
  98. * @example Info.weekdays('short')[0] //=> 'Mon'
  99. * @example Info.weekdays('short', { locale: 'fr-CA' })[0] //=> 'lun.'
  100. * @example Info.weekdays('short', { locale: 'ar' })[0] //=> 'الاثنين'
  101. * @return {[string]}
  102. */
  103. static weekdays(length = "long", { locale = null, numberingSystem = null, locObj = null } = {}) {
  104. return (locObj || Locale.create(locale, numberingSystem, null)).weekdays(length);
  105. }
  106. /**
  107. * Return an array of format week names.
  108. * Format weekdays differ from standalone weekdays in that they're meant to appear next to more date information. In some languages, that
  109. * changes the string.
  110. * See {@link weekdays}
  111. * @param {string} [length='long'] - the length of the weekday representation, such as "narrow", "short", "long".
  112. * @param {Object} opts - options
  113. * @param {string} [opts.locale=null] - the locale code
  114. * @param {string} [opts.numberingSystem=null] - the numbering system
  115. * @param {string} [opts.locObj=null] - an existing locale object to use
  116. * @return {[string]}
  117. */
  118. static weekdaysFormat(
  119. length = "long",
  120. { locale = null, numberingSystem = null, locObj = null } = {}
  121. ) {
  122. return (locObj || Locale.create(locale, numberingSystem, null)).weekdays(length, true);
  123. }
  124. /**
  125. * Return an array of meridiems.
  126. * @param {Object} opts - options
  127. * @param {string} [opts.locale] - the locale code
  128. * @example Info.meridiems() //=> [ 'AM', 'PM' ]
  129. * @example Info.meridiems({ locale: 'my' }) //=> [ 'နံနက်', 'ညနေ' ]
  130. * @return {[string]}
  131. */
  132. static meridiems({ locale = null } = {}) {
  133. return Locale.create(locale).meridiems();
  134. }
  135. /**
  136. * Return an array of eras, such as ['BC', 'AD']. The locale can be specified, but the calendar system is always Gregorian.
  137. * @param {string} [length='short'] - the length of the era representation, such as "short" or "long".
  138. * @param {Object} opts - options
  139. * @param {string} [opts.locale] - the locale code
  140. * @example Info.eras() //=> [ 'BC', 'AD' ]
  141. * @example Info.eras('long') //=> [ 'Before Christ', 'Anno Domini' ]
  142. * @example Info.eras('long', { locale: 'fr' }) //=> [ 'avant Jésus-Christ', 'après Jésus-Christ' ]
  143. * @return {[string]}
  144. */
  145. static eras(length = "short", { locale = null } = {}) {
  146. return Locale.create(locale, null, "gregory").eras(length);
  147. }
  148. /**
  149. * Return the set of available features in this environment.
  150. * Some features of Luxon are not available in all environments. For example, on older browsers, timezone support is not available. Use this function to figure out if that's the case.
  151. * Keys:
  152. * * `zones`: whether this environment supports IANA timezones
  153. * * `intlTokens`: whether this environment supports internationalized token-based formatting/parsing
  154. * * `intl`: whether this environment supports general internationalization
  155. * * `relative`: whether this environment supports relative time formatting
  156. * @example Info.features() //=> { intl: true, intlTokens: false, zones: true, relative: false }
  157. * @return {Object}
  158. */
  159. static features() {
  160. let intl = false,
  161. intlTokens = false,
  162. zones = false,
  163. relative = false;
  164. if (hasIntl()) {
  165. intl = true;
  166. intlTokens = hasFormatToParts();
  167. relative = hasRelative();
  168. try {
  169. zones =
  170. new Intl.DateTimeFormat("en", { timeZone: "America/New_York" }).resolvedOptions()
  171. .timeZone === "America/New_York";
  172. } catch (e) {
  173. zones = false;
  174. }
  175. }
  176. return { intl, intlTokens, zones, relative };
  177. }
  178. }