digitalmars.D.learn - Date formatting in D
- aberba (10/10) Mar 07 2017 I've been trying to figure out an inbuilt functionality in phobos
- ikod (5/15) Mar 07 2017 Straightforward solution:
- aberba (5/23) Mar 08 2017 Having to do these stuff with C is a punch in the face.
- Adam D. Ruppe (17/20) Mar 08 2017 The PHP function is basically just (translated to D):
- aberba (2/20) Mar 08 2017 Your docs page is really effective, not pretty though.
- Adam D. Ruppe (8/9) Mar 08 2017 If you have specific complaints/suggestions, feel free to make a
- aberba (3/13) Mar 07 2017 Just found this http://code.dlang.org/packages/datetimeformat.
- Daniel Kozak via Digitalmars-d-learn (3/18) Mar 07 2017 I do not know? Is this some ISO/ANSI format for dates? If yes than we
- Daniel Kozak via Digitalmars-d-learn (5/20) Mar 07 2017 I have looked at some of our many years old codebase and we use
- Jonathan M Davis via Digitalmars-d-learn (8/10) Mar 07 2017 The ISO formats are already there. There's to/fromISOString and
- Daniel Kozak via Digitalmars-d-learn (5/14) Mar 07 2017 Sorry for my previous comments. I have not been reading this post
I've been trying to figure out an inbuilt functionality in phobos for formatting date. In my use case, I've been trying to format current Unix timestamp to something like "Thu, 08 Mar 2017 12:00:00 GMT". How do I go by this easily (Currently, long concatenation of strings is what I'm thinking)? I saw this thread[1] from 2011 on similar issue. Has it been resolved? What is the state of toCustomString? [1] http://forum.dlang.org/post/mailman.673.1320367887.24802.digitalmars-d-learn puremagic.com
Mar 07 2017
On Tuesday, 7 March 2017 at 20:29:07 UTC, aberba wrote:I've been trying to figure out an inbuilt functionality in phobos for formatting date. In my use case, I've been trying to format current Unix timestamp to something like "Thu, 08 Mar 2017 12:00:00 GMT". How do I go by this easily (Currently, long concatenation of strings is what I'm thinking)? I saw this thread[1] from 2011 on similar issue. Has it been resolved? What is the state of toCustomString? [1] http://forum.dlang.org/post/mailman.673.1320367887.24802.digitalmars-d-learn puremagic.comStraightforward solution: https://dlang.org/library/core/stdc/time/strftime.html http://man7.org/linux/man-pages/man3/strftime.3.html Maybe there is something better.
Mar 07 2017
On Tuesday, 7 March 2017 at 20:52:39 UTC, ikod wrote:On Tuesday, 7 March 2017 at 20:29:07 UTC, aberba wrote:Having to do these stuff with C is a punch in the face. Or PHP was: date(format, timestamp); Almost every other language (ive used) has this equivalent.I've been trying to figure out an inbuilt functionality in phobos for formatting date. In my use case, I've been trying to format current Unix timestamp to something like "Thu, 08 Mar 2017 12:00:00 GMT". How do I go by this easily (Currently, long concatenation of strings is what I'm thinking)? I saw this thread[1] from 2011 on similar issue. Has it been resolved? What is the state of toCustomString? [1] http://forum.dlang.org/post/mailman.673.1320367887.24802.digitalmars-d-learn puremagic.comStraightforward solution: https://dlang.org/library/core/stdc/time/strftime.html http://man7.org/linux/man-pages/man3/strftime.3.html Maybe there is something better.
Mar 08 2017
On Wednesday, 8 March 2017 at 15:29:11 UTC, aberba wrote:Having to do these stuff with C is a punch in the face. Or PHP was: date(format, timestamp);The PHP function is basically just (translated to D): string date(string format, time_t timestamp) { char[256] buffer; auto ret = strftime(buffer.ptr, buffer.ptr, toStringz(format), gmtime(×tamp); return buffer[0 .. ret].idup; } in other words, it is a thin wrapper around the C function. Let's see, how do we get a time_t out of D's std.datetime? http://dpldocs.info/locate?q=time_t The SysTime "toUnixTime" looks good: http://dpldocs.info/experimental-docs/std.datetime.SysTime.toUnixTime.html So an overload might be string date(string format, SysTime time) { date(format, time.toUnixTime()); }
Mar 08 2017
On Wednesday, 8 March 2017 at 15:46:42 UTC, Adam D. Ruppe wrote:On Wednesday, 8 March 2017 at 15:29:11 UTC, aberba wrote:Your docs page is really effective, not pretty though.[...]The PHP function is basically just (translated to D): string date(string format, time_t timestamp) { char[256] buffer; auto ret = strftime(buffer.ptr, buffer.ptr, toStringz(format), gmtime(×tamp); return buffer[0 .. ret].idup; } in other words, it is a thin wrapper around the C function. Let's see, how do we get a time_t out of D's std.datetime? http://dpldocs.info/locate?q=time_t The SysTime "toUnixTime" looks good: http://dpldocs.info/experimental-docs/std.datetime.SysTime.toUnixTime.html So an overload might be string date(string format, SysTime time) { date(format, time.toUnixTime()); }
Mar 08 2017
On Wednesday, 8 March 2017 at 16:00:26 UTC, aberba wrote:Your docs page is really effective, not pretty though.If you have specific complaints/suggestions, feel free to make a thread in the General forum, or email me destructionator gmail.com and I'll see what I can do (just don't want to get this thread too far off topic). I'm open to changing design, but I'll resist if it sacrifices readability. I'm not a very good designer but have been doing some usability testing here and don't want to go backward on that.
Mar 08 2017
On Tuesday, 7 March 2017 at 20:29:07 UTC, aberba wrote:I've been trying to figure out an inbuilt functionality in phobos for formatting date. In my use case, I've been trying to format current Unix timestamp to something like "Thu, 08 Mar 2017 12:00:00 GMT". How do I go by this easily (Currently, long concatenation of strings is what I'm thinking)? I saw this thread[1] from 2011 on similar issue. Has it been resolved? What is the state of toCustomString? [1] http://forum.dlang.org/post/mailman.673.1320367887.24802.digitalmars-d-learn puremagic.comJust found this http://code.dlang.org/packages/datetimeformat. Why is Phobos not still not having this in 2017?
Mar 07 2017
I do not know? Is this some ISO/ANSI format for dates? If yes than we should add it. If no there is no reason. Dne 7.3.2017 v 22:07 aberba via Digitalmars-d-learn napsal(a):On Tuesday, 7 March 2017 at 20:29:07 UTC, aberba wrote:I've been trying to figure out an inbuilt functionality in phobos for formatting date. In my use case, I've been trying to format current Unix timestamp to something like "Thu, 08 Mar 2017 12:00:00 GMT". How do I go by this easily (Currently, long concatenation of strings is what I'm thinking)? I saw this thread[1] from 2011 on similar issue. Has it been resolved? What is the state of toCustomString? [1] http://forum.dlang.org/post/mailman.673.1320367887.24802.digitalmars-d-learn puremagic.comJust found this http://code.dlang.org/packages/datetimeformat. Why is Phobos not still not having this in 2017?
Mar 07 2017
Dne 7.3.2017 v 22:07 aberba via Digitalmars-d-learn napsal(a):On Tuesday, 7 March 2017 at 20:29:07 UTC, aberba wrote:I have looked at some of our many years old codebase and we use andI've been trying to figure out an inbuilt functionality in phobos for formatting date. In my use case, I've been trying to format current Unix timestamp to something like "Thu, 08 Mar 2017 12:00:00 GMT". How do I go by this easily (Currently, long concatenation of strings is what I'm thinking)? I saw this thread[1] from 2011 on similar issue. Has it been resolved? What is the state of toCustomString? [1] http://forum.dlang.org/post/mailman.673.1320367887.24802.digitalmars-d-learn puremagic.comJust found this http://code.dlang.org/packages/datetimeformat. Why is Phobos not still not having this in 2017?
Mar 07 2017
On Tuesday, March 07, 2017 22:15:39 Daniel Kozak via Digitalmars-d-learn wrote:I do not know? Is this some ISO/ANSI format for dates? If yes than we should add it. If no there is no reason.The ISO formats are already there. There's to/fromISOString and to/fromISOExtString on SysTime, DateTime, Date, and TimeOfDay. What's missing is custom date/time formatting, and it's on my todo list, but I've had enough other stuff going on that I haven't gotten around to it even though I should have done it ages ago. - Jonathan M Davis
Mar 07 2017
Dne 7.3.2017 v 21:29 aberba via Digitalmars-d-learn napsal(a):I've been trying to figure out an inbuilt functionality in phobos for formatting date. In my use case, I've been trying to format current Unix timestamp to something like "Thu, 08 Mar 2017 12:00:00 GMT". How do I go by this easily (Currently, long concatenation of strings is what I'm thinking)? I saw this thread[1] from 2011 on similar issue. Has it been resolved? What is the state of toCustomString? [1] http://forum.dlang.org/post/mailman.673.1320367887.24802.digitalmars-d-learn puremagic.comSorry for my previous comments. I have not been reading this post carefully. AFAIK you want some universal (general) format method for dates. This make sense. So if you write pull request I believe it will be accepted.
Mar 07 2017