You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.6 KiB
55 lines
1.6 KiB
import './plus-minus.imba'
|
|
|
|
let h =
|
|
zero: do new Date("1970-01-01T00:00")
|
|
max_size: do #ms ||= R.getters.size "3_0_0", 1 # 3 days
|
|
|
|
validate: do |s|
|
|
return R.getters.size("0_0_5", 1) if s <= h.zero!
|
|
return new Date(h.max_size!) if s > h.max_size!
|
|
s
|
|
|
|
modify: do |what, n, date=R.param('size')|
|
|
date["set{what}"]( date["get{what}"]() + n )
|
|
h.validate(date)
|
|
|
|
change: do |what, n, date=R.param('size')|
|
|
h.save h.modify(*arguments)
|
|
|
|
save: do |date|
|
|
R.write 'size', date
|
|
|
|
days: do |day=R.param('size')| day.getDate! - 1
|
|
incr_day: do h.change "Date", 1
|
|
decr_day: do h.change "Date", -1
|
|
incr_h: do h.change "Hours", 1
|
|
decr_h: do h.change "Hours", -1
|
|
incr_min: do h.change "Minutes", 5
|
|
decr_min: do h.change "Minutes", -5
|
|
|
|
set_time: do |days, hour, min, date=h.zero!|
|
|
date.setHours(hour, min, 0, 0)
|
|
date.setDate(Number(days)+1)
|
|
date
|
|
|
|
format_d: do |n| "{n}{n > 1 ? "days" : "day"}"
|
|
format_h: do |n| "{n}h"
|
|
format_min: do |n| "{n}min"
|
|
|
|
export default h
|
|
|
|
R.setters.size = do |v| let s = "{h.days(v)}_{v.getHours!}_{v.getMinutes!}"; s if s!= "0_0_30"
|
|
R.getters.size = do |v, skip_validation|
|
|
v ||= "0_0_30"
|
|
let size = v.split('_')
|
|
let date = h.set_time(*size)
|
|
skip_validation ? date : h.validate(date)
|
|
|
|
tag slot-size-input
|
|
<self[d:hflex jac:center]>
|
|
console.log(R.param('size'))
|
|
if h.days! > 0
|
|
<plus-minus value=h.days! decorate=h.format_d decr=h.decr_day incr=h.incr_day>
|
|
<plus-minus value=R.param('size').getHours!.toString! decorate=h.format_h decr=h.decr_h incr=h.incr_h>
|
|
<plus-minus value=R.param('size').getMinutes!.toString! decorate=h.format_min decr=h.decr_min incr=h.incr_min>
|
|
|