~mihirsoni/ubuntu-calendar-app/dateSelectNewEventTest

3 by Frank Mertens
Initial code for the month view. Also bootstrapped a small extension library for JS::Date.
1
.pragma library
2
4.2.5 by Frank Mertens
Added a dummy desktop file. Renamed dateTimeUtils to DateLib.
3
Date.msPerDay = 86400e3
4
Date.msPerWeek = Date.msPerDay * 7
3 by Frank Mertens
Initial code for the month view. Also bootstrapped a small extension library for JS::Date.
5
4.2.6 by Frank Mertens
First prototype of the horizontally flicking month view.
6
Date.leapYear = function(year) {
7
    return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)
8
}
9
10
Date.daysInMonth = function(year, month) {
11
    return [
12
        31/*Jan*/, 28/*Feb*/, 31/*Mar*/, 30/*Apr*/, 31/*May*/, 30/*Jun*/,
13
        31/*Jul*/, 31/*Aug*/, 30/*Sep*/, 31/*Oct*/, 30/*Nov*/, 31/*Dec*/
4.2.20 by Frank Mertens
Fix for leap year: add leap day only to Feb.
14
    ][month] + (month == 1) * Date.leapYear(year)
4.2.6 by Frank Mertens
First prototype of the horizontally flicking month view.
15
}
16
17
Date.weeksInMonth = function(year, month, weekday) {
18
    var y = year, m = month
19
    var date0 = new Date(y, m, 1)
20
    var date1 = new Date(y + (m == 11), m < 11 ? m + 1 : 0, 1)
21
    var day = date0.getDay()
22
    var m = (date1.getTime() - date0.getTime()) / Date.msPerDay
23
    var n = 0
24
    while (m > 0) {
25
        if (day == weekday) n = n + 1
26
        day = day < 6 ? day + 1 : 0
27
        m = m - 1
28
    }
29
    return n
30
}
31
46.1.18 by Kunal Parmar
merge from trunk
32
Date.prototype.midnight = function() {
33
    var date = new Date(this)
34
    date.setHours(0,0,0,0);
35
    return date
36
}
37
3 by Frank Mertens
Initial code for the month view. Also bootstrapped a small extension library for JS::Date.
38
Date.prototype.addDays = function(days) {
39
    var date = new Date(this)
98.3.1 by Dennis O'Flaherty
Use setDate and getDate. Adding milliseconds breaks when crossing daylight savings time
40
    date.setDate(date.getDate() + days);
3 by Frank Mertens
Initial code for the month view. Also bootstrapped a small extension library for JS::Date.
41
    return date
42
}
43
4.2.6 by Frank Mertens
First prototype of the horizontally flicking month view.
44
Date.prototype.addMonths = function(months) {
45
    var date = new Date(this)
72.1.1 by Olivier Tilloy
Ensure that all dates are in local time, not a mix of local and UTC.
46
    date.setMonth(date.getMonth() + months)
4.2.6 by Frank Mertens
First prototype of the horizontally flicking month view.
47
    return date
48
}
49
3 by Frank Mertens
Initial code for the month view. Also bootstrapped a small extension library for JS::Date.
50
Date.prototype.weekStart = function(weekStartDay) {
51
    var date = this.midnight()
52
    var day = date.getDay(), n = 0
53
    while (day != weekStartDay) {
54
        if (day == 0) day = 6
55
        else day = day - 1
56
        n = n + 1
57
    }
58
    return date.addDays(-n)
59
}
60
4.2.6 by Frank Mertens
First prototype of the horizontally flicking month view.
61
Date.prototype.monthStart = function() {
62
    return this.midnight().addDays(1 - this.getDate())
63
}
64
3 by Frank Mertens
Initial code for the month view. Also bootstrapped a small extension library for JS::Date.
65
Date.prototype.weekNumber = function() {
66
    var date = this.weekStart(1).addDays(3) // Thursday midnight
67
    var newYear = new Date(date.getFullYear(), 0 /*Jan*/, 1 /*the 1st*/)
68
    var n = 0
69
    var tx = date.getTime(), tn = newYear.getTime()
70
    while (tn < tx) {
4.2.5 by Frank Mertens
Added a dummy desktop file. Renamed dateTimeUtils to DateLib.
71
        tx = tx - Date.msPerWeek
3 by Frank Mertens
Initial code for the month view. Also bootstrapped a small extension library for JS::Date.
72
        n = n + 1
73
    }
74
    return n
75
}
4.2.1 by Frank Mertens
Added JS::Date.daysInMonth() in compute the number of certain weekdays in a month.
76
4.2.6 by Frank Mertens
First prototype of the horizontally flicking month view.
77
Date.prototype.weeksInMonth = function(weekday) {
78
    return Date.weeksInMonth(this.getFullYear(), this.getMonth(), weekday)
4.2.1 by Frank Mertens
Added JS::Date.daysInMonth() in compute the number of certain weekdays in a month.
79
}
17.3.2 by Kunal Parmar
Merge from maib truck
80
81
Date.prototype.isSameDay = function ( otherDay ) {
82
    return ( this.getDate() === otherDay.getDate()
83
    && this.getMonth() === otherDay.getMonth()
84
    && this.getFullYear() === otherDay.getFullYear() );
85
}
63.1.1 by Kunal Parmar
year view implementation
86
87
function weekCount(year, month_number) {
88
    var firstOfMonth = new Date(year, month_number, 1);
89
    var lastOfMonth = new Date(year, month_number+1, 0);
90
91
    var used = firstOfMonth.getDay() + lastOfMonth.getDate();
92
93
    return Math.ceil( used / 7);
94
}
95
96
function getFirstDateofWeek( year, month) {
97
    var date = new Date(year, month, 1);
98
    var first = date.getDate() - date.getDay();
99
    return new Date(date.setDate(first));
100
}
72.2.22 by Kunal Parmar
temp merge
101
102
function today() {
103
    var date = new Date();
104
    date.setHours(0,0,0,0);
105
    return date
106
}
94.1.1 by Kunal Parmar
MonthView/YearView chaged according to new design
107
108
function isSameMonth(date1, date2) {
109
    return ( date1.getMonth() === date2.getMonth()
110
            && date1.getFullYear() === date2.getFullYear())
111
}