plchat/timeconvert.py

30 lines
1.2 KiB
Python
Raw Normal View History

#PlChat is a pleroma chat client
# Copyright (C) 2021 Knott Eye
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
2021-04-15 15:16:38 -05:00
from dateutil.parser import *
from dateutil.tz import *
from datetime import *
def utc_to_local(utc, twofourhr=False):
if twofourhr:
clockfmt = '%H:%M'
else:
clockfmt = '%I:%M%p'
time = parse(utc)
local = time.astimezone(tzlocal())
today = datetime.today()
if local.day == today.day and local.month == today.month and local.year == today.year:
return datetime.strftime(local, '%I:%M%p')
return datetime.strftime(local, '%I:%M%p %m-%d-%y')