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