if(bodymediaResponse.has("lastSync"))
{
DateTime d = form.parseDateTime(bodymediaResponse.getJSONObject("lastSync").getString("dateTime"));
// Get timezone map from UpdateInfo context
TimezoneMap tzMap = (TimezoneMap)updateInfo.getContext("tzMap");
// Insert lastSync into the updateInfo context so it's accessible to the updater
updateInfo.setContext("lastSync", d);
for(Object o : daysArray)
{
if(o instanceof JSONObject)
{
JSONObject day = (JSONObject) o;
BodymediaSleepFacet sleep = new BodymediaSleepFacet(updateInfo.apiKey.getId());
super.extractCommonFacetData(sleep, apiData);
sleep.efficiency = day.getDouble("efficiency");
sleep.totalLying = day.getInt("totalLying");
sleep.totalSleeping = day.getInt("totalSleep");
sleep.json = day.getString("sleepPeriods");
sleep.lastSync = d.getMillis();
//https://developer.bodymedia.com/docs/read/api_reference_v2/Sleep_Service
// sleep data is from noon the previous day to noon the current day,
// so subtract MILLIS_IN_DAY/2 from midnight
long MILLIS_IN_DAY = 86400000l;
DateTime date = formatter.parseDateTime(day.getString("date"));
if(tzMap!=null)
{
// Create a LocalDate object which just captures the date without any
// timezone assumptions
LocalDate ld = new LocalDate(date.getYear(),date.getMonthOfYear(),date.getDayOfMonth());
// Use tzMap to convert date into a datetime with timezone information
DateTime realDateStart = tzMap.getStartOfDate(ld);
// Set the start and end times for the facet. The start time is the leading midnight
// of burn.date according to BodyMedia's idea of what timezone you were in then.
// End should, I think, be start + the number of minutes in the minutes array *
// the number of milliseconds in a minute.
sleep.date = TimeUtils.dateFormatter.print(realDateStart.getMillis());