forked from hyoo-ru/mam_mol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalendar.view.ts
119 lines (92 loc) · 2.36 KB
/
calendar.view.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
namespace $.$mol {
export class $mol_calendar extends $.$mol_calendar {
@ $mol_mem
month_moment() {
const moment = new $mol_time_moment( this.month_string() || undefined )
return new $mol_time_moment({ year : moment.year , month : moment.month })
}
title() {
return this.month_moment().toString( 'Month YYYY' )
}
@ $mol_mem
day_first() {
return this.month_moment().merge({ day : 0 })
}
@ $mol_mem
day_last() {
return this.day_first().shift( 'P1M' )
}
@ $mol_mem
day_draw_from() {
let weekday = this.day_first().weekday
return this.day_first().shift({ day : - weekday })
}
@ $mol_mem
weekdays() {
const next : $mol_view[] = []
for( let index = 0 ; index < 7 ; ++index ) {
next.push( this.Weekday( index ) )
}
return next
}
@ $mol_mem_key
weekday( index : number ){
return this.day_draw_from().shift({ day : index }).toString( 'WD' )
}
weekend( index : number ){
return [ 5 , 6 ].indexOf( index ) >= 0
}
@ $mol_mem
weeks_count() {
const interval = new $mol_time_interval({
start : this.day_draw_from() ,
end : this.day_last() ,
})
return Math.ceil( interval.duration.count({ day : 7 }) )
}
@ $mol_mem
sub() {
return [
... super.sub() ,
... this.weeks() ,
]
}
@ $mol_mem
weeks() {
const weeks : $mol_view[] = []
let count = this.weeks_count()
for( let i = 0; i < count; ++i ) {
weeks.push( this.Week( i ) )
}
return weeks
}
@ $mol_mem_key
week_days( index : number ) {
const days : $mol_view[] = []
let start = this.day_draw_from().shift({ day : index * 7 })
for( let i = 0 ; i < 7 ; ++i ) {
days.push( this.Day( start.shift({ day : i }).toString( 'YYYY-MM-DD' ) ) )
}
return days
}
@ $mol_mem_key
day_text( day : string ) {
return new $mol_time_moment( day ).toString( "D" )
}
@ $mol_mem_key
day_holiday( day : string ) {
return this.weekend( new $mol_time_moment( day ).weekday )
}
@ $mol_mem_key
day_ghost( day : string ) {
return new $mol_time_moment( day ).toString( 'YYYY-MM' ) !== this.day_first().toString( 'YYYY-MM' )
}
@ $mol_mem_key
day_selected( day : string ) {
return new $mol_time_moment().toString( 'YYYY-MM-DD' ) === day
}
day_theme( day : string ) {
return this.day_selected( day ) ? '$mol_theme_base' : super.day_theme( day )
}
}
}