TimeWidget angepaßt, so daß es sich

* der eingestellten Locale anpaßt (12-Stunden vs. 24-Stunden-Format)
* Event angepaßt, so daß die Anzeige sich ebenfalls anpaßt (AttributeFormatter angepaßt). Diese Anpassung muß evt. bei allen PropertiesStep gemacht werden, die Datumsangaben verwenden oder es wir finden eine bessere Lösung, so daß man den AttributeFormatter nicht jedesmal neu schreiben muß.

git-svn-id: https://svn.libreccm.org/ccm/trunk@705 8810af33-2d31-482b-a856-94f89814c4df
master
quasi 2011-01-22 14:44:03 +00:00
parent 6eaabaf7fa
commit 8f2246aba2
4 changed files with 177 additions and 164 deletions

View File

@ -34,6 +34,7 @@ import com.arsdigita.cms.ui.authoring.SimpleEditStep;
import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess; import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess;
// replaced by AgendaGlobalizationUtil // replaced by AgendaGlobalizationUtil
// import com.arsdigita.cms.util.GlobalizationUtil; // import com.arsdigita.cms.util.GlobalizationUtil;
import com.arsdigita.dispatcher.DispatcherHelper;
import java.text.DateFormat; import java.text.DateFormat;
@ -91,7 +92,7 @@ public class AgendaPropertiesStep extends SimpleEditStep {
PageState state) { PageState state) {
ContentPage page = (ContentPage) item; ContentPage page = (ContentPage) item;
if(page.getLaunchDate() != null) { if(page.getLaunchDate() != null) {
return DateFormat.getDateInstance(DateFormat.LONG) return DateFormat.getDateInstance(DateFormat.LONG, DispatcherHelper.getNegotiatedLocale())
.format(page.getLaunchDate()); .format(page.getLaunchDate());
} else { } else {
return (String)AgendaGlobalizationUtil.globalize("cms.ui.unknown").localize(); return (String)AgendaGlobalizationUtil.globalize("cms.ui.unknown").localize();
@ -120,7 +121,7 @@ public class AgendaPropertiesStep extends SimpleEditStep {
PageState state) { PageState state) {
Agenda agenda = (Agenda) item; Agenda agenda = (Agenda) item;
if(agenda.getCreationDate() != null) { if(agenda.getCreationDate() != null) {
return DateFormat.getDateInstance(DateFormat.LONG) return DateFormat.getDateInstance(DateFormat.LONG, DispatcherHelper.getNegotiatedLocale())
.format(agenda.getCreationDate()); .format(agenda.getCreationDate());
} else { } else {
return (String)AgendaGlobalizationUtil.globalize("cms.ui.unknown").localize(); return (String)AgendaGlobalizationUtil.globalize("cms.ui.unknown").localize();

View File

@ -18,7 +18,6 @@
*/ */
package com.arsdigita.cms.contenttypes.ui; package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.bebop.Component; import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.PageState;
import com.arsdigita.cms.ContentPage; import com.arsdigita.cms.ContentPage;
@ -32,8 +31,13 @@ import com.arsdigita.cms.ui.authoring.BasicPageForm;
import com.arsdigita.cms.ui.authoring.SimpleEditStep; import com.arsdigita.cms.ui.authoring.SimpleEditStep;
import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess; import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess;
import com.arsdigita.cms.contenttypes.util.EventGlobalizationUtil; import com.arsdigita.cms.contenttypes.util.EventGlobalizationUtil;
import com.arsdigita.dispatcher.DispatcherHelper;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
/** /**
* Authoring step to view/edit the simple attributes of the Event content type (and * Authoring step to view/edit the simple attributes of the Event content type (and
@ -49,7 +53,7 @@ public class EventPropertiesStep extends SimpleEditStep {
public static String EDIT_SHEET_NAME = "edit"; public static String EDIT_SHEET_NAME = "edit";
public EventPropertiesStep(ItemSelectionModel itemModel, public EventPropertiesStep(ItemSelectionModel itemModel,
AuthoringKitWizard parent) { AuthoringKitWizard parent) {
super(itemModel, parent); super(itemModel, parent);
setDefaultEditKey(EDIT_SHEET_NAME); setDefaultEditKey(EDIT_SHEET_NAME);
@ -57,7 +61,7 @@ public class EventPropertiesStep extends SimpleEditStep {
editSheet = new EventPropertyForm(itemModel, this); editSheet = new EventPropertyForm(itemModel, this);
add(EDIT_SHEET_NAME, "Edit", new WorkflowLockedComponentAccess(editSheet, itemModel), add(EDIT_SHEET_NAME, "Edit", new WorkflowLockedComponentAccess(editSheet, itemModel),
editSheet.getSaveCancelSection().getCancelButton()); editSheet.getSaveCancelSection().getCancelButton());
setDisplayComponent(getEventPropertySheet(itemModel)); setDisplayComponent(getEventPropertySheet(itemModel));
} }
@ -71,102 +75,92 @@ public class EventPropertiesStep extends SimpleEditStep {
* @return A component to display the state of the basic properties * @return A component to display the state of the basic properties
* of the release * of the release
**/ **/
public static Component getEventPropertySheet(ItemSelectionModel public static Component getEventPropertySheet(ItemSelectionModel itemModel) {
itemModel) {
DomainObjectPropertySheet sheet = new DomainObjectPropertySheet(itemModel); DomainObjectPropertySheet sheet = new DomainObjectPropertySheet(itemModel);
sheet.add( (String)EventGlobalizationUtil.globalize sheet.add((String) EventGlobalizationUtil.globalize("cms.contenttypes.ui.event.name").localize(), Event.NAME);
("cms.contenttypes.ui.event.name").localize(), Event.NAME); sheet.add((String) EventGlobalizationUtil.globalize("cms.contenttypes.ui.event.title").localize(), Event.TITLE);
sheet.add( (String)EventGlobalizationUtil.globalize sheet.add((String) EventGlobalizationUtil.globalize("cms.contenttypes.ui.event.lead").localize(), Event.LEAD);
("cms.contenttypes.ui.event.title").localize(), Event.TITLE);
sheet.add( (String)EventGlobalizationUtil.globalize
("cms.contenttypes.ui.event.lead").localize(), Event.LEAD);
if (!ContentSection.getConfig().getHideLaunchDate()) { if (!ContentSection.getConfig().getHideLaunchDate()) {
sheet.add(EventGlobalizationUtil.globalize("cms.contenttypes.ui.launch_date"), sheet.add(EventGlobalizationUtil.globalize("cms.contenttypes.ui.launch_date"),
ContentPage.LAUNCH_DATE, ContentPage.LAUNCH_DATE,
new DomainObjectPropertySheet.AttributeFormatter() { new DomainObjectPropertySheet.AttributeFormatter() {
public String format(DomainObject item,
String attribute, public String format(DomainObject item,
PageState state) { String attribute,
ContentPage page = (ContentPage) item; PageState state) {
if(page.getLaunchDate() != null) { ContentPage page = (ContentPage) item;
return DateFormat.getDateInstance(DateFormat.LONG) if (page.getLaunchDate() != null) {
.format(page.getLaunchDate()); return DateFormat.getDateInstance(DateFormat.LONG, DispatcherHelper.getNegotiatedLocale()).format(page.getLaunchDate());
} else { } else {
return (String)EventGlobalizationUtil.globalize("cms.ui.unknown").localize(); return (String) EventGlobalizationUtil.globalize("cms.ui.unknown").localize();
} }
} }
}); });
} }
sheet.add( (String)EventGlobalizationUtil.globalize sheet.add((String) EventGlobalizationUtil.globalize("cms.contenttypes.ui.event.start_time").localize(), Event.START_DATE,
("cms.contenttypes.ui.event.start_time").localize(), Event.START_DATE, new DomainObjectPropertySheet.AttributeFormatter() {
new DomainObjectPropertySheet.AttributeFormatter() {
public String format(DomainObject item,
String attribute,
PageState state) {
Event e = (Event) item;
if (e.getStartDate() != null) { public String format(DomainObject item,
StringBuffer buf = new StringBuffer(); String attribute,
buf.append(DateFormat.getDateInstance(DateFormat.LONG) PageState state) {
.format(e.getStartDate())); Event e = (Event) item;
if (e.getStartTime() != null) { if (e.getStartDate() != null) {
buf.append(". " + e.getDisplayStartTime());
}
return buf.toString(); if (e.getStartTime() == null) {
} else { return DateFormat.getDateInstance(DateFormat.LONG, DispatcherHelper.getNegotiatedLocale()).format(e.getStartDate());
return "<i>unknown</i>"; } else {
} Date startDateTime = new Date(e.getStartDate().getTime() + e.getStartTime().getTime());
} return DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT, DispatcherHelper.getNegotiatedLocale()).format(startDateTime);
});
sheet.add( (String)EventGlobalizationUtil.globalize }
("cms.contenttypes.ui.event.end_time").localize(), Event.END_DATE,
new DomainObjectPropertySheet.AttributeFormatter() {
public String format(DomainObject item,
String attribute,
PageState state) {
Event e = (Event) item;
if (e.getEndDate() != null) {
StringBuffer buf = new StringBuffer();
buf.append(DateFormat.getDateInstance(DateFormat.LONG)
.format(e.getEndDate()));
if (e.getEndTime() != null) { } else {
buf.append(". " + e.getDisplayEndTime()); return (String) EventGlobalizationUtil.globalize("cms.ui.unknown").localize();
} }
}
});
return buf.toString(); sheet.add((String) EventGlobalizationUtil.globalize("cms.contenttypes.ui.event.end_time").localize(), Event.END_DATE,
} else { new DomainObjectPropertySheet.AttributeFormatter() {
return "<i>unknown</i>";
} public String format(DomainObject item,
} String attribute,
}); PageState state) {
if(!Event.getConfig().getHideDateDescription()) { Event e = (Event) item;
sheet.add( (String)EventGlobalizationUtil.globalize if (e.getEndDate() != null) {
("cms.contenttypes.ui.event.date_description").localize(), Event.EVENT_DATE);
} if (e.getEndTime() == null) {
sheet.add( (String)EventGlobalizationUtil.globalize return DateFormat.getDateInstance(DateFormat.LONG, DispatcherHelper.getNegotiatedLocale()).format(e.getEndDate());
("cms.contenttypes.ui.event.location").localize(), Event.LOCATION); } else {
Date endDateTime = new Date(e.getEndDate().getTime() + e.getEndTime().getTime());
if(!Event.getConfig().getHideMainContributor()) { return DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT, DispatcherHelper.getNegotiatedLocale()).format(endDateTime);
sheet.add( (String)EventGlobalizationUtil.globalize
("cms.contenttypes.ui.event.main_contributor").localize(), Event.MAIN_CONTRIBUTOR); }
}
if(!Event.getConfig().getHideEventType()) { } else {
sheet.add( (String)EventGlobalizationUtil.globalize return (String) EventGlobalizationUtil.globalize("cms.ui.unknown").localize();
("cms.contenttypes.ui.event.event_type").localize(), Event.EVENT_TYPE); }
} }
if(!Event.getConfig().getHideLinkToMap()) { });
sheet.add( (String)EventGlobalizationUtil.globalize if (!Event.getConfig().getHideDateDescription()) {
("cms.contenttypes.ui.event.link_to_map").localize(), Event.MAP_LINK); sheet.add((String) EventGlobalizationUtil.globalize("cms.contenttypes.ui.event.date_description").localize(), Event.EVENT_DATE);
} }
if(!Event.getConfig().getHideCost()) { sheet.add((String) EventGlobalizationUtil.globalize("cms.contenttypes.ui.event.location").localize(), Event.LOCATION);
sheet.add( (String)EventGlobalizationUtil.globalize
("cms.contenttypes.ui.event.cost").localize(), Event.COST); if (!Event.getConfig().getHideMainContributor()) {
} sheet.add((String) EventGlobalizationUtil.globalize("cms.contenttypes.ui.event.main_contributor").localize(), Event.MAIN_CONTRIBUTOR);
}
if (!Event.getConfig().getHideEventType()) {
sheet.add((String) EventGlobalizationUtil.globalize("cms.contenttypes.ui.event.event_type").localize(), Event.EVENT_TYPE);
}
if (!Event.getConfig().getHideLinkToMap()) {
sheet.add((String) EventGlobalizationUtil.globalize("cms.contenttypes.ui.event.link_to_map").localize(), Event.MAP_LINK);
}
if (!Event.getConfig().getHideCost()) {
sheet.add((String) EventGlobalizationUtil.globalize("cms.contenttypes.ui.event.cost").localize(), Event.COST);
}
return sheet; return sheet;
} }
} }

View File

@ -18,7 +18,6 @@
*/ */
package com.arsdigita.cms.contenttypes.ui; package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.bebop.Component; import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.PageState;
import com.arsdigita.cms.ContentPage; import com.arsdigita.cms.ContentPage;
@ -32,6 +31,7 @@ import com.arsdigita.cms.ui.authoring.BasicPageForm;
import com.arsdigita.cms.ui.authoring.SimpleEditStep; import com.arsdigita.cms.ui.authoring.SimpleEditStep;
import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess; import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess;
import com.arsdigita.cms.contenttypes.util.NewsItemGlobalizationUtil; import com.arsdigita.cms.contenttypes.util.NewsItemGlobalizationUtil;
import com.arsdigita.dispatcher.DispatcherHelper;
import java.text.DateFormat; import java.text.DateFormat;
@ -49,15 +49,15 @@ public class NewsItemPropertiesStep extends SimpleEditStep {
public static String EDIT_SHEET_NAME = "edit"; public static String EDIT_SHEET_NAME = "edit";
public NewsItemPropertiesStep(ItemSelectionModel itemModel, public NewsItemPropertiesStep(ItemSelectionModel itemModel,
AuthoringKitWizard parent) { AuthoringKitWizard parent) {
super(itemModel, parent); super(itemModel, parent);
setDefaultEditKey(EDIT_SHEET_NAME); setDefaultEditKey(EDIT_SHEET_NAME);
BasicPageForm editSheet; BasicPageForm editSheet;
editSheet = new NewsItemPropertyForm(itemModel,this); editSheet = new NewsItemPropertyForm(itemModel, this);
add(EDIT_SHEET_NAME, "Edit", new WorkflowLockedComponentAccess(editSheet, itemModel), add(EDIT_SHEET_NAME, "Edit", new WorkflowLockedComponentAccess(editSheet, itemModel),
editSheet.getSaveCancelSection().getCancelButton()); editSheet.getSaveCancelSection().getCancelButton());
setDisplayComponent(getNewsDomainObjectPropertySheet(itemModel)); setDisplayComponent(getNewsDomainObjectPropertySheet(itemModel));
} }
@ -71,75 +71,64 @@ public class NewsItemPropertiesStep extends SimpleEditStep {
* @return A component to display the state of the basic properties * @return A component to display the state of the basic properties
* of the item * of the item
**/ **/
public static Component getNewsDomainObjectPropertySheet(ItemSelectionModel public static Component getNewsDomainObjectPropertySheet(ItemSelectionModel itemModel) {
itemModel) {
DomainObjectPropertySheet sheet = new DomainObjectPropertySheet(itemModel); DomainObjectPropertySheet sheet = new DomainObjectPropertySheet(itemModel);
sheet.add( (String)NewsItemGlobalizationUtil.globalize sheet.add((String) NewsItemGlobalizationUtil.globalize("cms.contenttypes.ui.title").localize(), NewsItem.TITLE);
("cms.contenttypes.ui.title").localize(), NewsItem.TITLE); sheet.add((String) NewsItemGlobalizationUtil.globalize("cms.contenttypes.ui.newsitem.name").localize(), NewsItem.NAME);
sheet.add( (String)NewsItemGlobalizationUtil.globalize sheet.add((String) NewsItemGlobalizationUtil.globalize("cms.contenttypes.ui.newsitem.lead").localize(), NewsItem.LEAD);
("cms.contenttypes.ui.newsitem.name").localize(), NewsItem.NAME);
sheet.add( (String)NewsItemGlobalizationUtil.globalize
("cms.contenttypes.ui.newsitem.lead").localize(), NewsItem.LEAD);
if (!ContentSection.getConfig().getHideLaunchDate()) { if (!ContentSection.getConfig().getHideLaunchDate()) {
sheet.add(NewsItemGlobalizationUtil.globalize("cms.contenttypes.ui.launch_date"), sheet.add(NewsItemGlobalizationUtil.globalize("cms.contenttypes.ui.launch_date"),
ContentPage.LAUNCH_DATE, ContentPage.LAUNCH_DATE,
new DomainObjectPropertySheet.AttributeFormatter() { new DomainObjectPropertySheet.AttributeFormatter() {
public String format(DomainObject item,
String attribute, public String format(DomainObject item,
PageState state) { String attribute,
ContentPage page = (ContentPage) item; PageState state) {
if(page.getLaunchDate() != null) { ContentPage page = (ContentPage) item;
return DateFormat.getDateInstance(DateFormat.LONG) if (page.getLaunchDate() != null) {
.format(page.getLaunchDate()); return DateFormat.getDateInstance(DateFormat.LONG, DispatcherHelper.getNegotiatedLocale()).format(page.getLaunchDate());
} else { } else {
return (String)NewsItemGlobalizationUtil.globalize return (String) NewsItemGlobalizationUtil.globalize("cms.ui.unknown").localize();
("cms.ui.unknown").localize(); }
} }
} });
});
} }
// Show news item on homepage? // Show news item on homepage?
if (!NewsItem.getConfig().getHideHomepageField()) { if (!NewsItem.getConfig().getHideHomepageField()) {
sheet.add( (String)NewsItemGlobalizationUtil.globalize sheet.add((String) NewsItemGlobalizationUtil.globalize("cms.contenttypes.ui.newsitem.homepage").localize(),
("cms.contenttypes.ui.newsitem.homepage").localize(), NewsItem.IS_HOMEPAGE,
NewsItem.IS_HOMEPAGE, new DomainObjectPropertySheet.AttributeFormatter() {
new DomainObjectPropertySheet.AttributeFormatter() {
public String format(DomainObject item, public String format(DomainObject item,
String attribute, String attribute,
PageState state) { PageState state) {
NewsItem pr = (NewsItem) item; NewsItem pr = (NewsItem) item;
if ( pr.isHomepage().booleanValue()) { if (pr.isHomepage().booleanValue()) {
return (String) NewsItemGlobalizationUtil.globalize return (String) NewsItemGlobalizationUtil.globalize("cms.ui.yes").localize();
("cms.ui.yes").localize(); }
}
return (String) NewsItemGlobalizationUtil.globalize("cms.ui.no").localize();
return (String) NewsItemGlobalizationUtil.globalize }
("cms.ui.no").localize(); });
}
}
);
} }
sheet.add( (String)NewsItemGlobalizationUtil.globalize sheet.add((String) NewsItemGlobalizationUtil.globalize("cms.contenttypes.ui.newsitem.news_date").localize(), NewsItem.NEWS_DATE,
("cms.contenttypes.ui.newsitem.news_date").localize(), NewsItem.NEWS_DATE, new DomainObjectPropertySheet.AttributeFormatter() {
new DomainObjectPropertySheet.AttributeFormatter() {
public String format(DomainObject item, public String format(DomainObject item,
String attribute, String attribute,
PageState state) { PageState state) {
NewsItem pr = (NewsItem) item; NewsItem pr = (NewsItem) item;
if (pr.getNewsDate() != null) { if (pr.getNewsDate() != null) {
return DateFormat.getDateInstance(DateFormat.LONG) return DateFormat.getDateInstance(DateFormat.LONG, DispatcherHelper.getNegotiatedLocale()).format(pr.getNewsDate());
.format(pr.getNewsDate()); } else {
} else { return (String) NewsItemGlobalizationUtil.globalize("cms.ui.unknown").localize();
return (String)NewsItemGlobalizationUtil.globalize }
("cms.ui.unknown").localize(); }
} });
}
});
return sheet; return sheet;
} }

View File

@ -27,11 +27,15 @@ import com.arsdigita.bebop.parameters.NumberInRangeValidationListener;
import com.arsdigita.bebop.parameters.ParameterData; import com.arsdigita.bebop.parameters.ParameterData;
import com.arsdigita.bebop.parameters.ParameterModel; import com.arsdigita.bebop.parameters.ParameterModel;
import com.arsdigita.bebop.util.BebopConstants; import com.arsdigita.bebop.util.BebopConstants;
import com.arsdigita.dispatcher.DispatcherHelper;
import com.arsdigita.util.Assert; import com.arsdigita.util.Assert;
import com.arsdigita.xml.Element; import com.arsdigita.xml.Element;
import java.text.DateFormat;
import java.text.DateFormatSymbols; import java.text.DateFormatSymbols;
import java.text.ParseException;
import java.util.Calendar; import java.util.Calendar;
import java.util.Locale;
/** /**
* A class representing a time field in an HTML form. * A class representing a time field in an HTML form.
@ -57,7 +61,11 @@ public class Time extends Widget implements BebopConstants {
public HourFragment(String name, Time parent) { public HourFragment(String name, Time parent) {
super(name); super(name);
this.parent = parent; this.parent = parent;
this.addValidationListener(new NumberInRangeValidationListener(1, 12)); if (has12HourClock()) {
this.addValidationListener(new NumberInRangeValidationListener(1, 12));
} else {
this.addValidationListener(new NumberInRangeValidationListener(1, 24));
}
} }
@Override @Override
@ -71,9 +79,11 @@ public class Time extends Widget implements BebopConstants {
@Override @Override
public Object getValue(PageState ps) { public Object getValue(PageState ps) {
// Depending on locale we need to differ between 12 hour and 24 hout format if (has12HourClock()) {
// return parent.getFragmentValue(ps, Calendar.HOUR); return parent.getFragmentValue(ps, Calendar.HOUR);
return parent.getFragmentValue(ps, Calendar.HOUR_OF_DAY); } else {
return parent.getFragmentValue(ps, Calendar.HOUR_OF_DAY);
}
} }
} }
@ -178,11 +188,10 @@ public class Time extends Widget implements BebopConstants {
if (!(model instanceof TimeParameter)) { if (!(model instanceof TimeParameter)) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"The Time widget " + model.getName() + "The Time widget " + model.getName()
" must be backed by a TimeParameter parameter model"); + " must be backed by a TimeParameter parameter model");
} }
String name = model.getName(); String name = model.getName();
String nameHour = name + ".hour"; String nameHour = name + ".hour";
String nameMinute = name + ".minute"; String nameMinute = name + ".minute";
@ -267,7 +276,9 @@ public class Time extends Widget implements BebopConstants {
if (m_showSeconds) { if (m_showSeconds) {
m_second.generateXML(ps, time); m_second.generateXML(ps, time);
} }
m_amOrPm.generateXML(ps, time); if (has12HourClock()) {
m_amOrPm.generateXML(ps, time);
}
} }
@Override @Override
@ -277,7 +288,9 @@ public class Time extends Widget implements BebopConstants {
if (m_showSeconds) { if (m_showSeconds) {
m_second.setDisabled(); m_second.setDisabled();
} }
m_amOrPm.setDisabled(); if (has12HourClock()) {
m_amOrPm.setDisabled();
}
} }
@Override @Override
@ -287,7 +300,9 @@ public class Time extends Widget implements BebopConstants {
if (m_showSeconds) { if (m_showSeconds) {
m_second.setReadOnly(); m_second.setReadOnly();
} }
m_amOrPm.setReadOnly(); if (has12HourClock()) {
m_amOrPm.setReadOnly();
}
} }
/** /**
@ -319,7 +334,7 @@ public class Time extends Widget implements BebopConstants {
Calendar c = Calendar.getInstance(); Calendar c = Calendar.getInstance();
c.setTime(value); c.setTime(value);
int intVal = c.get(field); int intVal = c.get(field);
if (field == Calendar.HOUR && intVal == 0) { if (field == Calendar.HOUR && intVal == 0 && has12HourClock()) {
intVal = 12; intVal = 12;
} }
return new Integer(intVal); return new Integer(intVal);
@ -327,4 +342,18 @@ public class Time extends Widget implements BebopConstants {
} }
return null; return null;
} }
private boolean has12HourClock() {
Locale locale = DispatcherHelper.getNegotiatedLocale();
DateFormat format_12Hour = DateFormat.getTimeInstance(DateFormat.SHORT, Locale.US);
DateFormat format_locale = DateFormat.getTimeInstance(DateFormat.SHORT, locale);
String midnight = "";
try {
midnight = format_locale.format(format_12Hour.parse("12:00 AM"));
} catch (ParseException ignore) {
}
return midnight.contains("12");
}
} }