@@ -118,7 +118,8 @@ expected."}
118
118
(minus- [this period] " Returns a new date/time corresponding to the given date/time moved backwards by the given Period(s)." )
119
119
(first-day-of-the-month- [this] " Returns the first day of the month" )
120
120
(last-day-of-the-month- [this] " Returns the last day of the month" )
121
- (week-number-of-year [this] " Returs the number of weeks in the year" ))
121
+ (week-number-of-year [this] " Returns the week of the week based year of the given date/time" )
122
+ (week-year [this] " Returns the the week based year of the given date/time." ))
122
123
123
124
(defprotocol InTimeUnitProtocol
124
125
" Interface for in-<time unit> functions"
@@ -187,6 +188,17 @@ expected."}
187
188
(not= dayo dayother) (- dayo dayother)
188
189
:else 0 )))
189
190
191
+ (defn get-week-year
192
+ " Counterpart ot goog.date/getWeekNumber"
193
+ [year month date]
194
+ (let [january (= month 0 )
195
+ december (= month 11 )
196
+ week-number (goog.date/getWeekNumber year month date)]
197
+ (cond
198
+ (and january (>= week-number 52 )) (dec year)
199
+ (and december (= week-number 1 )) (inc year)
200
+ :else year)))
201
+
190
202
(extend-protocol DateTimeProtocol
191
203
goog.date.UtcDateTime
192
204
(year [this] (.getYear this))
@@ -211,6 +223,8 @@ expected."}
211
223
(week-number-of-year [this]
212
224
(goog.date/getWeekNumber
213
225
(.getYear this) (.getMonth this) (.getDate this)))
226
+ (week-year [this]
227
+ (get-week-year (.getYear this) (.getMonth this) (.getDate this)))
214
228
215
229
goog.date.DateTime
216
230
(year [this] (.getYear this))
@@ -235,6 +249,8 @@ expected."}
235
249
(week-number-of-year [this]
236
250
(goog.date/getWeekNumber
237
251
(.getYear this) (.getMonth this) (.getDate this)))
252
+ (week-year [this]
253
+ (get-week-year (.getYear this) (.getMonth this) (.getDate this)))
238
254
239
255
goog.date.Date
240
256
(year [this] (.getYear this))
@@ -258,7 +274,9 @@ expected."}
258
274
(period :days 1 )))
259
275
(week-number-of-year [this]
260
276
(goog.date/getWeekNumber
261
- (.getYear this) (.getMonth this) (.getDate this))))
277
+ (.getYear this) (.getMonth this) (.getDate this)))
278
+ (week-year [this]
279
+ (get-week-year (.getYear this) (.getMonth this) (.getDate this))))
262
280
263
281
(def utc #js {:id " UTC" :std_offset 0 :names [" UTC" ] :transitions []})
264
282
0 commit comments