hamyar_paygah.utils.text_utils

Utility functions related to text.

Functions

convert_date_to_datetime(date_string)

Convert a Jalali date string to a Gregorian datetime object.

convert_date_and_time_to_datetime(date_string, time_string)

Convert Jalali date and time strings to a Gregorian datetime.

is_valid_server_address(server_address)

Check whether a server address has a valid HTTP/HTTPS URL structure.

Module Contents

hamyar_paygah.utils.text_utils.convert_date_to_datetime(date_string)

Convert a Jalali date string to a Gregorian datetime object.

The input must be in the format YYYY/MM/DD. If None or an empty string is provided, None is returned.

Parameters:

date_string (str | None) – Jalali date string in YYYY/MM/DD format.

Returns:

A datetime.datetime object representing the corresponding Gregorian date at midnight, or None if the input is None or empty.

Return type:

datetime.datetime | None

hamyar_paygah.utils.text_utils.convert_date_and_time_to_datetime(date_string, time_string)

Convert Jalali date and time strings to a Gregorian datetime.

The date must be in YYYY/MM/DD format and the time must be in HH:MM format. If either value is None or equals "-", None is returned.

Parameters:
  • date_string (str | None) – Jalali date string in YYYY/MM/DD format.

  • time_string (str | None) – Jalali time string in HH:MM format.

Returns:

A datetime.datetime object representing the corresponding Gregorian date and time, or None if inputs are missing or marked as invalid.

Return type:

datetime.datetime | None

hamyar_paygah.utils.text_utils.is_valid_server_address(server_address)

Check whether a server address has a valid HTTP/HTTPS URL structure.

The address must: - Be a non-empty string - Use the http or https scheme - Contain a network location component (host)

This function validates only the structural format of the URL. It does not verify DNS resolution or server reachability.

Parameters:

server_address (str | None) – Server address entered by the user.

Returns:

True if the address appears structurally valid, otherwise False.

Return type:

bool