[PATCH] postgres: Workaround parsing DateTime with microseconds

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

[PATCH] postgres: Workaround parsing DateTime with microseconds

Holger Freyther
2013-11-09  Holger Hans Peter Freyther  <[hidden email]>

        * ColumnInfo.st: Truncate microseconds before passing
        it to DateTime>>#readFrom:.
---
 packages/dbd-postgresql/ColumnInfo.st | 5 ++++-
 packages/dbd-postgresql/Tests.st      | 7 +++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/packages/dbd-postgresql/ColumnInfo.st b/packages/dbd-postgresql/ColumnInfo.st
index 74c5343..6d40288 100644
--- a/packages/dbd-postgresql/ColumnInfo.st
+++ b/packages/dbd-postgresql/ColumnInfo.st
@@ -74,8 +74,11 @@ ColumnInfo subclass: PGColumnInfo [
     ]
 
     PGColumnInfo class >> convertDateTime: aRaw [
+ | parts |
  <category: 'type conversions'>
- ^DateTime readFrom: (ReadStream on: aRaw)
+        "Parse a date like 2013-11-08 16:53:03.11825"
+        parts := aRaw subStrings: $..
+        ^DateTime readFrom: (ReadStream on: parts first)
     ]
 
     PGColumnInfo class >> convertTimeInterval: aRaw [
diff --git a/packages/dbd-postgresql/Tests.st b/packages/dbd-postgresql/Tests.st
index b66cb0e..89f5bf8 100644
--- a/packages/dbd-postgresql/Tests.st
+++ b/packages/dbd-postgresql/Tests.st
@@ -133,6 +133,13 @@ TestCase subclass: PostgresTestCase [
         self assert: (res next at: 'integer')  = 100.
     ]
 
+    testDateTimeParse [
+        | res |
+        "Manually test if we can parse dates with ms"
+        res := PGColumnInfo convertDateTime: '2013-11-08 16:53:03.11825'.
+        self assert: res = (DateTime year: 2013 month: 11 day: 8 hour: 16 minute: 53 second: 3)
+    ]
+
     testDateTime [
         | statement res now now_utc row |
 
--
1.8.4.rc3


_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk