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.
47 lines
1.2 KiB
47 lines
1.2 KiB
2 years ago
|
import './plus-minus.imba'
|
||
|
|
||
|
let h =
|
||
|
today: do new Date
|
||
|
|
||
|
modify: do |what, n, date=R.param('date')|
|
||
|
date["set{what}"]( date["get{what}"]() + n )
|
||
|
date
|
||
|
|
||
|
change: do |what, n, date=R.param('date')|
|
||
|
h.save h.modify(*arguments)
|
||
|
|
||
|
save: do |date|
|
||
|
R.write 'date', date
|
||
|
|
||
|
incr_day: do h.change "Date", 1
|
||
|
decr_day: do h.change "Date", -1
|
||
|
incr_month: do h.change "Month", 1
|
||
|
decr_month: do h.change "Month", -1
|
||
|
incr_year: do h.change "FullYear", 1
|
||
|
decr_year: do h.change "FullYear", -1
|
||
|
|
||
|
no_time: do |date|
|
||
|
date.setHours(0,0,0,0)
|
||
|
date
|
||
|
|
||
|
valid: do |date|
|
||
|
( date || R.param('date') ) > h.no_time! h.today!
|
||
|
|
||
|
format: do |n|
|
||
|
"{if n < 10 then 0 else ''}{n}"
|
||
|
|
||
|
export default h
|
||
|
|
||
|
R.setters.date = do |v| "{v.getFullYear!}-{h.format(v.getMonth!+1)}-{h.format(v.getDate!)}" if h.valid(v)
|
||
|
R.getters.date = do |v|
|
||
|
if v
|
||
|
let date = new Date(v)
|
||
|
return date if h.valid(date)
|
||
|
h.today!
|
||
|
|
||
|
tag date-input
|
||
|
<self[d:hflex jac:center]>
|
||
|
<plus-minus value=R.param('date').getFullYear! decr=h.decr_year incr=h.incr_year>
|
||
|
<plus-minus value=R.param('date').getMonth!+1 decorate=h.format decr=h.decr_month incr=h.incr_month>
|
||
|
<plus-minus value=R.param('date').getDate! decorate=h.format decr=h.decr_day incr=h.incr_day>
|
||
|
|