Replace deprecated Date by Calendar

Apparently, Date.setYear and Date.getYear are deprecated in favour of Calendar, since Java6!
Source: https://docs.oracle.com/javase/6/docs/api/java/util/Date.html
master
jvoisin 5 years ago committed by GitHub
parent d17c00115a
commit d3a9a3226f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      airsonic-main/src/main/java/org/airsonic/player/controller/JAXBWriter.java
  2. 11
      airsonic-main/src/main/java/org/airsonic/player/controller/SubsonicRESTController.java

@ -42,6 +42,7 @@ import javax.xml.datatype.XMLGregorianCalendar;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.StringWriter; import java.io.StringWriter;
import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
@ -175,4 +176,12 @@ public class JAXBWriter {
c.setTime(date); c.setTime(date);
return datatypeFactory.newXMLGregorianCalendar(c).normalize(); return datatypeFactory.newXMLGregorianCalendar(c).normalize();
} }
public XMLGregorianCalendar convertCalendar(Calendar calendar) {
if (calendar == null) {
return null;
}
return datatypeFactory.newXMLGregorianCalendar((GregorianCalendar)calendar).normalize();
}
} }

@ -53,6 +53,7 @@ import org.subsonic.restapi.PodcastStatus;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper; import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.xml.datatype.XMLGregorianCalendar;
import java.util.*; import java.util.*;
@ -164,13 +165,13 @@ public class SubsonicRESTController {
request = wrapRequest(request); request = wrapRequest(request);
License license = new License(); License license = new License();
license.setEmail("airsonic@github.com"); license.setEmail("airsonic@github.com");
license.setValid(true); license.setValid(true);
Date farFuture = new Date(); Calendar calendar = Calendar.getInstance();
farFuture.setYear(farFuture.getYear() + 100); calendar.add(Calendar.YEAR, 100);
license.setLicenseExpires(jaxbWriter.convertDate(farFuture)); XMLGregorianCalendar farFuture = jaxbWriter.convertCalendar(calendar);
license.setTrialExpires(jaxbWriter.convertDate(farFuture)); license.setLicenseExpires(farFuture);
license.setTrialExpires(farFuture);
Response res = createResponse(); Response res = createResponse();
res.setLicense(license); res.setLicense(license);

Loading…
Cancel
Save