From 0ab601d9a2bc61c0448cf4754b364e89f62fd084 Mon Sep 17 00:00:00 2001
From: Jonathan Jordan <jojonaloha@1579186.no-reply.drupal.org>
Date: Fri, 6 Nov 2015 14:24:07 -0800
Subject: [PATCH 1/3] Issue #2325207 by jojonaloha: add date_now() tests.

---
 date.info           |  1 +
 tests/date_now.test | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+)
 create mode 100644 tests/date_now.test

diff --git a/date.info b/date.info
index 7ec18cd..adaec9c 100644
--- a/date.info
+++ b/date.info
@@ -6,6 +6,7 @@ core = 7.x
 php = 5.2
 files[] = date.migrate.inc
 files[] = tests/date_api.test
+files[] = tests/date_now.test
 files[] = tests/date.test
 files[] = tests/date_field.test
 files[] = tests/date_migrate.test
diff --git a/tests/date_now.test b/tests/date_now.test
new file mode 100644
index 0000000..a2095e4
--- /dev/null
+++ b/tests/date_now.test
@@ -0,0 +1,56 @@
+<?php
+
+/**
+ * @file
+ * Test Date Now unit tests.
+ */
+
+class DateNowUnitTestCase extends DrupalUnitTestCase {
+
+  /**
+   * @todo.
+   */
+  public static function getInfo() {
+    return array(
+      'name' => t('Date Now'),
+      'description' => t('Test Date Now function.') ,
+      'group' => t('Date'),
+    );
+  }
+
+  /**
+   * @todo.
+   */
+  public function testDateNowNoTimezone() {
+    // Test without passing a timezone.
+    $now = date_now();
+
+    $this->assertTrue(($now instanceof DateObject), 'Test date_now() returns a DateObject');
+  }
+
+  public function testDateNowStringTimezones() {
+    // Test with a string timezone
+    $la_time = date_now('America/Los_Angeles');
+    $ny_time = date_now('America/New_York');
+
+    $this->assertTrue(($la_time instanceof DateObject), 'Test America/Los_Angeles returns a DateObject');
+    $this->assertTrue(($ny_time instanceof DateObject), 'Test America/New_York returns a DateObject');
+
+    $this->assertEqual($la_time->getTimestamp(), $ny_time->getTimestamp(), 'Test different timezones have same Unix timestamp');
+  }
+
+  public function testDateNowObjectTimezones() {
+    // Test with object timezones
+    $la_tz = new DateTimeZone('America/Los_Angeles');
+    $ny_tz = new DateTimeZone('America/New_York');
+
+    $la_time = date_now($la_tz);
+    $ny_time = date_now($ny_tz);
+
+    $this->assertTrue(($la_time instanceof DateObject), 'Test America/Los_Angeles returns a DateObject');
+    $this->assertTrue(($ny_time instanceof DateObject), 'Test America/New_York returns a DateObject');
+
+    $this->assertEqual($la_time->getTimestamp(), $ny_time->getTimestamp(), 'Test different timezones have same Unix timestamp');
+  }
+
+}
-- 
2.3.8 (Apple Git-58)


From 7d9364061978cdefb3c9069a29d83435ddfa59e9 Mon Sep 17 00:00:00 2001
From: Jonathan Jordan <jojonaloha@1579186.no-reply.drupal.org>
Date: Sun, 8 Nov 2015 13:57:01 -0800
Subject: [PATCH 2/3] Issue #2325207 attempt to fix fatal error in test.

---
 tests/date_now.test | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/tests/date_now.test b/tests/date_now.test
index a2095e4..67cf6c1 100644
--- a/tests/date_now.test
+++ b/tests/date_now.test
@@ -21,6 +21,14 @@ class DateNowUnitTestCase extends DrupalUnitTestCase {
   /**
    * @todo.
    */
+  public function setUp() {
+    drupal_load('module', 'date_api');
+    parent::setUp();
+  }
+
+  /**
+   * @todo.
+   */
   public function testDateNowNoTimezone() {
     // Test without passing a timezone.
     $now = date_now();
-- 
2.3.8 (Apple Git-58)


From 5b8b1f9f19517dd94f62386c0e03e83f351ccd12 Mon Sep 17 00:00:00 2001
From: Jonathan Jordan <jojonaloha@1579186.no-reply.drupal.org>
Date: Fri, 6 Nov 2015 14:28:12 -0800
Subject: [PATCH 3/3] Issue #2325207 by jojonaloha, v1nk, podarok: DateTimeZone
 could not be converted to string

---
 date_api/date_api.module | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/date_api/date_api.module b/date_api/date_api.module
index 92d3237..ae6952f 100644
--- a/date_api/date_api.module
+++ b/date_api/date_api.module
@@ -1845,10 +1845,12 @@ function date_format_interval($date, $granularity = 2, $display_ago = TRUE) {
  *   The current time as a date object.
  */
 function date_now($timezone = NULL, $reset = FALSE) {
-  $static_var = __FUNCTION__ . $timezone;
   if ($timezone instanceof DateTimeZone) {
     $static_var = __FUNCTION__ . $timezone->getName();
   }
+  else {
+    $static_var = __FUNCTION__ . $timezone;
+  }
 
   if ($reset) {
     drupal_static_reset($static_var);
-- 
2.3.8 (Apple Git-58)

