date_functions
This commit is contained in:
parent
882942ff82
commit
006aae7a78
3 changed files with 32 additions and 0 deletions
|
|
@ -4,6 +4,7 @@ from typing import Dict
|
|||
from ytdl_sub.script.functions.array_functions import ArrayFunctions
|
||||
from ytdl_sub.script.functions.boolean_functions import BooleanFunctions
|
||||
from ytdl_sub.script.functions.conditional_functions import ConditionalFunctions
|
||||
from ytdl_sub.script.functions.date_functions import DateFunctions
|
||||
from ytdl_sub.script.functions.error_functions import ErrorFunctions
|
||||
from ytdl_sub.script.functions.map_functions import MapFunctions
|
||||
from ytdl_sub.script.functions.numeric_functions import NumericFunctions
|
||||
|
|
@ -22,6 +23,7 @@ class Functions(
|
|||
BooleanFunctions,
|
||||
ErrorFunctions,
|
||||
RegexFunctions,
|
||||
DateFunctions,
|
||||
):
|
||||
_custom_functions: Dict[str, Callable[..., Resolvable]] = {}
|
||||
|
||||
|
|
|
|||
13
src/ytdl_sub/script/functions/date_functions.py
Normal file
13
src/ytdl_sub/script/functions/date_functions.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
from datetime import datetime
|
||||
|
||||
from ytdl_sub.script.types.resolvable import Integer
|
||||
from ytdl_sub.script.types.resolvable import String
|
||||
|
||||
|
||||
class DateFunctions:
|
||||
@staticmethod
|
||||
def datetime_strftime(posix_timestamp: Integer, date_format: String) -> String:
|
||||
"""
|
||||
Converts a posix timestamp to a date using strftime formatting.
|
||||
"""
|
||||
return String(datetime.utcfromtimestamp(posix_timestamp.value).strftime(date_format.value))
|
||||
17
tests/unit/script/functions/test_date_functions.py
Normal file
17
tests/unit/script/functions/test_date_functions.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import pytest
|
||||
from unit.script.conftest import single_variable_output
|
||||
|
||||
from ytdl_sub.script.script import Script
|
||||
|
||||
|
||||
class TestNumericFunctions:
|
||||
@pytest.mark.parametrize(
|
||||
"timestamp, date_format, expected_output",
|
||||
[
|
||||
(1596877200, "'%Y%m%d'", "20200808"),
|
||||
(1596877200, "'%m'", "08"),
|
||||
],
|
||||
)
|
||||
def test_datetime_strftime(self, timestamp: int, date_format: str, expected_output: str):
|
||||
output = single_variable_output(f"{{%datetime_strftime({timestamp}, {date_format})}}")
|
||||
assert output == expected_output
|
||||
Loading…
Reference in a new issue