Encapsulate date formatting within the DateTime class [PREMIUM-4]
This commit is contained in:
@ -1,7 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\API\Endpoints\v1;
|
namespace MailPoet\API\Endpoints\v1;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use MailPoet\API\Endpoint as APIEndpoint;
|
use MailPoet\API\Endpoint as APIEndpoint;
|
||||||
use MailPoet\API\Error as APIError;
|
use MailPoet\API\Error as APIError;
|
||||||
use MailPoet\Services\Bridge;
|
use MailPoet\Services\Bridge;
|
||||||
@ -44,8 +43,7 @@ class Services extends APIEndpoint {
|
|||||||
} elseif($state == Bridge::MAILPOET_KEY_EXPIRING) {
|
} elseif($state == Bridge::MAILPOET_KEY_EXPIRING) {
|
||||||
$success_message = sprintf(
|
$success_message = sprintf(
|
||||||
__('Your MailPoet key expires on %s!', 'mailpoet'),
|
__('Your MailPoet key expires on %s!', 'mailpoet'),
|
||||||
Carbon::createFromTimestamp(strtotime($result['data']['expire_at']))
|
$this->date_time->formatDate(strtotime($result['data']['expire_at']))
|
||||||
->format($this->date_time->getDateFormat())
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,8 +92,7 @@ class Services extends APIEndpoint {
|
|||||||
} elseif($state == Bridge::PREMIUM_KEY_EXPIRING) {
|
} elseif($state == Bridge::PREMIUM_KEY_EXPIRING) {
|
||||||
$success_message = sprintf(
|
$success_message = sprintf(
|
||||||
__('Your license key expires on %s.', 'mailpoet'),
|
__('Your license key expires on %s.', 'mailpoet'),
|
||||||
Carbon::createFromTimestamp(strtotime($result['data']['expire_at']))
|
$this->date_time->formatDate(strtotime($result['data']['expire_at']))
|
||||||
->format($this->date_time->getDateFormat())
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ class ServicesChecker {
|
|||||||
) {
|
) {
|
||||||
if($display_error_notice) {
|
if($display_error_notice) {
|
||||||
$date_time = new DateTime();
|
$date_time = new DateTime();
|
||||||
$date = date($date_time->getDateFormat(), strtotime($mss_key['data']['expire_at']));
|
$date = $date_time->formatDate(strtotime($mss_key['data']['expire_at']));
|
||||||
$error = Helpers::replaceLinkTags(
|
$error = Helpers::replaceLinkTags(
|
||||||
__('Your newsletters are awesome! Don\'t forget to [link]upgrade your MailPoet email plan[/link] by %s to keep sending them to your subscribers.', 'mailpoet'),
|
__('Your newsletters are awesome! Don\'t forget to [link]upgrade your MailPoet email plan[/link] by %s to keep sending them to your subscribers.', 'mailpoet'),
|
||||||
'https://account.mailpoet.com?s=' . Subscriber::getTotalSubscribers()
|
'https://account.mailpoet.com?s=' . Subscriber::getTotalSubscribers()
|
||||||
@ -77,7 +77,7 @@ class ServicesChecker {
|
|||||||
) {
|
) {
|
||||||
if($display_error_notice) {
|
if($display_error_notice) {
|
||||||
$date_time = new DateTime();
|
$date_time = new DateTime();
|
||||||
$date = date($date_time->getDateFormat(), strtotime($premium_key['data']['expire_at']));
|
$date = $date_time->formatDate(strtotime($premium_key['data']['expire_at']));
|
||||||
$error = Helpers::replaceLinkTags(
|
$error = Helpers::replaceLinkTags(
|
||||||
__('Your License Key is expiring! Don\'t forget to [link]renew your license[/link] by %s to keep enjoying automatic updates and Premium support.', 'mailpoet'),
|
__('Your License Key is expiring! Don\'t forget to [link]renew your license[/link] by %s to keep enjoying automatic updates and Premium support.', 'mailpoet'),
|
||||||
'https://account.mailpoet.com'
|
'https://account.mailpoet.com'
|
||||||
|
@ -38,6 +38,12 @@ class DateTime {
|
|||||||
return date($format, $timestamp);
|
return date($format, $timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatDate($timestamp, $format=false) {
|
||||||
|
if (empty($format)) $format = $this->getDateFormat();
|
||||||
|
|
||||||
|
return date($format, $timestamp);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a list of time strings within an interval,
|
* Generates a list of time strings within an interval,
|
||||||
* formatted and mapped from DEFAULT_TIME_FORMAT to WordPress time strings.
|
* formatted and mapped from DEFAULT_TIME_FORMAT to WordPress time strings.
|
||||||
|
@ -42,9 +42,17 @@ class DateTimeTest extends MailPoetTest {
|
|||||||
function testFormatTime() {
|
function testFormatTime() {
|
||||||
$timestamp = 1234567;
|
$timestamp = 1234567;
|
||||||
$format = "H:i:s";
|
$format = "H:i:s";
|
||||||
|
expect($this->date_time->formatTime($timestamp))->equals(date($this->date_time->getTimeFormat(), $timestamp));
|
||||||
expect($this->date_time->formatTime($timestamp, $format))->equals(date($format, $timestamp));
|
expect($this->date_time->formatTime($timestamp, $format))->equals(date($format, $timestamp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testFormatDate() {
|
||||||
|
$timestamp = 1234567;
|
||||||
|
$format = "Y-m-d";
|
||||||
|
expect($this->date_time->formatDate($timestamp))->equals(date($this->date_time->getDateFormat(), $timestamp));
|
||||||
|
expect($this->date_time->formatDate($timestamp, $format))->equals(date($format, $timestamp));
|
||||||
|
}
|
||||||
|
|
||||||
function testTimeInterval() {
|
function testTimeInterval() {
|
||||||
$one_hour_interval = array_keys($this->date_time->getTimeInterval(
|
$one_hour_interval = array_keys($this->date_time->getTimeInterval(
|
||||||
'00:00:00',
|
'00:00:00',
|
||||||
|
Reference in New Issue
Block a user