001/* 002 * #%L 003 * GwtMaterial 004 * %% 005 * Copyright (C) 2015 - 2018 GwtMaterialDesign 006 * %% 007 * Licensed under the Apache License, Version 2.0 (the "License"); 008 * you may not use this file except in compliance with the License. 009 * You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 * #L% 019 */ 020package gwt.material.design.client.base.helper; 021 022/** 023 * Basic Date Format helper to support Java Based formats into <a href="http://amsul.ca/pickadate.js/date/#formats">Pickadate.js formats</a> 024 * As of {@link gwt.material.design.client.ui.MaterialDatePicker} 2.0 we just supported the conversion of uppercase 025 * formats to convert it to lower case for the basic support. 026 * 027 * @author kevzlou7979@gmail.com 028 */ 029public class DateFormatHelper { 030 031 static String DEFAULT_FORMAT = "d mmmm, yyyy"; 032 033 /** 034 * Will auto format the given string to provide support for pickadate.js formats. 035 */ 036 public static String format(String format) { 037 038 if (format == null) { 039 format = DEFAULT_FORMAT; 040 } else { 041 if (format.contains("M")) { 042 format = format.replace("M", "m"); 043 } 044 045 if (format.contains("Y")) { 046 format = format.replace("Y", "y"); 047 } 048 049 if (format.contains("D")) { 050 format = format.replace("D", "d"); 051 } 052 } 053 return format; 054 } 055}