Improved date display in organization page.
This commit is contained in:
parent
5c30a45346
commit
5822c9260a
6 changed files with 210 additions and 4 deletions
|
@ -175,6 +175,7 @@ public class Factory
|
|||
Organization organization = loadOrganization(inputURL, cache);
|
||||
if (organization != null)
|
||||
{
|
||||
organization.setFederation(result);
|
||||
result.getOrganizations().add(organization);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ package fr.devinsy.statoolinfos.core;
|
|||
import java.io.File;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
|
@ -62,6 +63,24 @@ public class Organization extends PathPropertyList
|
|||
this.services = new Services();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the age.
|
||||
*
|
||||
* @return the age
|
||||
*/
|
||||
public String getAge()
|
||||
{
|
||||
String result;
|
||||
|
||||
LocalDate startDate = StatoolInfosUtils.parseDate(getStartDate());
|
||||
LocalDate endDate = StatoolInfosUtils.parseDate(getEndDate());
|
||||
|
||||
result = StatoolInfosUtils.toHumanDuration(startDate, endDate);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the contact email.
|
||||
*
|
||||
|
@ -287,6 +306,54 @@ public class Organization extends PathPropertyList
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the member age.
|
||||
*
|
||||
* @return the member age
|
||||
*/
|
||||
public String getMemberAge()
|
||||
{
|
||||
String result;
|
||||
|
||||
LocalDate startDate = StatoolInfosUtils.parseDate(getMemberStartDate());
|
||||
LocalDate endDate = StatoolInfosUtils.parseDate(getMemberEndDate());
|
||||
|
||||
result = StatoolInfosUtils.toHumanDuration(startDate, endDate);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the member end date.
|
||||
*
|
||||
* @return the member end date
|
||||
*/
|
||||
public String getMemberEndDate()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = get("organization.memberof." + this.federation.getName() + ".enddate");
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the member start date.
|
||||
*
|
||||
* @return the member start date
|
||||
*/
|
||||
public String getMemberStartDate()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = get("organization.memberof." + this.federation.getName() + ".startdate");
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the mobilizon webpage.
|
||||
*
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2020 Christian Pierre MOMON <christian@momon.org>
|
||||
* Copyright (C) 2020-2021 Christian Pierre MOMON <christian@momon.org>
|
||||
*
|
||||
* This file is part of StatoolInfos, simple service statistics tool.
|
||||
*
|
||||
|
@ -25,8 +25,10 @@ import java.net.URL;
|
|||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.Period;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
|
@ -150,6 +152,49 @@ public class StatoolInfosUtils
|
|||
return new Date().getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the date.
|
||||
*
|
||||
* @param date
|
||||
* the date
|
||||
* @return the local date
|
||||
*/
|
||||
public static LocalDate parseDate(final String date)
|
||||
{
|
||||
LocalDate result;
|
||||
|
||||
try
|
||||
{
|
||||
if (date == null)
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
else if (date.matches("^\\d{1,2}/\\d{1,2}/\\d{4}$"))
|
||||
{
|
||||
result = LocalDate.parse(date, DateTimeFormatter.ofPattern("dd/MM/yyyy"));
|
||||
}
|
||||
else if (date.matches("^\\d{4}-\\d{1,2}-\\d{1,2}/$"))
|
||||
{
|
||||
result = LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||
}
|
||||
else if (date.matches("^\\d{1,2}/\\d{4}$"))
|
||||
{
|
||||
result = LocalDate.parse("01/" + date, DateTimeFormatter.ofPattern("dd/MM/yyyy"));
|
||||
}
|
||||
else
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
}
|
||||
catch (DateTimeParseException exception)
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Split day values.
|
||||
*
|
||||
|
@ -261,6 +306,83 @@ public class StatoolInfosUtils
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* To duration.
|
||||
*
|
||||
* @param startDate
|
||||
* the start date
|
||||
* @param endDate
|
||||
* the end date
|
||||
* @return the string
|
||||
*/
|
||||
public static String toHumanDuration(final LocalDate startDate, final LocalDate endDate)
|
||||
{
|
||||
String result;
|
||||
|
||||
if ((startDate == null) && (endDate == null))
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
else if ((startDate == null) && (endDate != null))
|
||||
{
|
||||
result = toHumanDuration(LocalDate.now(), endDate);
|
||||
}
|
||||
else if ((startDate != null) && (endDate == null))
|
||||
{
|
||||
result = toHumanDuration(startDate, LocalDate.now());
|
||||
}
|
||||
else if ((startDate != null) && (endDate != null))
|
||||
{
|
||||
Period period = Period.between(startDate, LocalDate.now());
|
||||
|
||||
if (period.getYears() == 0)
|
||||
{
|
||||
if (period.getMonths() == 0)
|
||||
{
|
||||
result = String.format("%d jours", period.getDays());
|
||||
}
|
||||
else
|
||||
{
|
||||
result = String.format("%d mois", period.getMonths());
|
||||
}
|
||||
}
|
||||
else if (period.getYears() == 1)
|
||||
{
|
||||
period.minusYears(1);
|
||||
|
||||
if (period.getMonths() == 0)
|
||||
{
|
||||
result = "1 an";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = String.format("1 an et %d mois", period.getMonths());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
long years = period.getYears();
|
||||
period.minusYears(period.getYears());
|
||||
|
||||
if (period.getMonths() == 0)
|
||||
{
|
||||
result = years + " ans";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = String.format("%d ans et %d mois", years, period.getMonths());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* To human long.
|
||||
*
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2020 Christian Pierre MOMON <christian@momon.org>
|
||||
* Copyright (C) 2020-2021 Christian Pierre MOMON <christian@momon.org>
|
||||
*
|
||||
* This file is part of StatoolInfos, simple service statistics tool.
|
||||
*
|
||||
|
@ -113,8 +113,23 @@ public class OrganizationPage
|
|||
data.setEscapedAttribute("organizationURL", "href", organization.getWebsite());
|
||||
|
||||
data.setEscapedContent("organizationDescription", organization.get("organization.description"));
|
||||
|
||||
data.setContent("organizationStartDate", StringUtils.defaultIfBlank(organization.getStartDate(), "n/a"));
|
||||
data.setContent("organizationEndDate", StringUtils.defaultIfBlank(organization.getEndDate(), "n/a"));
|
||||
data.setContent("organizationAge", StringUtils.defaultIfBlank(organization.getAge(), "n/a"));
|
||||
if (StringUtils.isBlank(organization.getEndDate()))
|
||||
{
|
||||
data.setAttribute("organizationEndDateData", "style", "display: none;");
|
||||
}
|
||||
|
||||
data.setContent("organizationMemberStartDate", StringUtils.defaultIfBlank(organization.getMemberStartDate(), "n/a"));
|
||||
data.setContent("organizationMemberEndDate", StringUtils.defaultIfBlank(organization.getMemberEndDate(), "n/a"));
|
||||
data.setContent("organizationMemberAge", StringUtils.defaultIfBlank(organization.getMemberAge(), "n/a"));
|
||||
if (StringUtils.isBlank(organization.getMemberEndDate()))
|
||||
{
|
||||
data.setAttribute("organizationMemberEndDateData", "style", "display: none;");
|
||||
}
|
||||
|
||||
data.setContent("serviceCount", organization.getServices().size());
|
||||
|
||||
data.setAttribute("rawLink", "href", organization.getTechnicalName() + ".properties");
|
||||
|
|
|
@ -22,7 +22,8 @@
|
|||
</div>
|
||||
<p id="organizationDescription" class="center_table" style="width: 500px;">Description absente…</p>
|
||||
</div>
|
||||
<div>Date d'entrée : <span id="organizationStartDate">n/a</span> – Date de sortie : <span id="organizationEndDate">n/a</span></div>
|
||||
<div>Date d'entrée : <span id="organizationMemberStartDate">n/a</span><span id="organizationMemberEndDateData"> – Date de sortie : <span id="organizationMemberEndDate">n/a</span></span> (<span id="organizationMemberAge">n/a</span>)</div>
|
||||
<div>Date de création : <span id="organizationStartDate">n/a</span><span id="organizationEndDateData"> – Date d'arrêt : <span id="organizationEndDate">n/a</span></span> (<span id="organizationAge">n/a</span>)</div>
|
||||
<div class="content_infos" style="margin: 5px;">
|
||||
Liens :
|
||||
<a id="legalLink" href="#"><img id="legalLinkImg" src="circle-icons/ribbon.svg" class="disabled" title="Mentions légales"/></a>
|
||||
|
|
|
@ -38,7 +38,7 @@ public class PathProperty
|
|||
*/
|
||||
public PathProperty(final String path, final String value)
|
||||
{
|
||||
if (StringUtils.isAllBlank(path))
|
||||
if (StringUtils.isBlank(path))
|
||||
{
|
||||
throw new IllegalArgumentException("Path is blank.");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue