1
0
Fork 0
mirror of https://github.com/Kozea/Radicale.git synced 2025-08-07 18:30:54 +00:00

add a function to format unixtime to string

This commit is contained in:
Peter Bieringer 2025-07-20 17:29:09 +02:00
parent 2a134061c0
commit 802037cf22

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with Radicale. If not, see <http://www.gnu.org/licenses/>.
import datetime
import os
import ssl
import sys
@ -46,6 +47,10 @@ ADDRESS_TYPE = Union[Tuple[Union[str, bytes, bytearray], int],
Tuple[str, int, int, int]]
# Max YEAR in datetime in unixtime
DATETIME_MAX_UNIXTIME: int = (datetime.MAXYEAR - 1970) * 365 * 24 * 60 * 60
def load_plugin(internal_types: Sequence[str], module_name: str,
class_name: str, base_class: Type[_T_co],
configuration: "config.Configuration") -> _T_co:
@ -244,3 +249,12 @@ def user_groups_as_string():
username = os.getlogin()
s = "user=%s" % (username)
return s
def format_ut(unixtime: int) -> str:
if unixtime < DATETIME_MAX_UNIXTIME:
dt = datetime.datetime.fromtimestamp(unixtime, datetime.UTC)
r = str(unixtime) + "(" + dt.strftime('%Y-%m-%dT%H:%M:%SZ') + ")"
else:
r = str(unixtime) + "(>MAX:" + str(DATETIME_MAX_UNIXTIME) + ")"
return r