Adamw has uploaded a new change for review.
https://gerrit.wikimedia.org/r/94470
Change subject: correct some timezone errors in recurring code
......................................................................
correct some timezone errors in recurring code
Change-Id: I687522d57036fb2c3147c9c26e11a69b0e1114a9
NOTE: there are more errors.
---
M sites/all/modules/wmf_common/wmf_civicrm/recurring.inc
M sites/all/modules/wmf_common/wmf_dates.php
2 files changed, 22 insertions(+), 4 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm
refs/changes/70/94470/1
diff --git a/sites/all/modules/wmf_common/wmf_civicrm/recurring.inc
b/sites/all/modules/wmf_common/wmf_civicrm/recurring.inc
index b56a1f9..1b424fb 100644
--- a/sites/all/modules/wmf_common/wmf_civicrm/recurring.inc
+++ b/sites/all/modules/wmf_common/wmf_civicrm/recurring.inc
@@ -74,7 +74,7 @@
throw new WmfException('IMPORT_SUBSCRIPTION', $error_message );
}
- $msg[ 'cycle_day' ] = (integer) date( 'j', $msg[ 'date' ] );
+ $msg['cycle_day'] = wmf_civicrm_get_cycle_day( $msg['date'] );
$next_sched_contribution =
wmf_civicrm_get_next_sched_contribution_date_for_month( $msg );
@@ -88,8 +88,8 @@
'frequency_unit' => $msg[ 'frequency_unit' ],
'frequency_interval' => $msg[ 'frequency_interval' ],
'installments' => $msg[ 'installments' ],
- 'start_date' => date( 'Y-m-d H:i:s', $msg[ 'date' ] ),
- 'create_date' => date( 'Y-m-d H:i:s', $msg[ 'date' ] ),
+ 'start_date' => wmf_common_date_unix_to_civicrm( $msg[ 'date' ] ),
+ 'create_date' => wmf_common_date_unix_to_civicrm( $msg[ 'date' ] ),
#FIXME:
'processor_id' => 1,
'cycle_day' => $msg[ 'cycle_day' ],
@@ -290,6 +290,14 @@
}
/**
+ * @param timestamp $date as unix seconds
+ * @return day of the month for this date
+ */
+function wmf_civicrm_get_cycle_day( $date ) {
+ return intval( gmdate( 'j', $date ) );
+}
+
+/**
* Increment the $date by one $interval, landing as close as possible to
* $cycle_day. Have only implemented the $interval of 'month' at this point.
* Might wire up more later as-needed.
@@ -304,7 +312,7 @@
case 'month':
default:
if ( is_null( $cycle_day ) ){
- $cycle_day = (int) date('j', $date);
+ $cycle_day = wmf_civicrm_get_cycle_day( $date );
}
$month = (int) date('n', $date);
$year = (int) date('Y', $date);
diff --git a/sites/all/modules/wmf_common/wmf_dates.php
b/sites/all/modules/wmf_common/wmf_dates.php
index 5eaaf11..aa170ba 100644
--- a/sites/all/modules/wmf_common/wmf_dates.php
+++ b/sites/all/modules/wmf_common/wmf_dates.php
@@ -94,3 +94,13 @@
function wmf_common_date_unix_to_sql( $unixtime ) {
return wmf_common_date_format_using_utc( "YmdHis", $unixtime );
}
+
+/**
+ * Convert civi api Y-m-d H:i:s to unix seconds
+ * @param string $date as Civi timestamp, returned by an api call
+ * @return int unix epoch seconds
+ */
+function wmf_common_date_civicrm_to_unix( $date ) {
+ return DateTime::createFromFormat( 'Y-m-d H:i:s', $date, new DateTimeZone(
'UTC' ) )
+ ->getTimestamp();
+}
--
To view, visit https://gerrit.wikimedia.org/r/94470
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I687522d57036fb2c3147c9c26e11a69b0e1114a9
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master
Gerrit-Owner: Adamw <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits