.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.weather.DateTime Class Reference

Public Member Functions

 __init__ (self, datetime.datetime time)
 __str__ (self)
str l10n (self, DateTimeFormats|str fmt="medium", DateTimeLocaleTypes|babel.Locale|GeoLocation|None locale=None)
str l10n_date (self, DateTimeFormats|str fmt="medium", DateTimeLocaleTypes|babel.Locale|GeoLocation|None locale=None)

Public Attributes

 datetime = time

Detailed Description

Class to represent date & time.  Essentially, it is a wrapper that
conveniently combines :py:obj:`datetime.datetime` and
:py:obj:`babel.dates.format_datetime`.  A conversion of time zones is not
provided (in the current version).

The localized string representation can be obtained via the
:py:obj:`DateTime.l10n` and :py:obj:`DateTime.l10n_date` methods, where the
``locale`` parameter defaults to the search language.  Alternatively, a
:py:obj:`GeoLocation` or a :py:obj:`babel.Locale` instance can be passed
directly. If the UI language is to be used, the string ``UI`` can be passed
as the value for the ``locale``.

Definition at line 205 of file weather.py.

Constructor & Destructor Documentation

◆ __init__()

searx.weather.DateTime.__init__ ( self,
datetime.datetime time )

Definition at line 219 of file weather.py.

219 def __init__(self, time: datetime.datetime):
220 self.datetime = time
221

Member Function Documentation

◆ __str__()

searx.weather.DateTime.__str__ ( self)

Definition at line 222 of file weather.py.

222 def __str__(self):
223 return self.l10n()
224

References l10n().

Here is the call graph for this function:

◆ l10n()

str searx.weather.DateTime.l10n ( self,
DateTimeFormats | str fmt = "medium",
DateTimeLocaleTypes | babel.Locale | GeoLocation | None locale = None )
Localized representation of date & time.

Definition at line 225 of file weather.py.

229 ) -> str:
230 """Localized representation of date & time."""
231 if isinstance(locale, str) and locale == "UI":
232 locale = flask_babel.get_locale()
233 elif isinstance(locale, GeoLocation):
234 locale = locale.locale()
235 elif locale is None:
236 locale = babel.Locale.parse(_get_sxng_locale_tag(), sep='-')
237 return babel.dates.format_datetime(self.datetime, format=fmt, locale=locale)
238

References searx.weather._get_sxng_locale_tag(), searx.result_types.answer.WeatherAnswer.Item.datetime, and datetime.

Referenced by searx.weather.Compass.__str__(), __str__(), searx.weather.Pressure.__str__(), searx.weather.RelativeHumidity.__str__(), searx.weather.Temperature.__str__(), and searx.weather.WindSpeed.__str__().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ l10n_date()

str searx.weather.DateTime.l10n_date ( self,
DateTimeFormats | str fmt = "medium",
DateTimeLocaleTypes | babel.Locale | GeoLocation | None locale = None )
Localized representation of date.

Definition at line 239 of file weather.py.

243 ) -> str:
244 """Localized representation of date."""
245
246 if isinstance(locale, str) and locale == "UI":
247 locale = flask_babel.get_locale()
248 elif isinstance(locale, GeoLocation):
249 locale = locale.locale()
250 elif locale is None:
251 locale = babel.Locale.parse(_get_sxng_locale_tag(), sep='-')
252 return babel.dates.format_date(self.datetime, format=fmt, locale=locale)
253
254
255@typing.final

References searx.weather._get_sxng_locale_tag(), searx.result_types.answer.WeatherAnswer.Item.datetime, and datetime.

Here is the call graph for this function:

Member Data Documentation

◆ datetime

searx.weather.DateTime.datetime = time

Definition at line 220 of file weather.py.

Referenced by l10n(), and l10n_date().


The documentation for this class was generated from the following file:
  • /home/andrew/Documents/code/public/searxng/searx/weather.py