Skip to content

Commit

Permalink
Fixing bug with UTC time
Browse files Browse the repository at this point in the history
  • Loading branch information
anufrievroman committed Sep 24, 2023
1 parent b8e5795 commit db8897d
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 2 deletions.
49 changes: 49 additions & 0 deletions calcure.1.gz
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
.TH CALCURE 2023-05-25
.nh
.SH NAME
calcure \- TUI calendar and task manager
.SH SYNOPSIS
.B calcure
[ \fIOPTION\fR ]
.SH DESCRIPTION
.B Calcure
is a TUI calendar and task manager program with a customizable interface and ability to read cloud calendars. For more information, visit \fIhttps://anufrievroman.gitbook.com/calcure\fR
.SH OPTIONS

.TP
\fB\-v \fP
Print version.

.TP
\fB\-h \fP
Start on help page.

.TP
\fB\-j \fP
Start on journal view.

.TP
\fB\-i \fP
Start using Iranian calendar.

.TP
\fB\-p \fP
Start in the privacy mode.

.TP
\fB\-c \fP \fI<filename>\fR
Use an alternative configuration file (default is \fI$HOME/.config/calcure/config.ini\fR).

.TP
\fB\-\-task "<task title>"\fP
Add a new task (without starting TUI).

.TP
\fB\-\-event "<event date> <event title>"\fP
Add a new event (without starting TUI).

.SH COMMANDS DURING USE
Press '\fB?\fP' during use to get a list of keybindings.
.br
.SH AUTHOR
Written by Roman Anufriev. For more information, visit \fIhttps://anufrievroman.gitbook.com/calcure\fR
2 changes: 1 addition & 1 deletion calcure/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from calcure.translations.en import *


__version__ = "2.9.4"
__version__ = "2.9.5"


def read_items_from_user_arguments(screen, user_tasks, user_events, task_saver_csv, event_saver_csv):
Expand Down
34 changes: 33 additions & 1 deletion calcure/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import csv
import os
import datetime
import time
import ics
import urllib.request
import io
Expand Down Expand Up @@ -372,6 +373,10 @@ def parse_event(self, event, index, calendar_number):
status = Status.NORMAL
is_private = False

# Calculate offset of local timezone from UTC:
utc_offset_sec = time.timezone if (time.localtime().tm_isdst == 0) else time.altzone
utc_offset_hours = -1 * utc_offset_sec / 3600

# Parameters of the event from ics file, if they exist:
name = event.name if event.name is not None else ""
all_day = event.all_day if event.all_day is not None else True
Expand All @@ -381,7 +386,34 @@ def parse_event(self, event, index, calendar_number):

# Add start time to the name of non-all-day events:
if not all_day:
hour = event.begin.hour if event.begin else 0
hour = int(event.begin.hour) if event.begin else 0

# Convert to local timezone, and add or remove a day:
hour += int(utc_offset_hours)
if hour >= 24:
hour -= 24
days_in_this_month = Calendar(0, self.use_persian_calendar).last_day(year, month)
if day < days_in_this_month:
day += 1
else:
day = 1
if month < 12:
month += 1
else:
month = 1
year += 1
if hour < 0:
hour += 24
if day > 1:
day -= 1
else:
if month > 1:
month -= 1
else:
month = 12
year -= 1
day = Calendar(0, self.use_persian_calendar).last_day(year, month)

minute = event.begin.minute if event.begin else 0
name = f"{hour:0=2}:{minute:0=2} {name}"

Expand Down

0 comments on commit db8897d

Please sign in to comment.