2020-11-22 20:17:57 +01:00
|
|
|
import traceback
|
|
|
|
from typing import Optional
|
|
|
|
|
2021-03-03 10:47:52 +01:00
|
|
|
from cpl.configuration.configuration_model_abc import ConfigurationModelABC
|
|
|
|
from cpl.console.console import Console
|
2021-03-12 16:06:30 +01:00
|
|
|
from cpl.console.foreground_color_enum import ForegroundColorEnum
|
|
|
|
from cpl.time.time_format_settings_names_enum import TimeFormatSettingsNamesEnum
|
2020-11-22 20:17:57 +01:00
|
|
|
|
|
|
|
|
2021-03-03 10:47:52 +01:00
|
|
|
class TimeFormatSettings(ConfigurationModelABC):
|
2020-11-22 20:17:57 +01:00
|
|
|
|
|
|
|
def __init__(self):
|
2021-03-03 10:47:52 +01:00
|
|
|
ConfigurationModelABC.__init__(self)
|
2020-11-22 20:17:57 +01:00
|
|
|
self._date_format: Optional[str] = None
|
|
|
|
self._time_format: Optional[str] = None
|
|
|
|
self._date_time_format: Optional[str] = None
|
|
|
|
self._date_time_log_format: Optional[str] = None
|
|
|
|
|
|
|
|
@property
|
|
|
|
def date_format(self) -> str:
|
|
|
|
return self._date_format
|
|
|
|
|
|
|
|
@date_format.setter
|
|
|
|
def date_format(self, date_format: str) -> None:
|
|
|
|
self._date_format = date_format
|
|
|
|
|
|
|
|
@property
|
|
|
|
def time_format(self) -> str:
|
|
|
|
return self._time_format
|
|
|
|
|
|
|
|
@time_format.setter
|
|
|
|
def time_format(self, time_format: str):
|
|
|
|
self._time_format = time_format
|
|
|
|
|
|
|
|
@property
|
|
|
|
def date_time_format(self) -> str:
|
|
|
|
return self._date_time_format
|
|
|
|
|
|
|
|
@date_time_format.setter
|
|
|
|
def date_time_format(self, date_time_format: str) -> None:
|
|
|
|
self._date_time_format = date_time_format
|
|
|
|
|
|
|
|
@property
|
|
|
|
def date_time_log_format(self):
|
|
|
|
return self._date_time_log_format
|
|
|
|
|
|
|
|
@date_time_log_format.setter
|
|
|
|
def date_time_log_format(self, date_time_now_format: str) -> None:
|
|
|
|
self._date_time_log_format = date_time_now_format
|
|
|
|
|
|
|
|
def from_dict(self, settings: dict):
|
|
|
|
try:
|
2021-03-12 16:06:30 +01:00
|
|
|
self._date_format = settings[TimeFormatSettingsNamesEnum.date_format.value]
|
|
|
|
self._time_format = settings[TimeFormatSettingsNamesEnum.time_format.value]
|
|
|
|
self._date_time_format = settings[TimeFormatSettingsNamesEnum.date_time_format.value]
|
|
|
|
self._date_time_log_format = settings[TimeFormatSettingsNamesEnum.date_time_log_format.value]
|
2020-11-22 20:17:57 +01:00
|
|
|
except Exception as e:
|
2021-03-12 16:06:30 +01:00
|
|
|
Console.set_foreground_color(ForegroundColorEnum.red)
|
2020-11-28 15:13:54 +01:00
|
|
|
Console.write_line(f'[ ERROR ] [ {__name__} ]: Reading error in {self.__name__} settings')
|
2020-12-14 21:10:26 +01:00
|
|
|
Console.write_line(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
|
2021-03-12 16:06:30 +01:00
|
|
|
Console.set_foreground_color(ForegroundColorEnum.default)
|