Azure / azure-cosmosdb-java

Java Async SDK for SQL API of Azure Cosmos DB
MIT License
54 stars 61 forks source link

Document's getTimestamp() method is returning 1970. #32

Closed Ramji-S closed 6 years ago

Ramji-S commented 6 years ago

Team

When trying to obtain the last modified timestamp of a document ("_ts") using the util method "document.getTimestamp()", I end up getting a date that reads 1970. Upon checking the base code (Resource.java), looks like the value corresponding to field "_ts" is converted to a Double LongValue (ex. 1524473670) and the Date object is created with this longValue. This is where I guess the trouble is, since the util date is getting only the 10 digit value as against 13.

E.g. new Date(1524473670) -> Sun Jan 18 20:57:53 IST 1970 new Date(1524473670000L) (appending 0's) -> Mon Apr 23 14:24:30 IST 2018

Can someone please take a look ?

Regards Ramji

moderakh commented 6 years ago

@Ramji-S Thanks for reporting this. You are right.

The resolution is to pass Date(millisec.longValue() * 1000) instead of Date(millisec.longValue())

If you are interested to contribute you can send a PR, I will merge yours :-)

Ramji-S commented 6 years ago

Sure. Thanks for acknowledging :-)

Ramji-S commented 6 years ago

I have sent a PR containing this fix in https://github.com/Azure/azure-cosmosdb-java/pull/35 Please verify the changes

Ramji-S commented 6 years ago

Thank you @moderakh