~pkunal-parmar/ubuntu-calendar-app/ICalImport

400.1.1 by mihirsoni-123
Added copyright header comments in all the pages
1
/*
400.1.2 by mihirsoni-123
updated copyright year
2
 * Copyright (C) 2013-2014 Canonical Ltd
400.1.1 by mihirsoni-123
Added copyright header comments in all the pages
3
 *
4
 * This file is part of Ubuntu Calendar App
5
 *
6
 * Ubuntu Calendar App is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License version 3 as
8
 * published by the Free Software Foundation.
9
 *
10
 * Ubuntu Calendar App is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
3 by Frank Mertens
Initial code for the month view. Also bootstrapped a small extension library for JS::Date.
18
.pragma library
19
4.2.5 by Frank Mertens
Added a dummy desktop file. Renamed dateTimeUtils to DateLib.
20
Date.msPerDay = 86400e3
21
Date.msPerWeek = Date.msPerDay * 7
3 by Frank Mertens
Initial code for the month view. Also bootstrapped a small extension library for JS::Date.
22
4.2.6 by Frank Mertens
First prototype of the horizontally flicking month view.
23
Date.leapYear = function(year) {
24
    return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)
25
}
26
27
Date.daysInMonth = function(year, month) {
28
    return [
29
        31/*Jan*/, 28/*Feb*/, 31/*Mar*/, 30/*Apr*/, 31/*May*/, 30/*Jun*/,
30
        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.
31
    ][month] + (month == 1) * Date.leapYear(year)
4.2.6 by Frank Mertens
First prototype of the horizontally flicking month view.
32
}
33
34
Date.weeksInMonth = function(year, month, weekday) {
35
    var y = year, m = month
36
    var date0 = new Date(y, m, 1)
37
    var date1 = new Date(y + (m == 11), m < 11 ? m + 1 : 0, 1)
38
    var day = date0.getDay()
39
    var m = (date1.getTime() - date0.getTime()) / Date.msPerDay
40
    var n = 0
41
    while (m > 0) {
42
        if (day == weekday) n = n + 1
43
        day = day < 6 ? day + 1 : 0
44
        m = m - 1
45
    }
46
    return n
47
}
48
46.1.18 by Kunal Parmar
merge from trunk
49
Date.prototype.midnight = function() {
50
    var date = new Date(this)
51
    date.setHours(0,0,0,0);
52
    return date
53
}
54
209.1.1 by Yohan Boniface
Use proper end of day value
55
Date.prototype.endOfDay = function() {
56
    var date = new Date(this)
209.1.3 by Yohan Boniface
Set also seconds in Date.endOfDay
57
    date.setHours(23,59,59,0);
209.1.1 by Yohan Boniface
Use proper end of day value
58
    return date
59
}
60
3 by Frank Mertens
Initial code for the month view. Also bootstrapped a small extension library for JS::Date.
61
Date.prototype.addDays = function(days) {
62
    var date = new Date(this)
98.3.1 by Dennis O'Flaherty
Use setDate and getDate. Adding milliseconds breaks when crossing daylight savings time
63
    date.setDate(date.getDate() + days);
3 by Frank Mertens
Initial code for the month view. Also bootstrapped a small extension library for JS::Date.
64
    return date
65
}
66
4.2.6 by Frank Mertens
First prototype of the horizontally flicking month view.
67
Date.prototype.addMonths = function(months) {
68
    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.
69
    date.setMonth(date.getMonth() + months)
4.2.6 by Frank Mertens
First prototype of the horizontally flicking month view.
70
    return date
71
}
72
3 by Frank Mertens
Initial code for the month view. Also bootstrapped a small extension library for JS::Date.
73
Date.prototype.weekStart = function(weekStartDay) {
74
    var date = this.midnight()
75
    var day = date.getDay(), n = 0
76
    while (day != weekStartDay) {
77
        if (day == 0) day = 6
78
        else day = day - 1
79
        n = n + 1
80
    }
81
    return date.addDays(-n)
82
}
83
4.2.6 by Frank Mertens
First prototype of the horizontally flicking month view.
84
Date.prototype.monthStart = function() {
85
    return this.midnight().addDays(1 - this.getDate())
86
}
87
3 by Frank Mertens
Initial code for the month view. Also bootstrapped a small extension library for JS::Date.
88
Date.prototype.weekNumber = function() {
89
    var date = this.weekStart(1).addDays(3) // Thursday midnight
90
    var newYear = new Date(date.getFullYear(), 0 /*Jan*/, 1 /*the 1st*/)
91
    var n = 0
92
    var tx = date.getTime(), tn = newYear.getTime()
93
    while (tn < tx) {
4.2.5 by Frank Mertens
Added a dummy desktop file. Renamed dateTimeUtils to DateLib.
94
        tx = tx - Date.msPerWeek
3 by Frank Mertens
Initial code for the month view. Also bootstrapped a small extension library for JS::Date.
95
        n = n + 1
96
    }
97
    return n
98
}
4.2.1 by Frank Mertens
Added JS::Date.daysInMonth() in compute the number of certain weekdays in a month.
99
4.2.6 by Frank Mertens
First prototype of the horizontally flicking month view.
100
Date.prototype.weeksInMonth = function(weekday) {
101
    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.
102
}
17.3.2 by Kunal Parmar
Merge from maib truck
103
104
Date.prototype.isSameDay = function ( otherDay ) {
105
    return ( this.getDate() === otherDay.getDate()
106
    && this.getMonth() === otherDay.getMonth()
107
    && this.getFullYear() === otherDay.getFullYear() );
108
}
63.1.1 by Kunal Parmar
year view implementation
109
197.1.3 by Yohan Boniface
Merge with trunk
110
Date.prototype.mergeDate = function (d) {
111
    this.setFullYear(d.getFullYear());
112
    this.setMonth(d.getMonth());
113
    this.setDate(d.getDate());
114
}
115
63.1.1 by Kunal Parmar
year view implementation
116
function weekCount(year, month_number) {
117
    var firstOfMonth = new Date(year, month_number, 1);
118
    var lastOfMonth = new Date(year, month_number+1, 0);
119
120
    var used = firstOfMonth.getDay() + lastOfMonth.getDate();
121
122
    return Math.ceil( used / 7);
123
}
124
125
function getFirstDateofWeek( year, month) {
126
    var date = new Date(year, month, 1);
127
    var first = date.getDate() - date.getDay();
128
    return new Date(date.setDate(first));
129
}
72.2.22 by Kunal Parmar
temp merge
130
131
function today() {
132
    var date = new Date();
133
    date.setHours(0,0,0,0);
134
    return date
135
}
94.1.1 by Kunal Parmar
MonthView/YearView chaged according to new design
136
137
function isSameMonth(date1, date2) {
199.1.1 by Kunal Parmar
YearView optimization
138
    return ( date1.getFullYear() === date2.getFullYear()
139
            && date1.getMonth() === date2.getMonth() )
94.1.1 by Kunal Parmar
MonthView/YearView chaged according to new design
140
}