{"action":"created","issue":{"url":"https://api.github.com/repos/discretelogics/TeaFiles.Net/issues/5","labels_url":"https://api.github.com/repos/discretelogics/TeaFiles.Net/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/discretelogics/TeaFiles.Net/issues/5/comments","events_url":"https://api.github.com/repos/discretelogics/TeaFiles.Net/issues/5/events","html_url":"https://github.com/discretelogics/TeaFiles.Net/issues/5","id":107494650,"number":5,"title":"DateTime support","user":{"login":"mayerwin","id":2272127,"avatar_url":"https://avatars.githubusercontent.com/u/2272127?v=3","gravatar_id":"","url":"https://api.github.com/users/mayerwin","html_url":"https://github.com/mayerwin","followers_url":"https://api.github.com/users/mayerwin/followers","following_url":"https://api.github.com/users/mayerwin/following{/other_user}","gists_url":"https://api.github.com/users/mayerwin/gists{/gist_id}","starred_url":"https://api.github.com/users/mayerwin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mayerwin/subscriptions","organizations_url":"https://api.github.com/users/mayerwin/orgs","repos_url":"https://api.github.com/users/mayerwin/repos","events_url":"https://api.github.com/users/mayerwin/events{/privacy}","received_events_url":"https://api.github.com/users/mayerwin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-09-21T11:48:25Z","updated_at":"2015-09-21T13:57:20Z","closed_at":null,"body":"Hello, when trying to use a DateTime field in my struct, I get the following error:\r\n\r\nDateTime is not supported as a field type. Use TeaTime.Time instead.\r\n\r\nHowever the example shown [here](\r\nhttp://discretelogics.com/teafiles/) uses DateTime. Could you kindly shed light on this? Has the library removed support for DateTime?\r\n"},"comment":{"url":"https://api.github.com/repos/discretelogics/TeaFiles.Net/issues/comments/141987849","html_url":"https://github.com/discretelogics/TeaFiles.Net/issues/5#issuecomment-141987849","issue_url":"https://api.github.com/repos/discretelogics/TeaFiles.Net/issues/5","id":141987849,"user":{"login":"thulka","id":313780,"avatar_url":"https://avatars.githubusercontent.com/u/313780?v=3","gravatar_id":"","url":"https://api.github.com/users/thulka","html_url":"https://github.com/thulka","followers_url":"https://api.github.com/users/thulka/followers","following_url":"https://api.github.com/users/thulka/following{/other_user}","gists_url":"https://api.github.com/users/thulka/gists{/gist_id}","starred_url":"https://api.github.com/users/thulka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thulka/subscriptions","organizations_url":"https://api.github.com/users/thulka/orgs","repos_url":"https://api.github.com/users/thulka/repos","events_url":"https://api.github.com/users/thulka/events{/privacy}","received_events_url":"https://api.github.com/users/thulka/received_events","type":"User","site_admin":false},"created_at":"2015-09-21T13:57:20Z","updated_at":"2015-09-21T13:57:20Z","body":"Great question!\r\n\r\n**Short answer**: Yes DateTime has been dropped.\r\n\r\n**Solution:** Use TeaTime.Time and you should be fine. example:\r\n\r\n    struct Tick\r\n    {\r\n        // just use TeaTime.Time here and it will still accept DateTime as seen below.\r\n        public Time Time;\r\n        public double Price;\r\n        public int Volume;\r\n    }\r\n\r\n    static void Main(string[] args)\r\n    {\r\n        // create file and write some values\r\n        using (var tf = TeaFile<Tick>.Create(\"silver.tea\"))\r\n        {\r\n            tf.Write(new Tick { Price = 5, Time = DateTime.Now, Volume = 700 });\r\n            tf.Write(new Tick { Price = 15, Time = DateTime.Now.AddHours(1), Volume = 1700 });\r\n            // ...\r\n        }\r\n    }\r\n\r\n**Long answer:**\r\nThe TeaFile file format as well as the APIs are designed for platform compatibility. Regarding time representation, Unix 1970 based time libraries were prevanlent, but we thought that the year 0 based .Net format is more reasonable and the modern way to represent time. So we first decided to use that.\r\n\r\nIt was until we worked on an R API (no there still is no public one from us or someone else) and faced a surprising issue: R had just 2 number formats: integer and floating point. Even the 64bit version of R would use 32bit integers. Since DateTime uses an unsigned 64bit value as the underlying tick counter, we had a problem. Back then, the majority of the R community had the oppinion, to never increase the size of ints from 32 to 64 bit. The workaround for integers larger than 32bit used by R package developers was to (ab)use doubles as integers. And this works until the 53bit border. So what can we do with 53bit for time representation? .Net DateTime counts 0.1us requiring 60bit for the 1.1.2000 . And this was the end of DateTime and when we though that a 1970 based time format is better, because nearly everybody deals with times withint the last years or decades and we do not loose many bits just for the sake of a jesus based starting point. Also, even newer languages like Ruby or Python base their library on the C library and thus start with the unix epoch time functions, so writing a TeaFile API for any of those is simpler with a unix epoch based time.\r\n\r\nFor TeaFile.Net users, the Time class makes interaction with DateTime values very easy, so we thought everything is safe now.\r\n\r\nYou can certainly create a struct with a long inside and store the Ticks of a DateTime in it. The difference is, that the TeaFiles.Net API will not be able to write the time starting point and the time precision into the file.\r\n\r\nHope that clarifies, will go and update discretelogics.com .\r\n\r\nThanks for asking\r\n\r\n"}}