Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
May 09, 2006 d_time and writefln | ||||
---|---|---|---|---|
| ||||
d_time should be recognized by writefln. //------------- import std.date; import std.stdio; void main() { d_time fecha = getUTCtime(); writefln("%s",toDateString(fecha)); writefln(fecha); } //------------- Outputs (any system): $ ./test Tue May 09 2006 1147138947602 -- Carlos Santander Bernal |
May 09, 2006 Re: d_time and writefln | ||||
---|---|---|---|---|
| ||||
Posted in reply to Carlos Santander | Carlos Santander wrote:
> d_time should be recognized by writefln.
>
> //-------------
> import std.date;
> import std.stdio;
>
> void main() {
> d_time fecha = getUTCtime();
> writefln("%s",toDateString(fecha));
> writefln(fecha);
> }
> //-------------
>
> Outputs (any system):
>
> $ ./test
> Tue May 09 2006
> 1147138947602
>
The problem is, that 'd_time' is just an alias of long, so writef*() just sees it as a long. Maybe d_time could be typedef'd to change this, but would that break anything? If it has no or few cons against it, I'm cool with typedef'ing it, although it would couple std.format and std.date to each other a little.
-- Chris Nicholson-Sauls
|
May 09, 2006 Re: d_time and writefln | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris Nicholson-Sauls | Chris Nicholson-Sauls wrote: <snip> > The problem is, that 'd_time' is just an alias of long, so writef*() just sees it as a long. Maybe d_time could be typedef'd to change this, but would that break anything? If it has no or few cons against it, I'm cool with typedef'ing it, although it would couple std.format and std.date to each other a little. If we have this, then we ought to have a way for the programmer to define a custom formatting for any typedef. Stewart. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/M d- s:-@ C++@ a->--- UB@ P+ L E@ W++@ N+++ o K-@ w++@ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++++ h-- r-- !y ------END GEEK CODE BLOCK------ My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit. |
May 09, 2006 Re: d_time and writefln | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | Stewart Gordon escribió: > Chris Nicholson-Sauls wrote: > <snip> >> The problem is, that 'd_time' is just an alias of long, so writef*() just sees it as a long. Maybe d_time could be typedef'd to change this, but would that break anything? If it has no or few cons against it, I'm cool with typedef'ing it, although it would couple std.format and std.date to each other a little. Another solution would be to add a bit of type information to aliases. In any case, if d_time is the official way to deal with dates and times in D, I wouldn't be surprised if many people new to D tried to do writefln(getUTCtime()); So, regardless of the solution, I believe printing the numeric representation is wrong. > > If we have this, then we ought to have a way for the programmer to define a custom formatting for any typedef. > There should be a way to do this, too. > Stewart. > -- Carlos Santander Bernal |
May 09, 2006 Re: d_time and writefln | ||||
---|---|---|---|---|
| ||||
Posted in reply to Carlos Santander | On Tue, 09 May 2006 09:47:59 -0500, Carlos Santander <csantander619@gmail.com> wrote:
> Stewart Gordon escribió:
>> Chris Nicholson-Sauls wrote:
>> <snip>
>>> The problem is, that 'd_time' is just an alias of long, so writef*() just sees it as a long. Maybe d_time could be typedef'd to change this, but would that break anything? If it has no or few cons against it, I'm cool with typedef'ing it, although it would couple std.format and std.date to each other a little.
>
> Another solution would be to add a bit of type information to aliases. In any case, if d_time is the official way to deal with dates and times in D, I wouldn't be surprised if many people new to D tried to do
>
> writefln(getUTCtime());
>
> So, regardless of the solution, I believe printing the numeric representation is wrong.
It should remain possible to print the numeric representation. For use in files/records/etc on disk or otherwise. I use the numeric time_t value from time() in C/C++ all the time. It's far easier to read/write a number than parse a string which could be in many different formats.
Regan
|
May 10, 2006 Re: d_time and writefln | ||||
---|---|---|---|---|
| ||||
Posted in reply to Regan Heath | Regan Heath wrote: <snip> > It should remain possible to print the numeric representation. For use in files/records/etc on disk or otherwise. I use the numeric time_t value from time() in C/C++ all the time. There are many different formats for converting dates/times into numbers. Is the format of time_t standardised? > It's far easier to read/write a number than parse a string which could be in many different formats. And somewhere between the two is parsing a string that can be in only one format. Depending on whether you want the files your program works with to be human-readable, you could use either a simple numeric representation or a uniform textual notation (ideally the ISO notation). Stewart. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/M d- s:-@ C++@ a->--- UB@ P+ L E@ W++@ N+++ o K-@ w++@ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++++ h-- r-- !y ------END GEEK CODE BLOCK------ My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit. |
Copyright © 1999-2021 by the D Language Foundation