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

org.schoellerfamily.gedbrowser.api.datamodel.DateUtil Maven / Gradle / Ivy

There is a newer version: 1.3.0-RC2
Show newest version
package org.schoellerfamily.gedbrowser.api.datamodel;

import java.time.LocalDate;
import java.time.ZoneId;
import java.time.format.TextStyle;
import java.util.Locale;

/**
 * @author Dick Schoeller
 */
public class DateUtil {
    /**
     * @return a date attribute for today
     */
    public ApiAttribute todayDateAttribute() {
        final java.util.Date date = new java.util.Date();
        final LocalDate localDate = date.toInstant()
                .atZone(ZoneId.systemDefault()).toLocalDate();
        final int day = localDate.getDayOfMonth();
        final String month = localDate.getMonth()
                .getDisplayName(TextStyle.SHORT, Locale.ENGLISH)
                .toUpperCase(Locale.ENGLISH);
        final int year = localDate.getYear();
        final String todayString = twoDigit(day) + " " + month + " " + year;
        return new ApiAttribute("date", todayString);
    }

    /**
     * @param day a day number
     * @return as a two digit string
     */
    private String twoDigit(final int day) {
        final int ten = 10;
        if (day >= ten) {
            return Integer.toString(day);
        }
        return "0" + day;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy