List of usage examples for com.google.gwt.i18n.client DateTimeFormat parse
public Date parse(String text) throws IllegalArgumentException
From source file:co.fxl.data.format.gwt.GWTDateFormat.java
License:Open Source License
private Date internalParse(DateTimeFormat dateTimeFormat, String pDateString) { try {// ww w. j a v a2 s . c o m // Parse Date for utc timezone Date date = dateTimeFormat.parse(pDateString + " UTC"); // Convert date to timezone return addTimezoneOffset(date); } catch (Exception e) { return null; } }
From source file:com.bramosystems.oss.player.playlist.client.impl.XSPFHandler.java
License:Apache License
@Override public void setNodeValue(String nodeName, String value) throws ParseException { try {//from w w w. j a v a 2s . com switch (XSPFNodeNames.valueOf(nodeName.toLowerCase())) { case title: switch (parentNode) { case playlist: playlist.setTitle(value); break; case track: track.setTitle(value); } break; case creator: switch (parentNode) { case playlist: playlist.setCreator(value); break; case track: track.setCreator(value); } break; case annotation: switch (parentNode) { case playlist: playlist.setAnnotation(value); break; case track: track.setAnnotation(value); } break; case info: switch (parentNode) { case playlist: playlist.setInfo(value); break; case track: track.setInfo(value); } break; case location: switch (parentNode) { case playlist: playlist.setLocation(value); break; case track: track.getLocation().push(value); break; case attribution: attribution.setLocation(value); } break; case identifier: switch (parentNode) { case playlist: playlist.setIdentifier(value); break; case attribution: attribution.setIdentifier(value); break; case track: track.getIdentifier().push(value); } break; case image: switch (parentNode) { case playlist: playlist.setImage(value); break; case track: track.setImage(value); } break; case date: switch (parentNode) { case playlist: DateTimeFormat dt = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.ISO_8601); playlist.setDate(dt.parse(value)); break; } break; case license: switch (parentNode) { case playlist: playlist.setLicense(value); break; } break; case album: switch (parentNode) { case track: track.setAlbum(value); break; } break; case tracknum: switch (parentNode) { case track: track.setTrackNumber(Double.parseDouble(value)); break; } break; case duration: switch (parentNode) { case track: track.setDuration(Double.parseDouble(value)); break; } break; } } catch (Exception e) { throw new ParseException("Parse Error : " + nodeName, e); } }
From source file:com.chap.links.client.GraphDemo1_basic_usage.java
License:Apache License
/** * This is the entry point method./* w w w . j ava2s . c om*/ */ public void onModuleLoad() { // Create a callback to be called when the visualization API // has been loaded. Runnable onLoadCallback = new Runnable() { public void run() { // Create and populate a data table. DataTable data = DataTable.create(); data.addColumn(DataTable.ColumnType.DATETIME, "time"); data.addColumn(DataTable.ColumnType.NUMBER, "Function A"); data.addColumn(DataTable.ColumnType.NUMBER, "Function B"); DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy-MM-dd"); // create data Date d = dtf.parse("2010-08-23"); int n = 200; // number of datapoints for (int i = 0; i < n; i++) { data.addRow(); data.setValue(i, 0, new Date(d.getTime())); data.setValue(i, 1, customFunctionA(i)); data.setValue(i, 2, customFunctionB(i)); d.setTime(d.getTime() + 1000 * 60); // steps of one minute } Graph.Options options = Graph.Options.create(); options.setHeight("400px"); options.setLineStyle(Graph.Options.LINESTYLE.DOT, 1); options.setLineColor("blue", 1); options.setLineLegend(false, 0); // create the graph, with data and options chart = new Graph(data, options); RootPanel.get("mygraph").add(chart); } }; // Load the visualization api, passing the onLoadCallback to be called // when loading is done. VisualizationUtils.loadVisualizationApi(onLoadCallback); }
From source file:com.chap.links.client.GraphDemo2_interactive_and_custom_css.java
License:Apache License
/** * This is the entry point method.//from www .jav a 2 s .c o m */ public void onModuleLoad() { // Create a callback to be called when the visualization API // has been loaded. Runnable onLoadCallback = new Runnable() { public void run() { RootPanel.get("txtStartDate").add(txtStartDate); RootPanel.get("txtEndDate").add(txtEndDate); RootPanel.get("btnSetRange").add(btnSetRange); // Add a handler to the add button btnSetRange.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { setRange(); } }); // Create and populate a data table. DataTable data = DataTable.create(); data.addColumn(DataTable.ColumnType.DATETIME, "time"); data.addColumn(DataTable.ColumnType.NUMBER, "Function A"); data.addColumn(DataTable.ColumnType.NUMBER, "Function B"); DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy-MM-dd"); // create data Date d = dtf.parse("2010-08-23"); int n = 10000; // number of datapoints for (int i = 0; i < n; i++) { data.addRow(); data.setValue(i, 0, new Date(d.getTime())); data.setValue(i, 1, customFunction(i)); data.setValue(i, 2, customFunction2(i)); d.setTime(d.getTime() + 1000 * 60); // steps of one minute } Graph.Options options = Graph.Options.create(); options.setHeight("400px"); options.setVerticalStep(10); options.setLegendCheckboxes(true); //options.setScale(Graph.Options.SCALE.HOUR, 2); options.setLineColor("red", 1); options.setLineStyle(Graph.Options.LINESTYLE.DOT, 0); options.setLineRadius(1.0, 0); options.setLineColor("blue", 0); // create the linechart, with data and options graph = new Graph(data, options); // add event handlers graph.addRangeChangeHandler(createRangeChangeHandler(graph)); RootPanel.get("mygraph").add(graph); getRange(); } }; // Load the visualization api, passing the onLoadCallback to be called // when loading is done. VisualizationUtils.loadVisualizationApi(onLoadCallback); }
From source file:com.chap.links.client.GraphDemo2_interactive_and_custom_css.java
License:Apache License
/** * Get the entered dates from the textboxes on screen, and apply them to * the timeline// www .j ava 2 s. c o m */ private void setRange() { DateTimeFormat datetime = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss"); DateTimeFormat date = DateTimeFormat.getFormat("yyyy-MM-dd"); Date startDate; Date endDate; // Try to parse the startdate try { startDate = datetime.parse(txtStartDate.getText()); } catch (IllegalArgumentException err) { try { startDate = date.parse(txtStartDate.getText()); } catch (IllegalArgumentException err2) { Window.alert("I don't understand the startdate that you entered :("); return; } } // Try to parse the enddate try { endDate = datetime.parse(txtEndDate.getText()); } catch (IllegalArgumentException err) { try { endDate = date.parse(txtEndDate.getText()); } catch (IllegalArgumentException err2) { Window.alert("I cannot make sense of the enddate that you entered :("); return; } } graph.setVisibleChartRange(startDate, endDate); graph.redraw(); }
From source file:com.chap.links.client.GraphDemo3_offline.java
License:Apache License
/** * This is the entry point method./*from ww w . jav a 2s . co m*/ */ public void onModuleLoad() { DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy-MM-dd"); JSONArray dataA = new JSONArray(); JSONArray dataB = new JSONArray(); // create data Date d = dtf.parse("2012-08-23"); int n = 200; // number of datapoints for (int i = 0; i < n; i++) { JSONObject pointA = new JSONObject(); pointA.put("date", new JSONNumber(d.getTime())); pointA.put("value", new JSONNumber(customFunctionA(i))); dataA.set(i, pointA); JSONObject pointB = new JSONObject(); pointB.put("date", new JSONNumber(d.getTime())); pointB.put("value", new JSONNumber(customFunctionB(i))); dataB.set(i, pointB); d.setTime(d.getTime() + 1000 * 60); // steps of one minute } JSONObject dataSetA = new JSONObject(); dataSetA.put("label", new JSONString("Function A")); dataSetA.put("data", dataA); JSONObject dataSetB = new JSONObject(); dataSetB.put("label", new JSONString("Function B")); dataSetB.put("data", dataB); Graph.Options options = Graph.Options.create(); options.setHeight("400px"); options.setLineStyle(Graph.Options.LINESTYLE.DOT, 1); options.setLineColor("blue", 1); options.setLineLegend(false, 0); JSONArray data = new JSONArray(); data.set(0, dataSetA); data.set(1, dataSetB); // create the graph, with data and options chart = new Graph(data.getJavaScriptObject(), options); RootPanel.get("mygraph").add(chart); }
From source file:com.chap.links.client.GraphEntryPoint.java
License:Apache License
/** * This is the entry point method.// w w w . ja va2 s . c o m */ public void onModuleLoad() { // Create a callback to be called when the visualization API // has been loaded. Runnable onLoadCallback = new Runnable() { public void run() { RootPanel.get("txtStartDate").add(txtStartDate); RootPanel.get("txtEndDate").add(txtEndDate); RootPanel.get("btnSetRange").add(btnSetRange); Button btnAutoRange = new Button("Auto Range"); btnAutoRange.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { graph.setValueRangeAuto(); graph.setVisibleChartRangeAuto(); } }); RootPanel.get("btnAutoRange").add(btnAutoRange); // Add a handler to the add button btnSetRange.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { setRange(); } }); // Create and populate a data table. DataTable data = DataTable.create(); data.addColumn(DataTable.ColumnType.DATETIME, "time"); data.addColumn(DataTable.ColumnType.NUMBER, "Function A"); data.addColumn(DataTable.ColumnType.NUMBER, "Function B"); DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy-MM-dd"); // create data Date d = dtf.parse("2010-08-23"); int n = 1000; // number of datapoints for (int i = 0; i < n; i++) { data.addRow(); data.setValue(i, 0, new Date(d.getTime())); data.setValue(i, 1, customFunction(i) / 100); data.setValue(i, 2, customFunction2(i) / 100); d.setTime(d.getTime() + 1000 * 60); // steps of one minute } Graph.Options options = Graph.Options.create(); options.setHeight("400px"); options.setLegendCheckboxes(true); //options.setVerticalStep(10); //options.setScale(Graph.Options.SCALE.HOUR, 2); options.setLineStyle(Graph.Options.LINESTYLE.DOT, 0); options.setLineRadius(1.0, 0); options.setLineColor("#FFA500", 0); options.setLineVisibe(false, 1); options.setLineColor("#FF0000", 1); options.setLineStyle(Graph.Options.LINESTYLE.DOTLINE); options.setVerticalMin(-1); options.setVerticalMax(1); options.setMin(dtf.parse("2010-08-22")); options.setMax(dtf.parse("2010-08-24")); options.setZoomMin(1000L * 60L * 60L); /* String json = "[{ " + " \"label\" : \"Dataset A\", " + " \"data\" : [" + " {\"date\": 1281823200000, \"value\" : 12.5}," + " {\"date\": 1281909600000, \"value\" : 3.5}" + " ]" + " }," + " {" + " \"label\" : \"Dataset B\"," + " \"data\" : [" + " {\"date\": 1281823200000, \"value\" : 3.2}," + " {\"date\": 1281996000000, \"value\" : 6.1}" + " ]" + " }]"; JavaScriptObject jsonData = JsonUtils.safeEval(json); */ // create the linechart, with data and options graph = new Graph(data, options); //graph.draw(jso, options); // add event handlers graph.addRangeChangeHandler(createRangeChangeHandler(graph)); RootPanel.get("mygraph").add(graph); getRange(); } }; // Load the visualization api, passing the onLoadCallback to be called // when loading is done. VisualizationUtils.loadVisualizationApi(onLoadCallback); }
From source file:com.chinarewards.gwt.license.util.DateTool.java
/** * N?//w w w . jav a 2s .c o m * * @param date * @param day * @return */ public static Date addSomeMonth(Date date, int intervalMonth) { // FIXME harry implement it DateTimeFormat formatYMD = DateTimeFormat.getFormat("yyyy-MM-dd"); DateTimeFormat formatM = DateTimeFormat.getFormat("MM"); DateTimeFormat formatY = DateTimeFormat.getFormat("yyyy"); DateTimeFormat formatD = DateTimeFormat.getFormat("dd"); String month = formatM.format(date); String year = formatY.format(date); String day = formatD.format(date); if (intervalMonth > 12) { int y = intervalMonth / 12; intervalMonth = intervalMonth % 12; year = (Integer.parseInt(year) + y) + ""; } int mon = Integer.parseInt(month) + intervalMonth; if (mon > 12) { mon = mon - 12; year = (Integer.parseInt(year) + 1) + ""; } int threeMontyAfterDay = getDaysOfMonth(Integer.parseInt(year), mon); if (Integer.parseInt(day) > threeMontyAfterDay) { day = threeMontyAfterDay + ""; } month = (mon < 10) ? "0" + mon : mon + ""; return formatYMD.parse(year + "-" + month + "-" + day); }
From source file:com.edgenius.wiki.gwt.client.widgets.CalendarDetailDialog.java
License:Open Source License
public void onClick(ClickEvent evt) { if (evt.getSource() == isAllDayEvent) { onAllDayEvent();//from w w w . ja v a2s . c o m } else if (evt.getSource() == okBtn) { this.hidebox(); } else if (evt.getSource() == cancelBtn) { this.hidebox(); } else if (evt.getSource() == saveBtn) { PluginControllerAsync action = ControllerFactory.getPluginController(); try { if (StringUtil.isEmpty((subject.getText()))) { message.error("Please input event subject."); return; } DateTimeFormat format = DateTimeFormat.getFormat("MM/dd/yyyy hh:mm"); Date st = format.parse( StringUtil.trimToEmpty(sdate.getText()) + " " + StringUtil.trimToEmpty(stime.getText())); Date ed = format.parse( StringUtil.trimToEmpty(edate.getText()) + " " + StringUtil.trimToEmpty(etime.getText())); if (!isAllDayEvent.getValue() && (ed.before(st) || st.equals(ed))) { message.error("End time must greater than start time."); return; } //TODO String repeatRule = ""; action.request(PageMain.getSpaceUname(), PageMain.getPageUuid(), "calendarService", "saveEvent", new String[] { pageUuid.getValue(), calendarName.getValue(), eventID.getValue(), color.getValue(), subject.getText(), String.valueOf(st.getTime()), String.valueOf(ed.getTime()), location.getText(), description.getText(), String.valueOf(isAllDayEvent.getValue()), repeatRule }, this); this.hidebox(); } catch (Exception e) { message.error("Invalid date format. Expect MM/dd/yyyy hh:mm"); } } }
From source file:com.extjs.gxt.samples.resources.client.ResourcesData.java
License:Open Source License
public static List<Stock> getCompanies() { DateTimeFormat f = DateTimeFormat.getFormat("M/d h:mma"); List<Stock> stocks = new ArrayList<Stock>(); stocks.add(new Stock("3m Co", 71.72, 0.02, 0.03, f.parse("4/2 12:00am"), "Manufacturing")); stocks.add(new Stock("Alcoa Inc", 29.01, 0.42, 1.47, f.parse("4/1 12:00am"), "Manufacturing")); stocks.add(new Stock("Altria Group Inc", 83.81, 0.28, 0.34, f.parse("4/3 12:00am"), "Manufacturing")); stocks.add(new Stock("American Express Company", 52.55, 0.01, 0.02, f.parse("4/8 12:00am"), "Finance")); stocks.add(new Stock("American International Group, Inc.", 64.13, 0.31, 0.49, f.parse("4/1 12:00am"), "Services")); stocks.add(new Stock("AT&T Inc.", 31.61, -0.48, -1.54, f.parse("4/8 12:00am"), "Services")); stocks.add(new Stock("Boeing Co.", 75.43, 0.53, 0.71, f.parse("4/8 12:00am"), "Manufacturing")); stocks.add(new Stock("Caterpillar Inc.", 67.27, 0.92, 1.39, f.parse("4/1 12:00am"), "Services")); stocks.add(new Stock("Citigroup, Inc.", 49.37, 0.02, 0.04, f.parse("4/4 12:00am"), "Finance")); stocks.add(new Stock("E.I. du Pont de Nemours and Company", 40.48, 0.51, 1.28, f.parse("4/1 12:00am"), "Manufacturing")); stocks.add(new Stock("Exxon Mobil Corp", 68.1, -0.43, -0.64, f.parse("4/3 12:00am"), "Manufacturing")); stocks.add(new Stock("General Electric Company", 34.14, -0.08, -0.23, f.parse("4/3 12:00am"), "Manufacturing")); stocks.add(// w ww. j a va2 s.c o m new Stock("General Motors Corporation", 30.27, 1.09, 3.74, f.parse("4/3 12:00am"), "Automotive")); stocks.add(new Stock("Hewlett-Packard Co.", 36.53, -0.03, -0.08, f.parse("4/3 12:00am"), "Computer")); stocks.add(new Stock("Honeywell Intl Inc", 38.77, 0.05, 0.13, f.parse("4/3 12:00am"), "Manufacturing")); stocks.add(new Stock("Intel Corporation", 19.88, 0.31, 1.58, f.parse("4/2 12:00am"), "Computer")); stocks.add(new Stock("International Business Machines", 81.41, 0.44, 0.54, f.parse("4/1 12:00am"), "Computer")); stocks.add(new Stock("Johnson & Johnson", 64.72, 0.06, 0.09, f.parse("4/2 12:00am"), "Medical")); stocks.add(new Stock("JP Morgan & Chase & Co", 45.73, 0.07, 0.15, f.parse("4/2 12:00am"), "Finance")); stocks.add(new Stock("McDonald\"s Corporation", 36.76, 0.86, 2.40, f.parse("4/2 12:00am"), "Food")); stocks.add(new Stock("Merck & Co., Inc.", 40.96, 0.41, 1.01, f.parse("4/2 12:00am"), "Medical")); stocks.add(new Stock("Microsoft Corporation", 25.84, 0.14, 0.54, f.parse("4/2 12:00am"), "Computer")); stocks.add(new Stock("Pfizer Inc", 27.96, 0.4, 1.45, f.parse("4/8 12:00am"), "Services")); stocks.add(new Stock("The Coca-Cola Company", 45.07, 0.26, 0.58, f.parse("4/1 12:00am"), "Food")); stocks.add(new Stock("The Home Depot, Inc.", 34.64, 0.35, 1.02, f.parse("4/8 12:00am"), "Retail")); stocks.add(new Stock("The Procter & Gamble Company", 61.91, 0.01, 0.02, f.parse("4/1 12:00am"), "Manufacturing")); stocks.add(new Stock("United Technologies Corporation", 63.26, 0.55, 0.88, f.parse("4/1 12:00am"), "Computer")); stocks.add(new Stock("Verizon Communications", 35.57, 0.39, 1.11, f.parse("4/3 12:00am"), "Services")); stocks.add(new Stock("Wal-Mart Stores, Inc.", 45.45, 0.73, 1.63, f.parse("4/3 12:00am"), "Retail")); stocks.add(new Stock("Walt Disney Company (The) (Holding Company)", 29.89, 0.24, 0.81, f.parse("4/1 12:00am"), "Services")); return stocks; }