I tried searching the internet and found a lot of questions on StackOverlflow somewhat regarding the same topic, but couldn't find anything that I was able to understand...
So, I have this data class that contains a dateOfOrigin of type GregorianCalendar. Using gson I convert all json and return an Observable array with all locations. Inside the json file, I added the dateOfOrigin as an object like so:
{
"id": 6,
"name": "Fuse",
"image": "fuse.jpg",
"street": "Blaesstraat 208",
"city": "Brussels Hoofdstedelijk Gewest",
"zip": 1000,
"date_of_origin": {"year":1994,"month":4,"dayOfMonth":16},
"parking": true
}
And this is what my data class looks like:
data class Location ( val id : Int, val name : String, val image : String, val street : String, val city : String, val zip : Int, @SerializedName("date_of_origin") val originDate : GregorianCalendar?, val parking : Boolean = true, var imageBitmap : Bitmap? = null )
Whenever I try to set the dateText like this:
originDate?.let {
dateText = "${it.get(Calendar.DAY_OF_MONTH)} ${it.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.getDefault())} ${it.get(Calendar.YEAR)}"
dateText = resources.getString(R.string.origin_date, dateText)
}
It outputs 16 May 1994
instead of 16 Apr 1994
I'm not able to figure out how to fix this...
EDIT
Subtracting 1 from the month seems to fix the problem for most cases. Still, I have one result that is supposed to output 30 Jan 2016
but displays 1 Feb 2016
.
"date_of_origin": {"year":2016,"month":1,"dayOfMonth":30}