Coverage for packages/azericard/src/integrify/azericard/utils.py: 88%
13 statements
« prev ^ index » next coverage.py v7.16.0, created at 2026-10-19 02:39 +0000
« prev ^ index » next coverage.py v7.16.0, created at 2026-10-19 02:39 +0000
1from datetime import datetime
2from typing import Annotated
4from pydantic import BeforeValidator, Field
7def timestamp_to_str(timestamp: datetime | str) -> str:
8 """Serialize etdikdə timestamp-i AzeriCard formatına salan funksiya"""
10 if isinstance(timestamp, datetime): 10 ↛ 13line 10 didn't jump to line 13 because the condition on line 10 was always true
11 return timestamp.strftime('%Y%m%d%H%M%S')
13 return timestamp
16def str_to_timestamp(timestamp: datetime | str) -> datetime:
17 """Deserialize etdikdə timestamp-i datetime obyektine salan funksiya"""
19 if isinstance(timestamp, datetime):
20 return timestamp
22 return datetime.strptime(timestamp, '%Y%m%d%H%M%S')
25TimeStampOut = Annotated[
26 str,
27 Field(default_factory=datetime.now, validate_default=True),
28 BeforeValidator(timestamp_to_str),
29 'AzeriCard-a göndəriləcək timestamp (YYMMDDhhmmss formatına salınır)',
30]
33TimeStampIn = Annotated[
34 datetime,
35 BeforeValidator(str_to_timestamp),
36 'AzeriCard-dan gələn, python datetime-a konvert olunan timestamp',
37]