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:
parent
2a134061c0
commit
802037cf22
1 changed files with 14 additions and 0 deletions
|
@ -17,6 +17,7 @@
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with Radicale. If not, see <http://www.gnu.org/licenses/>.
|
# along with Radicale. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import datetime
|
||||||
import os
|
import os
|
||||||
import ssl
|
import ssl
|
||||||
import sys
|
import sys
|
||||||
|
@ -46,6 +47,10 @@ ADDRESS_TYPE = Union[Tuple[Union[str, bytes, bytearray], int],
|
||||||
Tuple[str, int, int, 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,
|
def load_plugin(internal_types: Sequence[str], module_name: str,
|
||||||
class_name: str, base_class: Type[_T_co],
|
class_name: str, base_class: Type[_T_co],
|
||||||
configuration: "config.Configuration") -> _T_co:
|
configuration: "config.Configuration") -> _T_co:
|
||||||
|
@ -244,3 +249,12 @@ def user_groups_as_string():
|
||||||
username = os.getlogin()
|
username = os.getlogin()
|
||||||
s = "user=%s" % (username)
|
s = "user=%s" % (username)
|
||||||
return s
|
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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue