about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorJesse Jones <jesse9jones@gmail.com>2012-11-17 09:27:03 -0800
committerBrian Anderson <banderson@mozilla.com>2012-11-18 13:25:25 -0800
commit2c0dab02ad64e581ede4344401dca0db67430897 (patch)
tree2233f0aa67e4b47abd6a0dcf9f0f723bb0ee7766 /src
parentc58951ea7d70bfab8c9a0a3ad6540d829c59b585 (diff)
Made the time to string functions pure as well as empty_tm.
This closes #3919.
Diffstat (limited to 'src')
-rw-r--r--src/libstd/time.rs24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/libstd/time.rs b/src/libstd/time.rs
index d5a5deeae8c..912df9c7558 100644
--- a/src/libstd/time.rs
+++ b/src/libstd/time.rs
@@ -107,7 +107,7 @@ impl Tm : Eq {
     pure fn ne(other: &Tm) -> bool { *self != *(*other) }
 }
 
-pub fn empty_tm() -> Tm {
+pub pure fn empty_tm() -> Tm {
     Tm_({
         tm_sec: 0_i32,
         tm_min: 0_i32,
@@ -151,13 +151,17 @@ pub fn now() -> Tm {
 }
 
 /// Parses the time from the string according to the format string.
-pub fn strptime(s: &str, format: &str) -> Result<Tm, ~str> {
-    do_strptime(s, format)
+pub pure fn strptime(s: &str, format: &str) -> Result<Tm, ~str> {
+    // unsafe only because do_strptime is annoying to make pure
+    // (it does IO with a str_reader)
+    unsafe {do_strptime(s, format)}
 }
 
 /// Formats the time according to the format string.
-pub fn strftime(format: &str, tm: Tm) -> ~str {
-    do_strftime(format, tm)
+pub pure fn strftime(format: &str, tm: Tm) -> ~str {
+    // unsafe only because do_strftime is annoying to make pure
+    // (it does IO with a str_reader)
+    unsafe {do_strftime(format, tm)}
 }
 
 impl Tm {
@@ -186,10 +190,10 @@ impl Tm {
      * Return a string of the current time in the form
      * "Thu Jan  1 00:00:00 1970".
      */
-    fn ctime() -> ~str { self.strftime(~"%c") }
+    pure fn ctime() -> ~str { self.strftime(~"%c") }
 
     /// Formats the time according to the format string.
-    fn strftime(format: &str) -> ~str { strftime(format, self) }
+    pure fn strftime(format: &str) -> ~str { strftime(format, self) }
 
     /**
      * Returns a time string formatted according to RFC 822.
@@ -197,7 +201,7 @@ impl Tm {
      * local: "Thu, 22 Mar 2012 07:53:18 PST"
      * utc:   "Thu, 22 Mar 2012 14:53:18 UTC"
      */
-    fn rfc822() -> ~str {
+    pure fn rfc822() -> ~str {
         if self.tm_gmtoff == 0_i32 {
             self.strftime(~"%a, %d %b %Y %T GMT")
         } else {
@@ -211,7 +215,7 @@ impl Tm {
      * local: "Thu, 22 Mar 2012 07:53:18 -0700"
      * utc:   "Thu, 22 Mar 2012 14:53:18 -0000"
      */
-    fn rfc822z() -> ~str {
+    pure fn rfc822z() -> ~str {
         self.strftime(~"%a, %d %b %Y %T %z")
     }
 
@@ -221,7 +225,7 @@ impl Tm {
      * local: "2012-02-22T07:53:18-07:00"
      * utc:   "2012-02-22T14:53:18Z"
      */
-    fn rfc3339() -> ~str {
+    pure fn rfc3339() -> ~str {
         if self.tm_gmtoff == 0_i32 {
             self.strftime(~"%Y-%m-%dT%H:%M:%SZ")
         } else {