Date/time formatting and reading

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

Date/time formatting and reading

kobetic
"C. David Shaffer"<[hidden email]> wrote:

> Date: May 6, 2010 1:13:44 PM
> From: "C. David Shaffer" <[hidden email]>
> 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.

The best I could figure out (for EXIF timestamp parsing in my case) was:

policy := (TimestampPrintPolicy newFor: #en_US) policyNamed: #full putString: 'yyyy:mm:dd hh:mm:ss'.
policy reader readTimestampFrom: timestampString readStream

HTH,

Martin
_______________________________________________
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
[vwnc] Date/time formatting and reading
I note that Martin is using CLDR locales in his example , and David is using Legacy locales in his.
 
However, since Martin's code uses a standalone TimestampPrintPolicy (rather than one from the locale), and initializes it to the locale name in the CLDR set (which is different than the one in the Legacy set), it can actually work in a Legacy locale environment, although it is depending on that locale name mismatch to work.
 
I tested this in a development VisualWorks 7.7.1 image set to use Legacy locales. You do need to adjust the code a bit... as it stands it sets the policy variable to the format string, not to the instance of TimestampPrintPolicy.
 
This is what worked for me:
 
| policy timestampString |
policy := (TimestampPrintPolicy newFor: #en_US).
policy policyNamed: #full putString: 'yyyy:mm:dd hh:mm:ss'.
timestampString := '2010:05:06 16:10:20'.
policy reader readTimestampFrom: timestampString readStream

 

This will not work in VisualWorks 7.6 because the code is not there. This is taking advantage of TimestampReader's use of the print format as hints to read the input stream, which was introduced in 7.7.

Also HTH,

Les


From: [hidden email] on behalf of [hidden email]
Sent: Thu 5/6/2010 2:45 PM
To: C. David Shaffer
Cc: [hidden email]
Subject: [vwnc] Date/time formatting and reading

"C. David Shaffer"<[hidden email]> wrote:


> Date: May 6, 2010 1:13:44 PM
> From: "C. David Shaffer" <[hidden email]>
> 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.

The best I could figure out (for EXIF timestamp parsing in my case) was:

policy := (TimestampPrintPolicy newFor: #en_US) policyNamed: #full putString: 'yyyy:mm:dd hh:mm:ss'.
policy reader readTimestampFrom: timestampString readStream

HTH,

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


_______________________________________________
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
[vwnc] Date/time formatting and reading
My comments in this message may be based upon a faulty assumption: in David's original example, he reference the #us locale, which is part of the Legacy set rather than the new CLDR locales. Based upon that reference, I concluded that David is running with Legacy locales, but it may just be that he is working with an old example of code in his message.
 
In any case, doing what I describe is of course something of a kludge, but it does work.
 
We'll make the need to do this kind of subterfuge unnecessary.


From: [hidden email] on behalf of Kooyman, Les
Sent: Thu 5/6/2010 4:22 PM
To: [hidden email]; C. David Shaffer
Cc: [hidden email]
Subject: Re: [vwnc] Date/time formatting and reading

I note that Martin is using CLDR locales in his example , and David is using Legacy locales in his.
 
However, since Martin's code uses a standalone TimestampPrintPolicy (rather than one from the locale), and initializes it to the locale name in the CLDR set (which is different than the one in the Legacy set), it can actually work in a Legacy locale environment, although it is depending on that locale name mismatch to work.
 
I tested this in a development VisualWorks 7.7.1 image set to use Legacy locales. You do need to adjust the code a bit... as it stands it sets the policy variable to the format string, not to the instance of TimestampPrintPolicy.
 
This is what worked for me:
 
| policy timestampString |
policy := (TimestampPrintPolicy newFor: #en_US).
policy policyNamed: #full putString: 'yyyy:mm:dd hh:mm:ss'.
timestampString := '2010:05:06 16:10:20'.
policy reader readTimestampFrom: timestampString readStream

 

This will not work in VisualWorks 7.6 because the code is not there. This is taking advantage of TimestampReader's use of the print format as hints to read the input stream, which was introduced in 7.7.

Also HTH,

Les


From: [hidden email] on behalf of [hidden email]
Sent: Thu 5/6/2010 2:45 PM
To: C. David Shaffer
Cc: [hidden email]
Subject: [vwnc] Date/time formatting and reading

"C. David Shaffer"<[hidden email]> wrote:


> Date: May 6, 2010 1:13:44 PM
> From: "C. David Shaffer" <[hidden email]>
> 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.

The best I could figure out (for EXIF timestamp parsing in my case) was:

policy := (TimestampPrintPolicy newFor: #en_US) policyNamed: #full putString: 'yyyy:mm:dd hh:mm:ss'.
policy reader readTimestampFrom: timestampString readStream

HTH,

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


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