From 6bfc44fb53d73a4d9590a88332ad75f1c3c301b8 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Mon, 1 Feb 2016 20:54:37 -0500 Subject: [PATCH] (js) Add support for %p in date formatting Fixes #3480 --- UI/Common/UIxPageFrame.m | 5 +++++ UI/SOGoUI/UIxComponent.h | 8 +++++--- UI/SOGoUI/UIxComponent.m | 10 ++++++++++ UI/WebServerResources/js/Common/utils.js | 1 + 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/UI/Common/UIxPageFrame.m b/UI/Common/UIxPageFrame.m index 0be91ece9..3c1ef68d9 100644 --- a/UI/Common/UIxPageFrame.m +++ b/UI/Common/UIxPageFrame.m @@ -232,6 +232,11 @@ // Add strings from Locale NSDictionary *moreStrings; + // AM/PM + moreStrings = [NSDictionary dictionaryWithObjects: [locale objectForKey: NSAMPMDesignation] + forKeys: [UIxComponent amPmLabelKeys]]; + [strings addEntriesFromDictionary: moreStrings]; + // Month names moreStrings = [NSDictionary dictionaryWithObjects: [locale objectForKey: NSMonthNameArray] forKeys: [UIxComponent monthLabelKeys]]; diff --git a/UI/SOGoUI/UIxComponent.h b/UI/SOGoUI/UIxComponent.h index 7052d315f..f4e5531c2 100644 --- a/UI/SOGoUI/UIxComponent.h +++ b/UI/SOGoUI/UIxComponent.h @@ -1,14 +1,15 @@ /* Copyright (C) 2000-2005 SKYRIX Software AG + Copyright (C) 2007-2016 Inverse inc. - This file is part of OpenGroupware.org. + This file is part of SOGo - OGo is free software; you can redistribute it and/or modify it under + SOGo is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - OGo is distributed in the hope that it will be useful, but WITHOUT ANY + SOGo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. @@ -46,6 +47,7 @@ NSArray *languages; } ++ (NSArray *) amPmLabelKeys; + (NSArray *) monthLabelKeys; + (NSArray *) abbrMonthLabelKeys; diff --git a/UI/SOGoUI/UIxComponent.m b/UI/SOGoUI/UIxComponent.m index 0dad42a3d..75f5b87a6 100644 --- a/UI/SOGoUI/UIxComponent.m +++ b/UI/SOGoUI/UIxComponent.m @@ -64,6 +64,7 @@ @implementation UIxComponent +static NSMutableArray *amPmLabelKeys = nil; static NSMutableArray *dayLabelKeys = nil; static NSMutableArray *abbrDayLabelKeys = nil; static NSMutableArray *monthLabelKeys = nil; @@ -72,6 +73,10 @@ static SoProduct *commonProduct = nil; + (void)initialize { if (dayLabelKeys == nil) { + amPmLabelKeys = [[NSMutableArray alloc] initWithCapacity:2]; + [amPmLabelKeys addObject:@"AM"]; + [amPmLabelKeys addObject:@"PM"]; + dayLabelKeys = [[NSMutableArray alloc] initWithCapacity:7]; [dayLabelKeys addObject:@"Sunday"]; [dayLabelKeys addObject:@"Monday"]; @@ -124,6 +129,11 @@ static SoProduct *commonProduct = nil; } } ++ (NSArray *) amPmLabelKeys +{ + return (NSArray *) amPmLabelKeys; +} + + (NSArray *) abbrDayLabelKeys { return (NSArray *) abbrDayLabelKeys; diff --git a/UI/WebServerResources/js/Common/utils.js b/UI/WebServerResources/js/Common/utils.js index 4f4e822ea..da9355cb7 100644 --- a/UI/WebServerResources/js/Common/utils.js +++ b/UI/WebServerResources/js/Common/utils.js @@ -394,6 +394,7 @@ Date.prototype.format = function(localeProvider, format) { '%H': this.getHours(), // hour (00..23) '%M': this.getMinutes() }; // minute (00..59) val['%I'] = val['%H'] > 12 ? val['%H'] % 12 : val['%H']; // hour (01..12) + val['%p'] = val['%H'] < 12 ? l('AM') : l('PM'); // locale's equivalent of either AM or PM val['%d'] = (val['%d'] < 10 ? '0' : '') + val['%d']; val['%e'] = (val['%e'] < 10 ? ' ' : '') + val['%e'];