All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.vaadin.data.converter.DateToLongConverter Maven / Gradle / Ivy

There is a newer version: 8.27.3
Show newest version
/*
 * Copyright (C) 2000-2024 Vaadin Ltd
 *
 * This program is available under Vaadin Commercial License and Service Terms.
 *
 * See  for the full
 * license.
 */

package com.vaadin.data.converter;

import java.util.Date;

import com.vaadin.data.Converter;
import com.vaadin.data.Result;
import com.vaadin.data.ValueContext;

/**
 * A converter that converts from {@link Long} to {@link Date} and back.
 *
 * @author Vaadin Ltd
 * @since 8.0
 */
public class DateToLongConverter implements Converter {

    @Override
    public Result convertToModel(Date value, ValueContext context) {
        if (value == null) {
            return Result.ok(null);
        }

        return Result.ok(value.getTime());
    }

    @Override
    public Date convertToPresentation(Long value, ValueContext context) {
        if (value == null) {
            return null;
        }

        return new Date(value);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy