Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TimePicker now defaults in hour24 mode to value as in am mode. #399

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,18 @@ public void setOkText(String okText) {
reload();
}
}

/**
* Set the "Default" on TimePicker
*/

public void setStartTime(Date startTime) {
options.startTime = DateTimeFormat.getFormat(options.hour24 ? "HH:mm" : "hh:mm aa").format(startTime);
}

public void setStartTime(String startTimeStr) {
options.startTime = startTimeStr;
}

@Override
public MaterialIcon getIcon() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,7 @@ public class JsTimePickerOptions {

@JsProperty
public String okText;

@JsProperty
public String startTime;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@
package gwt.material.design.incubator.client.daterange.js;

import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.json.client.JSONString;

import jsinterop.annotations.JsOverlay;
import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsProperty;
import jsinterop.annotations.JsType;

import java.util.List;

/**
* @author kevzlou7979
* @see {@link gwt.material.design.incubator.client.daterange.DateRangePicker#setLocale(DateRangeLocale)}
Expand Down Expand Up @@ -67,7 +64,7 @@ public class DateRangeLocale {
private LocaleString[] monthNames;

@JsProperty
private String firstDay;
private int firstDay;

@JsOverlay
public final void setFormat(String format) {
Expand Down Expand Up @@ -123,7 +120,7 @@ public final void setMonthNames(LocaleString[] monthNames) {
}
}
@JsOverlay
public final void setFirstDay(String firstDay) {
public final void setFirstDay(int firstDay) {
this.firstDay = firstDay;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
See the License for the specific language governing permissions and
limitations under the License.
#L%
-->


<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.7.0//EN"
"http://gwtproject.org/doctype/2.7.0/gwt-module.dtd">
-->
<module rename-to='GwtMaterialAddins'>
<inherits name="gwt.material.design.addins.GwtMaterialAddinsBase"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
See the License for the specific language governing permissions and
limitations under the License.
#L%
-->


<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.7.0//EN"
"http://gwtproject.org/doctype/2.7.0/gwt-module.dtd">
-->
<module rename-to='GwtMaterialAddins'>
<set-configuration-property name="CssResource.conversionMode" value="strict" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
See the License for the specific language governing permissions and
limitations under the License.
#L%
-->

<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.7.0//EN"
"http://gwtproject.org/doctype/2.7.0/gwt-module.dtd">
-->
<module rename-to='GwtMaterialAddins'>
<inherits name="gwt.material.design.addins.GwtMaterialAddinsBase"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
See the License for the specific language governing permissions and
limitations under the License.
#L%
-->


<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.7.0//EN"
"http://gwtproject.org/doctype/2.7.0/gwt-module.dtd">
-->
<module rename-to='GwtMaterialAddins'>
<replace-with class="gwt.material.design.addins.client.StartupState.DebugState">
<when-type-is class="gwt.material.design.addins.client.StartupState"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
See the License for the specific language governing permissions and
limitations under the License.
#L%
-->


<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.7.0//EN"
"http://gwtproject.org/doctype/2.7.0/gwt-module.dtd">
-->
<module rename-to='GwtMaterialAddins'>
<replace-with class="gwt.material.design.addins.client.StartupState.DebugState">
<when-type-is class="gwt.material.design.addins.client.StartupState"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*!
* Lolliclock v0.1.0
* Matthew Krick 2015
* Volker Kubitz 2020 added startTime for hour24 mode
* Inspired by Google's material design & ClockPicker v0.0.7 (http://weareoutman.github.io/clockpicker/)
*/

Expand Down Expand Up @@ -444,37 +445,37 @@
});

//Get the time
function timeToDate(time) {
function timeToDate(time,hour24) {
var parts = time.split(':');
if (parts.length === 2){
var hours = +parts[0];
var minAM = parts[1].split(' ');
if (minAM.length === 2) {
if (minAM.length === 2||(hour24&&minAM.length === 1)) {
var mins = minAM[0];
if (minAM[1] === 'PM') hours += 12;
if (!hour24&&minAM[1] === 'PM') hours += 12;
return new Date(1970, 1, 1, hours, mins);
}
}
return new Date('x');
}

function isValidTime(time) {
return !isNaN(timeToDate(time).getTime());
function isValidTime(time,hour24) {
return !isNaN(timeToDate(time,hour24).getTime());
}

var value;
var inputValue = this.input.prop('value');
var defaultValue = this.options.startTime;
var placeholderValue = this.input.prop('placeholder');

if (inputValue && isValidTime(inputValue)) {
value = timeToDate(inputValue);
if (inputValue && isValidTime(inputValue,this.options.hour24)) {
value = timeToDate(inputValue,this.options.hour24);
} else if (defaultValue === 'now') {
value = new Date();
} else if (defaultValue && isValidTime(defaultValue)) {
value = timeToDate(defaultValue);
} else if (placeholderValue && isValidTime(placeholderValue)) {
value = timeToDate(placeholderValue);
} else if (defaultValue && isValidTime(defaultValue,this.options.hour24)) {
value = timeToDate(defaultValue,this.options.hour24);
} else if (placeholderValue && isValidTime(placeholderValue,this.options.hour24)) {
value = timeToDate(placeholderValue,this.options.hour24);
} else {
value = new Date();
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
See the License for the specific language governing permissions and
limitations under the License.
#L%
-->


<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.7.0//EN"
"http://gwtproject.org/doctype/2.7.0/gwt-module.dtd">
-->
<module rename-to='AddinsIncubator'>
<inherits name="gwt.material.design.addins.GwtMaterialAddinsBase"/>
<inherits name="com.google.gwt.json.JSON"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
See the License for the specific language governing permissions and
limitations under the License.
#L%
-->


<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.7.0//EN"
"http://gwtproject.org/doctype/2.7.0/gwt-module.dtd">
-->
<module rename-to='GwtMaterialAddins'>
<replace-with class="gwt.material.design.addins.client.StartupState.DebugState">
<when-type-is class="gwt.material.design.addins.client.StartupState"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
<!--
When updating your version of GWT, you should also update this DTD reference,
so that your app can take advantage of the latest GWT module capabilities.
-->

<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.8.0//EN"
"http://gwtproject.org/doctype/2.8.0/gwt-module.dtd">
-->
<module>
<!-- Include all public css and icons files -->
<public path="public"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
<!--
When updating your version of GWT, you should also update this DTD reference,
so that your app can take advantage of the latest GWT module capabilities.
-->

<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.8.0//EN"
"http://gwtproject.org/doctype/2.8.0/gwt-module.dtd">
-->
<module>
<!-- Include all public css and icons files -->
<public path="public"/>
Expand Down