Thursday, 15 September 2011

servicestack.redis - ServiceStack - DateTime SerializeFn from Cache different from Database -



servicestack.redis - ServiceStack - DateTime SerializeFn from Cache different from Database -

in servicestack application, i'm trying serialize datetime database rfc3339 standard. datetime stored in databases local time. application, database located in 2 different location, 1 republic of indonesia +7 offset, malaysia +8 offset. both database stored local time respectively.

same application used serve both database different location. local time application offset +8, located in malaysia.

when datetime republic of indonesia database, illustration "2014-09-19 14:07:27.387"(2pm), append offset +7 "2014-09-19t14:07:27.3870000+07:00"(2pm+7). next code serializefn

jsconfig<datetime?>.serializefn = time => { if (time != null) { datetimeoffset datetimeoffset = datetimezone.getdatetimeoffset((datetime)time, commonfunction.getdbcountrycode()); homecoming string.format("{0:o}", datetimeoffset); } homecoming null; };

the codes getdatetimeoffset function:

public static datetimeoffset getdatetimeoffset(datetime datetime, string country) { switch (country.toupper()) { case "id": homecoming new datetimeoffset(datetime, timespan.fromhours(+7)); default: homecoming new datetimeoffset(datetime, timespan.fromhours(+8)); ; } }

then redis cached value "2014-09-19t14:07:27.3870000+07:00"(2pm+7). subsequent request redis cached value , .net application auto convert application local time turn "2014-09-19 15:07:27.387"(3pm, application local time offset +8) before serializefn.

the datetime's hours has increased 1 hour. output value cache go through same serializefn has become "2014-09-19t15:07:27.3870000+07:00"(3pm+7)

the datetime cache republic of indonesia +7 has increased hours due auto conversion in .net.

is anyway identify sources in serializefn? can guide me if i'm doing in right way? in advance.

found solution. added deserializefn process info cache. , there part missed out alter in code caused solution didn't work.

datetimeoffset dto = jsonserializer.deserializefromstring<datetimeoffset>(time); datetime temp = new datetime(dto.utcdatetime.ticks, datetimekind.utc); homecoming datetimezone.convertdatetimezonefromutc(commonfunction.getdbcountrycode(), temp);

servicestack servicestack.redis

No comments:

Post a Comment