Directory

← Back

NaturalDate

A date field that understands natural-language input (e.g "next friday at eleven")

Author

Rating

Popularity

<100

NaturalDate is a date input field that accepts natural language input, allowing the user to input dates (and times) such as "next friday", "tomorrow at nine", etc.

The component uses the now defunct JChronic library (which in turn is a Java version of the ruby Chronic library) to parse the input on the server side. A client-side implementation is in the works and will be added to a future version.

Sample code

package org.vaadin.naturaldate;

import org.vaadin.naturaldate.NaturalDate.InvalidValueEvent;
import org.vaadin.naturaldate.NaturalDate.InvalidValueListener;

import com.mdimension.jchronic.Options;
import com.vaadin.Application;
import com.vaadin.ui.DateField;
import com.vaadin.ui.InlineDateField;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;

public class NaturaldateDemo extends Application {
    @Override
    public void init() {
        new MainWindow("NaturalDateField Demo");

    }

    private class MainWindow extends Window {
        MainWindow(String caption) {
            super(caption);
            setMainWindow(this);
            ((VerticalLayout) getContent()).setSpacing(true);

            // This is the NaturalDate component
            NaturalDate nd = new NaturalDate("Natural date");
            addComponent(nd);
            nd.setValue("2nd tuesday this month");
            Options o = new Options();
            o.setDebug(true);
            nd.setOptions(o);
            nd.setWidth("240px");
            nd.setInputPrompt("When?");
            nd.setImmediate(true);
            nd.addListener(new InvalidValueListener() {
                public void invalidValue(InvalidValueEvent event) {
                    getMainWindow().showNotification("InvalidValue",
                            event.getInvalidValue(),
                            Notification.TYPE_WARNING_MESSAGE);
                }
            });

            // ...connect to regular DateField to show everything is working
            DateField d = new InlineDateField("Interpreted date");
            d.setImmediate(true);
            addComponent(d);
            d.setPropertyDataSource(nd);

        }
    }

}

Compatibility

(Loading compatibility data...)

Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.

Version

Released
2010-01-22
Maturity
EXPERIMENTAL
License
Apache License 2.0

Compatibility

Framework
Vaadin 6.0+
Browser
N/A

NaturalDate - Vaadin Add-on Directory

A date field that understands natural-language input (e.g "next friday at eleven") NaturalDate - Vaadin Add-on Directory
NaturalDate is a date input field that accepts natural language input, allowing the user to input dates (and times) such as "next friday", "tomorrow at nine", etc. The component uses the now defunct JChronic library (which in turn is a Java version of the ruby Chronic library) to parse the input on the server side. A client-side implementation is in the works and will be added to a future version.
Project on Google Code
Live demo

NaturalDate version 0.1
null

Online