Date/time formatting and reading

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Date/time formatting and reading

cdavidshaffer
Does anyone know a convenient way to read and write Timestamps in VW with user-specified formatting?  I never seem to get more than 1/2 of the way to a solution:

policy := (TimestampPrintPolicy newFor: #us).
policy longPolicyString: 'yyyymmddhhmmss'. "this format string is just an example"
stem1 := policy print: Timestamp now.
(Delay forSeconds: 5) wait.
stem2 := policy print: Timestamp now.

OK, now I want to read the Timestamps back out...I don't really see any helpful docs so I tried what looked like made the most sense:

reader := TimestampReader newFor: #us.
reader printPolicy: policy.
reader readTimestampFrom: stem1 readStream

...walkback.  Must be wrong.  So, given a format string is there a way to read and write Timestamps?  Are there any docs on this? Internationalization guide has some hints but it seems too tied up in "Locales" and whatnot.  I just want to print/parse timestamps -- like java.text.DateFormat.

David


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Date/time formatting and reading

Kooyman, Les
David:
 
From the reference to locale #us I am assuming you are using Legacy locales rather than CLDR-derived locales.
 
I've created AR 60136: Add convenience methods to read/write time things and number things with user-specified formats in TimestampReader, TimestampPrintPolicy, NumberReader and NumberPrintPolicy.
 
This will be added to the  CLDR-derived locale environment, along with related enhancements. One of the reasons for this is that the supporting code (which you would be using) in the CLDR version uses the print policy formats as hints when attempting to read in textual representations. When implementing the convenience methods, your custom format would be added to the head of the list of formats used when attempting to parse textual input.
 
The infrastructure supporting the Legacy locale environment doesn't know about the convention to use print policy formats as hints for reading, so your conversion accuracy would be problematic with Legacy locale environment code - mm/dd/yy ordering is not discernable in all cases from the data alone, for example.
 
Note that there is fallback to the readLatinXXXX methods from the readLocaleXXXX forms, but what I'm discussing adding would start off using the readLocaleXXXX forms with your format as hint, so should read your supplied data with your supplied format with high accuracy. (One of the tests for the CLDR locale set involves writing a timestamp in every format for all locales and then reading the textual representations back in and converting them back to Timestamps that should match with the originals.)
 
This doesn't mean you'd be dependent upon the CLDR locales as far as their locale-based formats are concerned, but you would need to be using that version of the locale subsystem in order to have the infrastructure to support your requested functionality.
 
This is not the first time this has been requested, my bad for not including it in 7.7.1. (If I can sneak this in, I will - it's small - but otherwise it will be part of the follow-on release to 7.7.1, which I believe is also going to be a fairly short development cycle - just don't quote me on that as sometimes things change.)
 
Les Kooyman
Cincom Smalltalk


From: [hidden email] on behalf of C. David Shaffer
Sent: Thu 5/6/2010 10:13 AM
To: [hidden email]
Subject: [vwnc] Date/time formatting and reading

Does anyone know a convenient way to read and write Timestamps in VW with user-specified formatting?  I never seem to get more than 1/2 of the way to a solution:

policy := (TimestampPrintPolicy newFor: #us).
policy longPolicyString: 'yyyymmddhhmmss'. "this format string is just an example"
stem1 := policy print: Timestamp now.
(Delay forSeconds: 5) wait.
stem2 := policy print: Timestamp now.

OK, now I want to read the Timestamps back out...I don't really see any helpful docs so I tried what looked like made the most sense:

reader := TimestampReader newFor: #us.
reader printPolicy: policy.
reader readTimestampFrom: stem1 readStream

...walkback.  Must be wrong.  So, given a format string is there a way to read and write Timestamps?  Are there any docs on this? Internationalization guide has some hints but it seems too tied up in "Locales" and whatnot.  I just want to print/parse timestamps -- like java.text.DateFormat.

David


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc