summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/Clipperz/PM/Date.js
Unidiff
Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/Date.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/gamma/js/Clipperz/PM/Date.js201
1 files changed, 201 insertions, 0 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/Date.js b/frontend/gamma/js/Clipperz/PM/Date.js
new file mode 100644
index 0000000..a131357
--- a/dev/null
+++ b/frontend/gamma/js/Clipperz/PM/Date.js
@@ -0,0 +1,201 @@
1/*
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer to http://www.clipperz.com
12
13* Javascript Crypto Library is free software: you can redistribute
14 it and/or modify it under the terms of the GNU Affero General Public
15 License as published by the Free Software Foundation, either version
16 3 of the License, or (at your option) any later version.
17
18* Javascript Crypto Library is distributed in the hope that it will
19 be useful, but WITHOUT ANY WARRANTY; without even the implied
20 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 See the GNU Affero General Public License for more details.
22
23* You should have received a copy of the GNU Affero General Public
24 License along with Javascript Crypto Library. If not, see
25 <http://www.gnu.org/licenses/>.
26
27*/
28
29if (typeof(Clipperz) == 'undefined') { Clipperz = {}; }
30if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; }
31if (typeof(Clipperz.PM.Date) == 'undefined') { Clipperz.PM.Date = {}; }
32
33Clipperz.PM.Date.VERSION = "0.1";
34Clipperz.PM.Date.NAME = "Clipperz.PM.Date";
35
36MochiKit.Base.update(Clipperz.PM.Date, {
37
38 '__repr__': function () {
39 return "[" + this.NAME + " " + this.VERSION + "]";
40 },
41
42 //-------------------------------------------------------------------------
43
44 'toString': function () {
45 return this.__repr__();
46 },
47
48 //-------------------------------------------------------------------------
49
50 'locale': function() {
51 return {
52 'amDesignation':Clipperz.PM.Strings.getValue('calendarStrings.amDesignation'),
53 'pmDesignation':Clipperz.PM.Strings.getValue('calendarStrings.pmDesignation'),
54 'days': Clipperz.PM.Strings.getValue('calendarStrings.days'),
55 'shortDays': Clipperz.PM.Strings.getValue('calendarStrings.shortDays'),
56 'shortMonths': Clipperz.PM.Strings.getValue('calendarStrings.shortMonths'),
57 'months': Clipperz.PM.Strings.getValue('calendarStrings.months')
58 }
59 },
60
61 //=========================================================================
62/*
63 'formatDateWithPHPLikeTemplate': function(aDate, aTemplate) {
64 return Clipperz.Date.formatDateWithPHPLikeTemplateAndLocale(aDate, aTemplate, Clipperz.PM.Date.locale());
65 },
66
67 'parseDateWithPHPLikeTemplate': function(aDate, aTemplate) {
68 return Clipperz.Date.parseDateWithPHPTemplateAndLocale(aDate, aTemplate, Clipperz.PM.Date.locale());
69 },
70
71 //=========================================================================
72
73 'formatDateWithJavaLikeTemplate': function(aDate, aTemplate) {
74 return Clipperz.Date.formatDateWithJavaLikeTemplateAndLocale(aDate, aTemplate, Clipperz.PM.Date.locale());
75 },
76
77 'parseDateWithJavaLikeTemplate': function(aDate, aTemplate) {
78 return Clipperz.Date.parseDateWithJavaLikeTemplateAndLocale(aDate, aTemplate, Clipperz.PM.Date.locale());
79 },
80*/
81 //=========================================================================
82
83 'formatWithTemplate': function (aTemplate, aDate) {
84 return Clipperz.PM.Date.formatDateWithTemplate(aDate, aTemplate);
85 },
86
87 'formatDateWithTemplate': function(aDate, aTemplate) {
88 var result;
89
90 if (aDate == null) {
91 result = ""
92 } else {
93 result = Clipperz.Date.formatDateWithPHPLikeTemplateAndLocale(aDate, aTemplate, Clipperz.PM.Date.locale());
94 };
95
96 return result;
97 },
98
99 'parseDateWithTemplate': function(aValue, aTemplate) {
100 return Clipperz.Date.parseDateWithPHPTemplateAndLocale(aValue, aTemplate, Clipperz.PM.Date.locale());
101 },
102
103 //=========================================================================
104
105 'formatDateWithUTCFormat': function(aDate) {
106 return Clipperz.Date.formatDateWithUTCFormatAndLocale(aDate, Clipperz.PM.Date.locale());
107 },
108
109 'parseDateWithUTCFormat': function(aValue) {
110 var result;
111
112 if (aValue == null) {
113 result = null;
114 } else {
115 result = Clipperz.Date.parseDateWithUTCFormatAndLocale(aValue, Clipperz.PM.Date.locale());
116 }
117
118 return result;
119 },
120
121 //=========================================================================
122
123 'getElapsedTimeDescription': function(aDate) {
124 var result;
125
126 result = ""
127
128 if (aDate != null) {
129 var now;
130 var elapsedTime;
131
132 var millisencondsInAMinute;
133 var millisencondsInAnHour;
134 var millisencondsInADay;
135 var millisencondsInAWeek;
136 var millisencondsInAMonth;
137
138 now = new Date();
139 elapsedTime = now.getTime() - aDate.getTime();
140
141 millisencondsInAMinute = 60 * 1000;
142 millisencondsInAnHour = millisencondsInAMinute * 60;
143 millisencondsInADay = millisencondsInAnHour * 24;
144 millisencondsInAWeek = millisencondsInADay * 7;
145 millisencondsInAMonth = millisencondsInAWeek * 5;
146
147 if ((elapsedTime / millisencondsInAMonth) > 1) {
148 result = Clipperz.PM.Strings.getValue('elapsedTimeDescriptions.MORE_THAN_A_MONTH_AGO');
149 } else if ((elapsedTime / millisencondsInAWeek) > 1) {
150 var elapsedWeeks;
151
152 elapsedWeeks = Math.floor((elapsedTime / millisencondsInAWeek));
153 if (elapsedWeeks == 1) {
154 result = Clipperz.PM.Strings.getValue('elapsedTimeDescriptions.MORE_THAN_A_WEEK_AGO');
155 } else {
156 result = Clipperz.PM.Strings.getValue('elapsedTimeDescriptions.MORE_THAN_*_WEEKS_AGO').replace(/__elapsed__/, elapsedWeeks);
157 }
158 } else if ((elapsedTime / millisencondsInADay) > 1) {
159 var elapsedDays;
160
161 elapsedDays = Math.floor((elapsedTime / millisencondsInADay));
162 if (elapsedDays == 1) {
163 result = Clipperz.PM.Strings.getValue('elapsedTimeDescriptions.YESTERDAY');
164 } else {
165 result = Clipperz.PM.Strings.getValue('elapsedTimeDescriptions.*_DAYS_AGO').replace(/__elapsed__/, elapsedDays);
166 }
167 } else if ((elapsedTime / millisencondsInAnHour) > 1) {
168 var elapsedHours;
169
170 elapsedHours = Math.floor((elapsedTime / millisencondsInAnHour));
171 if (elapsedHours == 1) {
172 result = Clipperz.PM.Strings.getValue('elapsedTimeDescriptions.ABOUT_AN_HOUR_AGO');
173 } else {
174 result = Clipperz.PM.Strings.getValue('elapsedTimeDescriptions.*_HOURS_AGO').replace(/__elapsed__/, elapsedHours);
175 }
176 } else {
177 var elapsed10Minutes;
178
179 elapsed10Minutes = (Math.floor((elapsedTime / millisencondsInAMinute) / 10)) * 10;
180 if (elapsed10Minutes == 0) {
181 result = Clipperz.PM.Strings.getValue('elapsedTimeDescriptions.JUST_A_FEW_MINUTES_AGO');
182 } else {
183 result = Clipperz.PM.Strings.getValue('elapsedTimeDescriptions.ABOUT_*_MINUTES_AGO').replace(/__elapsed__/, elapsed10Minutes+"");
184 }
185 }
186 }
187
188 return result;
189 },
190
191 //-------------------------------------------------------------------------
192
193 'parse': function (aValue) {
194 return Clipperz.PM.Date.parseDateWithUTCFormat(aValue);
195 },
196
197 //-------------------------------------------------------------------------
198 __syntaxFix__: "syntax fix"
199
200});
201