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

org.vfdtech.implementations.DateTimeUtil Maven / Gradle / Ivy

Go to download

A utilities service with generic tools implementation. Can be plugged into your java project

There is a newer version: 0.3.5
Show newest version
package org.vfdtech.implementations;

import com.fasterxml.jackson.core.JsonProcessingException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.Year;
import java.util.Date;
import java.util.List;
import org.vfdtech.exceptions.CustomException;
import org.vfdtech.interfaces.IDateTimeUtil;

/**
 *
 * @author Muhammed.Ibrahim
 */
public class DateTimeUtil implements IDateTimeUtil {
    
    private static final String NOT_AVAILABLE = "Not supported yet.";

    @Override
    public String convertDateFormat(String fromFormat, String toFormat, String dateToFormat) throws ParseException, NullPointerException, IllegalArgumentException, CustomException {
        try {
            DateFormat originalFormat = new SimpleDateFormat(fromFormat);
            DateFormat targetFormat = new SimpleDateFormat(toFormat);
            Date date = originalFormat.parse(dateToFormat);
            return targetFormat.format(date);
        } catch (ParseException | NullPointerException | IllegalArgumentException ex) {
            throw new CustomException("Wrong date format parsed - " + ex.getMessage());
        }
    }
    
    @Override
    public String convertDateFormat(String toFormat, Date dateToFormat) throws NullPointerException, IllegalArgumentException, CustomException {
        try {
            DateFormat targetFormat = new SimpleDateFormat(toFormat);
            return targetFormat.format(dateToFormat);
        } catch (NullPointerException | IllegalArgumentException ex) {
            throw new CustomException("Wrong date format parsed - " + ex.getMessage());
        }
    }
    
    @Override
    public Object getDateFromString(String dateString, Class classToBeConvertedTo) {
        throw new UnsupportedOperationException(NOT_AVAILABLE);
    }

    @Override
    public Object getDateFromString(String dateString, Class classToBeConvertedTo, String formatterString) {
        throw new UnsupportedOperationException(NOT_AVAILABLE);
    }

    @Override
    public List getDateRange(String startDate, String endDate, boolean includeCurrentDate) {
        throw new UnsupportedOperationException(NOT_AVAILABLE);
    }

    @Override
    public int getDaysInMonth(LocalDateTime dayInContext) {
        throw new UnsupportedOperationException(NOT_AVAILABLE);
    }

    @Override
    public LocalDateTime getPreviousDayFrom(LocalDateTime dayInContext) {
        throw new UnsupportedOperationException(NOT_AVAILABLE);
    }

    @Override
    public LocalDateTime getNextDayFrom(LocalDateTime dayInContext) {
        throw new UnsupportedOperationException(NOT_AVAILABLE);
    }

    @Override
    public Month getLastMonthFrom(LocalDateTime dayInContext) {
        throw new UnsupportedOperationException(NOT_AVAILABLE);
    }

    @Override
    public Month getNextMonthFrom(LocalDateTime dayInContext) {
        throw new UnsupportedOperationException(NOT_AVAILABLE);
    }

    @Override
    public LocalDateTime getTodayMidnight() {
        throw new UnsupportedOperationException(NOT_AVAILABLE);
    }

    @Override
    public LocalDateTime getFirstMidnightOfTheMonth(Month... month) {
        throw new UnsupportedOperationException(NOT_AVAILABLE);
    }

    @Override
    public LocalDateTime getFirstMidnightOfTheYear(Year... year) {
        throw new UnsupportedOperationException(NOT_AVAILABLE);
    }

    @Override
    public LocalDateTime addMinutesToNowDate(Integer somMinutes) throws ParseException {
        throw new UnsupportedOperationException(NOT_AVAILABLE);
    }

    @Override
    public LocalDateTime convertDateToString(LocalDate date, DateFormat... format) {
        throw new UnsupportedOperationException(NOT_AVAILABLE);
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy