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

com.uwetrottmann.tmdb2.entities.TmdbDate Maven / Gradle / Ivy

The newest version!
package com.uwetrottmann.tmdb2.entities;

import com.uwetrottmann.tmdb2.TmdbHelper;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class TmdbDate {

    // can not use ThreadLocal.withInitial as it requires Java 8
    private static final ThreadLocal TMDB_DATE_FORMAT = new ThreadLocal() {
        @Override
        public DateFormat initialValue() {
            return new SimpleDateFormat(TmdbHelper.TMDB_DATE_PATTERN);
        }
    };

    private final Date date;

    public TmdbDate(Date date) {
        this.date = date;
    }

    public TmdbDate(String date) {
        Date parsedDate;
        try {
            parsedDate = TMDB_DATE_FORMAT.get().parse(date);
        } catch (ParseException e) {
            parsedDate = null;
        }
        this.date = parsedDate;
    }

    @Override
    public String toString() {
        return TMDB_DATE_FORMAT.get().format(date);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy