aboutsummaryrefslogtreecommitdiff
path: root/ui/date_picker/date_picker.gd
diff options
context:
space:
mode:
authordam <dam@gudinoff>2022-04-18 09:06:19 +0000
committerdam <dam@gudinoff>2022-04-18 09:06:19 +0000
commit79691f93bab7aa093bb606bfb80d2b4b236ee091 (patch)
tree6e90c6601893895d7640f478f0cad402cc7590b4 /ui/date_picker/date_picker.gd
parent697e1ba3c4cb0a96c4584f1553de368d46287ab7 (diff)
parentee31a9a3d387121030a5f4503adeac5816d7726f (diff)
downloadsurgery-log-79691f93bab7aa093bb606bfb80d2b4b236ee091.tar.zst
surgery-log-79691f93bab7aa093bb606bfb80d2b4b236ee091.zip
Merge godot branch.v1.0
Diffstat (limited to 'ui/date_picker/date_picker.gd')
-rw-r--r--ui/date_picker/date_picker.gd64
1 files changed, 64 insertions, 0 deletions
diff --git a/ui/date_picker/date_picker.gd b/ui/date_picker/date_picker.gd
new file mode 100644
index 0000000..e2a793f
--- /dev/null
+++ b/ui/date_picker/date_picker.gd
@@ -0,0 +1,64 @@
+extends Control
+class_name DatePicker
+
+const days_per_month: Dictionary = {
+ 1: 31,
+ 2: 28,
+ 3: 31,
+ 4: 30,
+ 5: 31,
+ 6: 30,
+ 7: 31,
+ 8: 31,
+ 9: 30,
+ 10: 31,
+ 11: 30,
+ 12: 31,
+}
+
+onready var year_picker := get_node("year") as ValuePicker
+onready var month_picker := get_node("month") as ValuePicker
+onready var day_picker := get_node("day") as ValuePicker
+
+
+func _process(delta: float):
+ var year := year_picker.value
+ var month := month_picker.value
+ var day := day_picker.value
+ var days_on_month: int = days_per_month[month]
+
+ var is_leap_year := (year % 4 == 0 && year % 100 != 0) || year % 400 == 0
+ if is_leap_year && month == 2:
+ days_on_month = 29
+
+ if day > days_on_month:
+ day_picker.value = days_on_month
+ day_picker.max_value = days_on_month
+
+
+func get_day() -> int:
+ return day_picker.value
+
+
+func get_month() -> int:
+ return month_picker.value
+
+
+func get_year() -> int:
+ return year_picker.value
+
+
+func get_date() -> Dictionary:
+ return {
+ year = year_picker.value,
+ month = month_picker.value,
+ day = day_picker.value,
+ }
+
+
+func set_date(new_year: int, new_month: int, new_day: int):
+ year_picker.value = new_year
+ month_picker.value = new_month
+ day_picker.value = new_day
+
+