summaryrefslogtreecommitdiffstats
path: root/girok/utils/calendar.py
diff options
context:
space:
mode:
Diffstat (limited to 'girok/utils/calendar.py')
-rw-r--r--girok/utils/calendar.py129
1 files changed, 0 insertions, 129 deletions
diff --git a/girok/utils/calendar.py b/girok/utils/calendar.py
deleted file mode 100644
index e2e0763..0000000
--- a/girok/utils/calendar.py
+++ /dev/null
@@ -1,129 +0,0 @@
-from datetime import datetime
-import calendar
-from textual import log
-from rich.text import Text
-from rich.style import Style
-
-import girok.constants as constants
-
-def build_category_tree(parent, cats):
- """
- tree (textual.widgets.Tree object)
- cats: dictionary containing hierarchical category structure
- """
- for cat_name in cats:
- if cats[cat_name]['subcategories'] == {}:
- cur = parent.add_leaf(cat_name)
- else:
- cur = parent.add(cat_name, expand=True)
- build_category_tree(cur, cats[cat_name]['subcategories'])
-
-
-def get_full_path_from_node(node):
- label = str(node._label)
- if label.endswith(" " + constants.LEFT_ARROW_EMOJI):
- label = label[:-2]
- else:
- pass
- if label == "All Categories":
- return ""
- elif label == "No Category":
- return "No Category"
- node_name = label
- parent_path = get_full_path_from_node(node.parent)
- return parent_path + node_name + "/"
-
-
-def convert_day_to_cell_num(year: int, month: int, day: int):
- """
-
- """
- first_weekday, total_days = calendar.monthrange(year, month)
- return first_weekday + day - 1
-
-
-def convert_cell_num_to_day(year: int, month: int, cell_num: int):
- first_weekday, total_days = calendar.monthrange(year, month)
- return cell_num - first_weekday + 1
-
-
-def convert_cell_num_to_coord(cell_num: int):
- """
- cell_num: 0 ~ 34
- """
-
- return (cell_num // 7, cell_num % 7)
-
-
-def convert_coord_to_cell_num(x: int, y: int):
- return x * 7 + y
-
-
-def get_date_obj_from_str_separated_by_T(s: str):
- s = str(s)
- delim = "T" if "T" in s else " "
- return datetime.strptime(s, f"%Y-%m-%d{delim}%H:%M:%S")
-
-
-def remove_left_arrow(cell):
- if cell is None:
- return
- if not cell.children:
- return
- cell_label = cell.children[0]
- cell_label_text = cell_label.render()
- style = cell_label_text.style
- if str(cell_label_text).endswith(" " + constants.LEFT_ARROW_EMOJI):
- if cell_label_text.spans:
- style = cell_label_text.spans[0].style
-
- if str(cell_label_text).endswith(" " + constants.LEFT_ARROW_EMOJI):
- new_label_text = Text(str(cell_label_text)[:2], style=style)
- else:
- new_label_text = Text(str(cell_label_text), style=style)
- cell_label.update(new_label_text)
-
-
-def add_left_arrow(cell):
- if not cell.children:
- return
-
- cell_label = cell.children[0]
- cell_label_text = cell_label.render()
- style = cell_label_text.style
-
- if str(cell_label_text).endswith(" " + constants.LEFT_ARROW_EMOJI):
- new_label_text = Text(str(cell_label_text), style=style)
- else:
- new_label_text = Text.assemble(Text(str(cell_label_text), style=style), " ", Text(constants.LEFT_ARROW_EMOJI, style=Style(color="#9bdfbb")))
- cell_label.update(new_label_text)
-
-
-def remove_left_arrow_tree(node):
- label_text = node.label
- style = label_text.style
- if str(label_text).endswith(" " + constants.LEFT_ARROW_EMOJI):
- new_label_text = Text(str(label_text)[:-2], style=style)
- else:
- new_label_text = Text(str(label_text), style=style)
-
- node.set_label(new_label_text)
-
-def add_left_arrow_tree(node):
- label_text = node.label
- style = label_text.style
- if str(label_text).endswith(" " + constants.LEFT_ARROW_EMOJI):
- pass
- else:
- node.set_label(Text.assemble(label_text, " ", constants.LEFT_ARROW_EMOJI, style=style))
-
-
-def remove_highlight(node):
- label_text = node.label
- style = label_text.style
- node.set_label(Text(str(label_text)))
-
-
-def add_highlight(node):
- label = str(node.label)
- node.set_label(Text(label, style=Style(color="#9bdfbb"))) \ No newline at end of file