forked from joomla/super-powers
Update 2024-10-11 12:23:31
This commit is contained in:
parent
7ce368db75
commit
7096370b60
@ -85,6 +85,7 @@ This repository contains an index (see below) of all the approved powers within
|
||||
- **abstract class ArrayHelper** | [Details](src/0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a) | [Code](src/0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a/code.php) | [Settings](src/0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a/settings.json) | SPK: `Super---0a59c65c_9daf_4bc9_baf4_e063ff9e6a8a---Power`
|
||||
- **abstract class Base64Helper** | [Details](src/64a6ff6c-069c-4a11-a76b-db5e36c27690) | [Code](src/64a6ff6c-069c-4a11-a76b-db5e36c27690/code.php) | [Settings](src/64a6ff6c-069c-4a11-a76b-db5e36c27690/settings.json) | SPK: `Super---64a6ff6c_069c_4a11_a76b_db5e36c27690---Power`
|
||||
- **abstract class ClassHelper** | [Details](src/13c2cac1-a70d-42d7-99fc-eb7ac3443069) | [Code](src/13c2cac1-a70d-42d7-99fc-eb7ac3443069/code.php) | [Settings](src/13c2cac1-a70d-42d7-99fc-eb7ac3443069/settings.json) | SPK: `Super---13c2cac1_a70d_42d7_99fc_eb7ac3443069---Power`
|
||||
- **abstract class DateHelper** | [Details](src/993fe913-8e36-4800-a5f7-544aa728ee48) | [Code](src/993fe913-8e36-4800-a5f7-544aa728ee48/code.php) | [Settings](src/993fe913-8e36-4800-a5f7-544aa728ee48/settings.json) | SPK: `Super---993fe913_8e36_4800_a5f7_544aa728ee48---Power`
|
||||
- **abstract class FileHelper** | [Details](src/a223b31e-ea1d-4cdf-92ae-5f9becffaff0) | [Code](src/a223b31e-ea1d-4cdf-92ae-5f9becffaff0/code.php) | [Settings](src/a223b31e-ea1d-4cdf-92ae-5f9becffaff0/settings.json) | SPK: `Super---a223b31e_ea1d_4cdf_92ae_5f9becffaff0---Power`
|
||||
- **abstract class FormHelper** | [Details](src/1198aecf-84c6-45d2-aea8-d531aa4afdfa) | [Code](src/1198aecf-84c6-45d2-aea8-d531aa4afdfa/code.php) | [Settings](src/1198aecf-84c6-45d2-aea8-d531aa4afdfa/settings.json) | SPK: `Super---1198aecf_84c6_45d2_aea8_d531aa4afdfa---Power`
|
||||
- **abstract class GetHelper** | [Details](src/db87c339-5bb6-4291-a7ef-2c48ea1b06bc) | [Code](src/db87c339-5bb6-4291-a7ef-2c48ea1b06bc/code.php) | [Settings](src/db87c339-5bb6-4291-a7ef-2c48ea1b06bc/settings.json) | SPK: `Super---db87c339_5bb6_4291_a7ef_2c48ea1b06bc---Power`
|
||||
@ -94,6 +95,7 @@ This repository contains an index (see below) of all the approved powers within
|
||||
- **abstract class MathHelper** | [Details](src/152c8793-8b75-4715-996a-257b9f65451c) | [Code](src/152c8793-8b75-4715-996a-257b9f65451c/code.php) | [Settings](src/152c8793-8b75-4715-996a-257b9f65451c/settings.json) | SPK: `Super---152c8793_8b75_4715_996a_257b9f65451c---Power`
|
||||
- **abstract class MimeHelper** | [Details](src/f11dc790-713e-4706-9a85-a318ed3ad56e) | [Code](src/f11dc790-713e-4706-9a85-a318ed3ad56e/code.php) | [Settings](src/f11dc790-713e-4706-9a85-a318ed3ad56e/settings.json) | SPK: `Super---f11dc790_713e_4706_9a85_a318ed3ad56e---Power`
|
||||
- **abstract class ObjectHelper** | [Details](src/91004529-94a9-4590-b842-e7c6b624ecf5) | [Code](src/91004529-94a9-4590-b842-e7c6b624ecf5/code.php) | [Settings](src/91004529-94a9-4590-b842-e7c6b624ecf5/settings.json) | SPK: `Super---91004529_94a9_4590_b842_e7c6b624ecf5---Power`
|
||||
- **abstract class SessionHelper** | [Details](src/47a63728-cd5d-4d53-99cf-2409bd1c744c) | [Code](src/47a63728-cd5d-4d53-99cf-2409bd1c744c/code.php) | [Settings](src/47a63728-cd5d-4d53-99cf-2409bd1c744c/settings.json) | SPK: `Super---47a63728_cd5d_4d53_99cf_2409bd1c744c---Power`
|
||||
- **abstract class StringHelper** | [Details](src/1f28cb53-60d9-4db1-b517-3c7dc6b429ef) | [Code](src/1f28cb53-60d9-4db1-b517-3c7dc6b429ef/code.php) | [Settings](src/1f28cb53-60d9-4db1-b517-3c7dc6b429ef/settings.json) | SPK: `Super---1f28cb53_60d9_4db1_b517_3c7dc6b429ef---Power`
|
||||
- **abstract class UploadHelper** | [Details](src/d7600b43-771a-4747-9f5d-952765721799) | [Code](src/d7600b43-771a-4747-9f5d-952765721799/code.php) | [Settings](src/d7600b43-771a-4747-9f5d-952765721799/settings.json) | SPK: `Super---d7600b43_771a_4747_9f5d_952765721799---Power`
|
||||
- **Namespace**: [VDM\Joomla\Abstraction\Remote](#vdm-joomla-abstraction-remote)
|
||||
@ -128,7 +130,6 @@ This repository contains an index (see below) of all the approved powers within
|
||||
- **final class SchemaChecker** | [Details](src/709d7294-9a43-46e2-b64e-d16a16f0eab1) | [Code](src/709d7294-9a43-46e2-b64e-d16a16f0eab1/code.php) | [Settings](src/709d7294-9a43-46e2-b64e-d16a16f0eab1/settings.json) | SPK: `Super---709d7294_9a43_46e2_b64e_d16a16f0eab1---Power`
|
||||
- **Namespace**: [VDM\Joomla\Componentbuilder\Utilities](#vdm-joomla-componentbuilder-utilities)
|
||||
|
||||
- **abstract class SessionHelper** | [Details](src/47a63728-cd5d-4d53-99cf-2409bd1c744c) | [Code](src/47a63728-cd5d-4d53-99cf-2409bd1c744c/code.php) | [Settings](src/47a63728-cd5d-4d53-99cf-2409bd1c744c/settings.json) | SPK: `Super---47a63728_cd5d_4d53_99cf_2409bd1c744c---Power`
|
||||
- **abstract class UserHelper** | [Details](src/7832a726-87b6-4e95-887e-7b725d3fab8f) | [Code](src/7832a726-87b6-4e95-887e-7b725d3fab8f/code.php) | [Settings](src/7832a726-87b6-4e95-887e-7b725d3fab8f/settings.json) | SPK: `Super---7832a726_87b6_4e95_887e_7b725d3fab8f---Power`
|
||||
- **Namespace**: [VDM\Joomla\Data\Action](#vdm-joomla-data-action)
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# abstract class SessionHelper (Details)
|
||||
> namespace: **VDM\Joomla\Componentbuilder\Utilities**
|
||||
> namespace: **VDM\Joomla\Utilities**
|
||||
|
||||
```uml
|
||||
@startuml
|
||||
|
@ -9,7 +9,7 @@
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Utilities;
|
||||
namespace VDM\Joomla\Utilities;
|
||||
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
|
@ -11,7 +11,7 @@
|
||||
"type": "abstract class",
|
||||
"use_selection": null,
|
||||
"extendsinterfaces": null,
|
||||
"namespace": "[[[NamespacePrefix]]]\\Joomla\\[[[ComponentNamespace]]].Utilities.SessionHelper",
|
||||
"namespace": "[[[NamespacePrefix]]]\\Joomla\\Utilities.SessionHelper",
|
||||
"description": "Simple Session\r\n\r\n@since 5.0.2",
|
||||
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2020\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
|
||||
"head": "use Joomla\\CMS\\Factory;\r\nuse Joomla\\CMS\\Session\\Session;",
|
||||
|
187
src/993fe913-8e36-4800-a5f7-544aa728ee48/README.md
Normal file
187
src/993fe913-8e36-4800-a5f7-544aa728ee48/README.md
Normal file
@ -0,0 +1,187 @@
|
||||
```
|
||||
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# abstract class DateHelper (Details)
|
||||
> namespace: **VDM\Joomla\Utilities**
|
||||
|
||||
```uml
|
||||
@startuml
|
||||
abstract DateHelper #Orange {
|
||||
+ {static} fancyDate(string|int $date, bool $checkStamp = true) : string
|
||||
+ {static} fancyDynamicDate(string|int $date, bool $checkStamp = true) : string
|
||||
+ {static} fancyDayTimeDate(string|int $date, bool $checkStamp = true) : string
|
||||
+ {static} fancyDateTime(string|int $date, bool $checkStamp = true) : string
|
||||
+ {static} fancyTime(string|int $date, bool $checkStamp = true) : string
|
||||
+ {static} setDayName(string|int $date, bool $checkStamp = true) : string
|
||||
+ {static} setMonthName(string|int $date, bool $checkStamp = true) : string
|
||||
+ {static} setDay(string|int $date, bool $checkStamp = true) : string
|
||||
+ {static} setMonth(string|int $date, bool $checkStamp = true) : string
|
||||
+ {static} setYear(string|int $date, bool $checkStamp = true) : string
|
||||
+ {static} setYearMonth(string|int $date, string $spacer = '/', ...) : string
|
||||
+ {static} setYearMonthDay(string|int $date, string $spacer = '/', ...) : string
|
||||
+ {static} setDayMonthYear(string|int $date, string $spacer = '/', ...) : string
|
||||
+ {static} getValidTimestamp(string|int $date, bool $checkStamp) : int
|
||||
+ {static} isValidTimeStamp(mixed $timestamp) : bool
|
||||
+ {static} isValidateDate(string $date, string $format = 'Y-m-d H:i:s') : bool
|
||||
}
|
||||
|
||||
note right of DateHelper::fancyDate
|
||||
Convert a date to a human-readable fancy format (e.g., "1st of January 2024").
|
||||
|
||||
since: 3.0.0
|
||||
return: string
|
||||
end note
|
||||
|
||||
note left of DateHelper::fancyDynamicDate
|
||||
Get a formatted date based on the time period (dynamic format based on age of the date).
|
||||
|
||||
since: 3.0.0
|
||||
return: string
|
||||
end note
|
||||
|
||||
note right of DateHelper::fancyDayTimeDate
|
||||
Convert a date to a human-readable day, time, and date format (e.g., "Mon 12am 1st of January 2024").
|
||||
|
||||
since: 3.0.0
|
||||
return: string
|
||||
end note
|
||||
|
||||
note left of DateHelper::fancyDateTime
|
||||
Convert a date to a human-readable time and date format (e.g., "(12:00) 1st of January 2024").
|
||||
|
||||
since: 3.0.0
|
||||
return: string
|
||||
end note
|
||||
|
||||
note right of DateHelper::fancyTime
|
||||
Convert a time to a human-readable format (e.g., "12:00").
|
||||
|
||||
since: 3.0.0
|
||||
return: string
|
||||
end note
|
||||
|
||||
note left of DateHelper::setDayName
|
||||
Convert a date to the day name (e.g., "Sunday").
|
||||
|
||||
since: 3.0.0
|
||||
return: string
|
||||
end note
|
||||
|
||||
note right of DateHelper::setMonthName
|
||||
Convert a date to the month name (e.g., "January").
|
||||
|
||||
since: 3.0.0
|
||||
return: string
|
||||
end note
|
||||
|
||||
note left of DateHelper::setDay
|
||||
Convert a date to the day with suffix (e.g., "1st").
|
||||
|
||||
since: 3.0.0
|
||||
return: string
|
||||
end note
|
||||
|
||||
note right of DateHelper::setMonth
|
||||
Convert a date to the numeric month (e.g., "5").
|
||||
|
||||
since: 3.0.0
|
||||
return: string
|
||||
end note
|
||||
|
||||
note left of DateHelper::setYear
|
||||
Convert a date to the full year (e.g., "2024").
|
||||
|
||||
since: 3.0.0
|
||||
return: string
|
||||
end note
|
||||
|
||||
note right of DateHelper::setYearMonth
|
||||
Convert a date to a year/month format (e.g., "2024/05").
|
||||
|
||||
since: 3.0.0
|
||||
return: string
|
||||
|
||||
arguments:
|
||||
string|int $date
|
||||
string $spacer = '/'
|
||||
bool $checkStamp = true
|
||||
end note
|
||||
|
||||
note left of DateHelper::setYearMonthDay
|
||||
Convert a date to a year/month/day format (e.g., "2024/05/03").
|
||||
|
||||
since: 3.0.0
|
||||
return: string
|
||||
|
||||
arguments:
|
||||
string|int $date
|
||||
string $spacer = '/'
|
||||
bool $checkStamp = true
|
||||
end note
|
||||
|
||||
note right of DateHelper::setDayMonthYear
|
||||
Convert a date to a day/month/year format (e.g., "03/05/2024").
|
||||
|
||||
since: 3.0.0
|
||||
return: string
|
||||
|
||||
arguments:
|
||||
string|int $date
|
||||
string $spacer = '/'
|
||||
bool $checkStamp = true
|
||||
end note
|
||||
|
||||
note left of DateHelper::getValidTimestamp
|
||||
Convert a date string to a valid timestamp.
|
||||
|
||||
since: 3.0.0
|
||||
return: int
|
||||
end note
|
||||
|
||||
note right of DateHelper::isValidTimeStamp
|
||||
Check if the input is a valid Unix timestamp.
|
||||
|
||||
since: 3.0.0
|
||||
return: bool
|
||||
end note
|
||||
|
||||
note left of DateHelper::isValidateDate
|
||||
Check if a string is a valid date according to the specified format.
|
||||
|
||||
since: 3.0.0
|
||||
return: bool
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
The Power feature in JCB allows you to write PHP classes and their implementations, making it easy to include them in your Joomla project. JCB handles linking, autoloading, namespacing, and folder structure creation for you.
|
||||
|
||||
By using the SPK (Super Power Key) in your custom code (replacing the class name in your code with the SPK), JCB will automatically pull the power from the repository into your project. This makes it available in your JCB instance, allowing you to edit it and include the class in your generated Joomla component.
|
||||
|
||||
JCB uses placeholders like [[[`NamespacePrefix`]]] and [[[`ComponentNamespace`]]] in namespacing to prevent collisions and improve reusability across different JCB systems. You can also set the **JCB powers path** globally or per component under the **Dynamic Integration** tab, providing flexibility and easy maintainability.
|
||||
|
||||
To add this specific Power to your project in JCB:
|
||||
|
||||
> simply use this SPK
|
||||
```
|
||||
Super---993fe913_8e36_4800_a5f7_544aa728ee48---Power
|
||||
```
|
||||
> remember to replace the `---` with `___` to activate this Power in your code
|
||||
|
||||
---
|
||||
```
|
||||
██╗ ██████╗██████╗
|
||||
██║██╔════╝██╔══██╗
|
||||
██║██║ ██████╔╝
|
||||
██ ██║██║ ██╔══██╗
|
||||
╚█████╔╝╚██████╗██████╔╝
|
||||
╚════╝ ╚═════╝╚═════╝
|
||||
```
|
||||
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
|
294
src/993fe913-8e36-4800-a5f7-544aa728ee48/code.php
Normal file
294
src/993fe913-8e36-4800-a5f7-544aa728ee48/code.php
Normal file
@ -0,0 +1,294 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2020
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Utilities;
|
||||
|
||||
|
||||
/**
|
||||
* Simple Date Helper
|
||||
*
|
||||
* @since 5.0.2
|
||||
*/
|
||||
abstract class DateHelper
|
||||
{
|
||||
/**
|
||||
* Convert a date to a human-readable fancy format (e.g., "1st of January 2024").
|
||||
*
|
||||
* @param string|int $date The date as a string or timestamp.
|
||||
* @param bool $checkStamp Whether to check if the input is a timestamp.
|
||||
*
|
||||
* @return string Formatted date.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public static function fancyDate($date, bool $checkStamp = true): string
|
||||
{
|
||||
$date = static::getValidTimestamp($date, $checkStamp);
|
||||
|
||||
return date('jS \o\f F Y', $date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a formatted date based on the time period (dynamic format based on age of the date).
|
||||
*
|
||||
* @param string|int $date The date as a string or timestamp.
|
||||
* @param bool $checkStamp Whether to check if the input is a timestamp.
|
||||
*
|
||||
* @return string Formatted date.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public static function fancyDynamicDate($date, bool $checkStamp = true): string
|
||||
{
|
||||
$date = static::getValidTimestamp($date, $checkStamp);
|
||||
|
||||
// If older than a year, use m/d/y format.
|
||||
if (date('Y', $date) < date('Y', strtotime('-1 year')))
|
||||
{
|
||||
return date('m/d/y', $date);
|
||||
}
|
||||
|
||||
// If it's the same day, return the time.
|
||||
if ($date > strtotime('-1 day'))
|
||||
{
|
||||
return date('g:i A', $date);
|
||||
}
|
||||
|
||||
// Otherwise, return the month and day.
|
||||
return date('M j', $date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a date to a human-readable day, time, and date format (e.g., "Mon 12am 1st of January 2024").
|
||||
*
|
||||
* @param string|int $date The date as a string or timestamp.
|
||||
* @param bool $checkStamp Whether to check if the input is a timestamp.
|
||||
*
|
||||
* @return string Formatted day, time, and date.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public static function fancyDayTimeDate($date, bool $checkStamp = true): string
|
||||
{
|
||||
$date = static::getValidTimestamp($date, $checkStamp);
|
||||
|
||||
return date('D gA jS \o\f F Y', $date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a date to a human-readable time and date format (e.g., "(12:00) 1st of January 2024").
|
||||
*
|
||||
* @param string|int $date The date as a string or timestamp.
|
||||
* @param bool $checkStamp Whether to check if the input is a timestamp.
|
||||
*
|
||||
* @return string Formatted time and date.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public static function fancyDateTime($date, bool $checkStamp = true): string
|
||||
{
|
||||
$date = static::getValidTimestamp($date, $checkStamp);
|
||||
|
||||
return date('(G:i) jS \o\f F Y', $time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a time to a human-readable format (e.g., "12:00").
|
||||
*
|
||||
* @param string|int $date The date as a string or timestamp.
|
||||
* @param bool $checkStamp Whether to check if the input is a timestamp.
|
||||
*
|
||||
* @return string Formatted time.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public static function fancyTime($date, bool $checkStamp = true): string
|
||||
{
|
||||
$date = static::getValidTimestamp($date, $checkStamp);
|
||||
|
||||
return date('G:i', $date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a date to the day name (e.g., "Sunday").
|
||||
*
|
||||
* @param string|int $date The date as a string or timestamp.
|
||||
* @param bool $checkStamp Whether to check if the input is a timestamp.
|
||||
*
|
||||
* @return string Day name.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public static function setDayName($date, bool $checkStamp = true): string
|
||||
{
|
||||
$date = static::getValidTimestamp($date, $checkStamp);
|
||||
|
||||
return date('l', $date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a date to the month name (e.g., "January").
|
||||
*
|
||||
* @param string|int $date The date as a string or timestamp.
|
||||
* @param bool $checkStamp Whether to check if the input is a timestamp.
|
||||
*
|
||||
* @return string Month name.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public static function setMonthName($date, bool $checkStamp = true): string
|
||||
{
|
||||
$date = static::getValidTimestamp($date, $checkStamp);
|
||||
|
||||
return date('F', $date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a date to the day with suffix (e.g., "1st").
|
||||
*
|
||||
* @param string|int $date The date as a string or timestamp.
|
||||
* @param bool $checkStamp Whether to check if the input is a timestamp.
|
||||
*
|
||||
* @return string Day with suffix.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public static function setDay($date, bool $checkStamp = true): string
|
||||
{
|
||||
$date = static::getValidTimestamp($date, $checkStamp);
|
||||
|
||||
return date('jS', $date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a date to the numeric month (e.g., "5").
|
||||
*
|
||||
* @param string|int $date The date as a string or timestamp.
|
||||
* @param bool $checkStamp Whether to check if the input is a timestamp.
|
||||
*
|
||||
* @return string Numeric month.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public static function setMonth($date, bool $checkStamp = true): string
|
||||
{
|
||||
$date = static::getValidTimestamp($date, $checkStamp);
|
||||
|
||||
return date('n', $date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a date to the full year (e.g., "2024").
|
||||
*
|
||||
* @param string|int $date The date as a string or timestamp.
|
||||
* @param bool $checkStamp Whether to check if the input is a timestamp.
|
||||
*
|
||||
* @return string Full year.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public static function setYear($date, bool $checkStamp = true): string
|
||||
{
|
||||
$date = static::getValidTimestamp($date, $checkStamp);
|
||||
|
||||
return date('Y', $date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a date to a year/month format (e.g., "2024/05").
|
||||
*
|
||||
* @param string|int $date The date as a string or timestamp.
|
||||
* @param string $spacer The spacer between year and month.
|
||||
* @param bool $checkStamp Whether to check if the input is a timestamp.
|
||||
*
|
||||
* @return string Year/Month format.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public static function setYearMonth($date, string $spacer = '/', bool $checkStamp = true): string
|
||||
{
|
||||
$date = static::getValidTimestamp($date, $checkStamp);
|
||||
|
||||
return date('Y' . $spacer . 'm', $date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a date to a year/month/day format (e.g., "2024/05/03").
|
||||
*
|
||||
* @param string|int $date The date as a string or timestamp.
|
||||
* @param string $spacer The spacer between year and month.
|
||||
* @param bool $checkStamp Whether to check if the input is a timestamp.
|
||||
*
|
||||
* @return string Year/Month/Day format.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public static function setYearMonthDay($date, string $spacer = '/', bool $checkStamp = true): string
|
||||
{
|
||||
$date = static::getValidTimestamp($date, $checkStamp);
|
||||
|
||||
return date('Y' . $spacer . 'm' . $spacer . 'd', $date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a date to a day/month/year format (e.g., "03/05/2024").
|
||||
*
|
||||
* @param string|int $date The date as a string or timestamp.
|
||||
* @param string $spacer The spacer between year and month.
|
||||
* @param bool $checkStamp Whether to check if the input is a timestamp.
|
||||
*
|
||||
* @return string Day/Month/Year format.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public static function setDayMonthYear($date, string $spacer = '/', bool $checkStamp = true): string
|
||||
{
|
||||
$date = static::getValidTimestamp($date, $checkStamp);
|
||||
|
||||
return date('d' . $spacer . 'm' . $spacer . 'Y', $date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a date string to a valid timestamp.
|
||||
*
|
||||
* @param string|int $date The date as a string or timestamp.
|
||||
* @param bool $checkStamp Whether to check if the input is a timestamp.
|
||||
*
|
||||
* @return int The valid timestamp.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public static function getValidTimestamp($date, bool $checkStamp): int
|
||||
{
|
||||
if ($checkStamp && !static::isValidTimeStamp($date))
|
||||
{
|
||||
$date = strtotime($date ?? 'Now');
|
||||
}
|
||||
|
||||
return (int) $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the input is a valid Unix timestamp.
|
||||
*
|
||||
* @param mixed $timestamp The timestamp to validate.
|
||||
*
|
||||
* @return bool True if valid timestamp, false otherwise.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public static function isValidTimeStamp($timestamp): bool
|
||||
{
|
||||
return (is_numeric($timestamp) && (int) $timestamp == $timestamp && $timestamp > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a string is a valid date according to the specified format.
|
||||
*
|
||||
* @param string $date The date string to validate.
|
||||
* @param string $format The format to check against (default is 'Y-m-d H:i:s').
|
||||
*
|
||||
* @return bool True if valid date, false otherwise.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public static function isValidateDate($date, string $format = 'Y-m-d H:i:s'): bool
|
||||
{
|
||||
$d = \DateTime::createFromFormat($format, $date);
|
||||
|
||||
return $d && $d->format($format) === $date;
|
||||
}
|
||||
}
|
||||
|
271
src/993fe913-8e36-4800-a5f7-544aa728ee48/code.power
Normal file
271
src/993fe913-8e36-4800-a5f7-544aa728ee48/code.power
Normal file
@ -0,0 +1,271 @@
|
||||
/**
|
||||
* Convert a date to a human-readable fancy format (e.g., "1st of January 2024").
|
||||
*
|
||||
* @param string|int $date The date as a string or timestamp.
|
||||
* @param bool $checkStamp Whether to check if the input is a timestamp.
|
||||
*
|
||||
* @return string Formatted date.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public static function fancyDate($date, bool $checkStamp = true): string
|
||||
{
|
||||
$date = static::getValidTimestamp($date, $checkStamp);
|
||||
|
||||
return date('jS \o\f F Y', $date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a formatted date based on the time period (dynamic format based on age of the date).
|
||||
*
|
||||
* @param string|int $date The date as a string or timestamp.
|
||||
* @param bool $checkStamp Whether to check if the input is a timestamp.
|
||||
*
|
||||
* @return string Formatted date.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public static function fancyDynamicDate($date, bool $checkStamp = true): string
|
||||
{
|
||||
$date = static::getValidTimestamp($date, $checkStamp);
|
||||
|
||||
// If older than a year, use m/d/y format.
|
||||
if (date('Y', $date) < date('Y', strtotime('-1 year')))
|
||||
{
|
||||
return date('m/d/y', $date);
|
||||
}
|
||||
|
||||
// If it's the same day, return the time.
|
||||
if ($date > strtotime('-1 day'))
|
||||
{
|
||||
return date('g:i A', $date);
|
||||
}
|
||||
|
||||
// Otherwise, return the month and day.
|
||||
return date('M j', $date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a date to a human-readable day, time, and date format (e.g., "Mon 12am 1st of January 2024").
|
||||
*
|
||||
* @param string|int $date The date as a string or timestamp.
|
||||
* @param bool $checkStamp Whether to check if the input is a timestamp.
|
||||
*
|
||||
* @return string Formatted day, time, and date.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public static function fancyDayTimeDate($date, bool $checkStamp = true): string
|
||||
{
|
||||
$date = static::getValidTimestamp($date, $checkStamp);
|
||||
|
||||
return date('D gA jS \o\f F Y', $date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a date to a human-readable time and date format (e.g., "(12:00) 1st of January 2024").
|
||||
*
|
||||
* @param string|int $date The date as a string or timestamp.
|
||||
* @param bool $checkStamp Whether to check if the input is a timestamp.
|
||||
*
|
||||
* @return string Formatted time and date.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public static function fancyDateTime($date, bool $checkStamp = true): string
|
||||
{
|
||||
$date = static::getValidTimestamp($date, $checkStamp);
|
||||
|
||||
return date('(G:i) jS \o\f F Y', $time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a time to a human-readable format (e.g., "12:00").
|
||||
*
|
||||
* @param string|int $date The date as a string or timestamp.
|
||||
* @param bool $checkStamp Whether to check if the input is a timestamp.
|
||||
*
|
||||
* @return string Formatted time.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public static function fancyTime($date, bool $checkStamp = true): string
|
||||
{
|
||||
$date = static::getValidTimestamp($date, $checkStamp);
|
||||
|
||||
return date('G:i', $date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a date to the day name (e.g., "Sunday").
|
||||
*
|
||||
* @param string|int $date The date as a string or timestamp.
|
||||
* @param bool $checkStamp Whether to check if the input is a timestamp.
|
||||
*
|
||||
* @return string Day name.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public static function setDayName($date, bool $checkStamp = true): string
|
||||
{
|
||||
$date = static::getValidTimestamp($date, $checkStamp);
|
||||
|
||||
return date('l', $date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a date to the month name (e.g., "January").
|
||||
*
|
||||
* @param string|int $date The date as a string or timestamp.
|
||||
* @param bool $checkStamp Whether to check if the input is a timestamp.
|
||||
*
|
||||
* @return string Month name.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public static function setMonthName($date, bool $checkStamp = true): string
|
||||
{
|
||||
$date = static::getValidTimestamp($date, $checkStamp);
|
||||
|
||||
return date('F', $date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a date to the day with suffix (e.g., "1st").
|
||||
*
|
||||
* @param string|int $date The date as a string or timestamp.
|
||||
* @param bool $checkStamp Whether to check if the input is a timestamp.
|
||||
*
|
||||
* @return string Day with suffix.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public static function setDay($date, bool $checkStamp = true): string
|
||||
{
|
||||
$date = static::getValidTimestamp($date, $checkStamp);
|
||||
|
||||
return date('jS', $date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a date to the numeric month (e.g., "5").
|
||||
*
|
||||
* @param string|int $date The date as a string or timestamp.
|
||||
* @param bool $checkStamp Whether to check if the input is a timestamp.
|
||||
*
|
||||
* @return string Numeric month.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public static function setMonth($date, bool $checkStamp = true): string
|
||||
{
|
||||
$date = static::getValidTimestamp($date, $checkStamp);
|
||||
|
||||
return date('n', $date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a date to the full year (e.g., "2024").
|
||||
*
|
||||
* @param string|int $date The date as a string or timestamp.
|
||||
* @param bool $checkStamp Whether to check if the input is a timestamp.
|
||||
*
|
||||
* @return string Full year.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public static function setYear($date, bool $checkStamp = true): string
|
||||
{
|
||||
$date = static::getValidTimestamp($date, $checkStamp);
|
||||
|
||||
return date('Y', $date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a date to a year/month format (e.g., "2024/05").
|
||||
*
|
||||
* @param string|int $date The date as a string or timestamp.
|
||||
* @param string $spacer The spacer between year and month.
|
||||
* @param bool $checkStamp Whether to check if the input is a timestamp.
|
||||
*
|
||||
* @return string Year/Month format.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public static function setYearMonth($date, string $spacer = '/', bool $checkStamp = true): string
|
||||
{
|
||||
$date = static::getValidTimestamp($date, $checkStamp);
|
||||
|
||||
return date('Y' . $spacer . 'm', $date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a date to a year/month/day format (e.g., "2024/05/03").
|
||||
*
|
||||
* @param string|int $date The date as a string or timestamp.
|
||||
* @param string $spacer The spacer between year and month.
|
||||
* @param bool $checkStamp Whether to check if the input is a timestamp.
|
||||
*
|
||||
* @return string Year/Month/Day format.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public static function setYearMonthDay($date, string $spacer = '/', bool $checkStamp = true): string
|
||||
{
|
||||
$date = static::getValidTimestamp($date, $checkStamp);
|
||||
|
||||
return date('Y' . $spacer . 'm' . $spacer . 'd', $date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a date to a day/month/year format (e.g., "03/05/2024").
|
||||
*
|
||||
* @param string|int $date The date as a string or timestamp.
|
||||
* @param string $spacer The spacer between year and month.
|
||||
* @param bool $checkStamp Whether to check if the input is a timestamp.
|
||||
*
|
||||
* @return string Day/Month/Year format.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public static function setDayMonthYear($date, string $spacer = '/', bool $checkStamp = true): string
|
||||
{
|
||||
$date = static::getValidTimestamp($date, $checkStamp);
|
||||
|
||||
return date('d' . $spacer . 'm' . $spacer . 'Y', $date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a date string to a valid timestamp.
|
||||
*
|
||||
* @param string|int $date The date as a string or timestamp.
|
||||
* @param bool $checkStamp Whether to check if the input is a timestamp.
|
||||
*
|
||||
* @return int The valid timestamp.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public static function getValidTimestamp($date, bool $checkStamp): int
|
||||
{
|
||||
if ($checkStamp && !static::isValidTimeStamp($date))
|
||||
{
|
||||
$date = strtotime($date ?? 'Now');
|
||||
}
|
||||
|
||||
return (int) $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the input is a valid Unix timestamp.
|
||||
*
|
||||
* @param mixed $timestamp The timestamp to validate.
|
||||
*
|
||||
* @return bool True if valid timestamp, false otherwise.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public static function isValidTimeStamp($timestamp): bool
|
||||
{
|
||||
return (is_numeric($timestamp) && (int) $timestamp == $timestamp && $timestamp > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a string is a valid date according to the specified format.
|
||||
*
|
||||
* @param string $date The date string to validate.
|
||||
* @param string $format The format to check against (default is 'Y-m-d H:i:s').
|
||||
*
|
||||
* @return bool True if valid date, false otherwise.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public static function isValidateDate($date, string $format = 'Y-m-d H:i:s'): bool
|
||||
{
|
||||
$d = \DateTime::createFromFormat($format, $date);
|
||||
|
||||
return $d && $d->format($format) === $date;
|
||||
}
|
19
src/993fe913-8e36-4800-a5f7-544aa728ee48/settings.json
Normal file
19
src/993fe913-8e36-4800-a5f7-544aa728ee48/settings.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"add_head": "0",
|
||||
"add_licensing_template": "2",
|
||||
"extends": "",
|
||||
"guid": "993fe913-8e36-4800-a5f7-544aa728ee48",
|
||||
"implements": null,
|
||||
"load_selection": null,
|
||||
"name": "DateHelper",
|
||||
"power_version": "1.0.0",
|
||||
"system_name": "Utilities Date Helper",
|
||||
"type": "abstract class",
|
||||
"use_selection": null,
|
||||
"extendsinterfaces": null,
|
||||
"namespace": "[[[NamespacePrefix]]]\\Joomla\\Utilities.DateHelper",
|
||||
"description": "Simple Date Helper\r\n\r\n@since 5.0.2",
|
||||
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2020\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
|
||||
"head": "",
|
||||
"composer": ""
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -12,6 +12,8 @@
|
||||
namespace VDM\Joomla\Componentbuilder\Spreadsheet;
|
||||
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\User\User;
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
@ -105,7 +107,7 @@ final class Exporter
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
'color' => ['rgb' => '1171A3'],
|
||||
'size' => 12,
|
||||
'size' => 13,
|
||||
'name' => 'Verdana'
|
||||
]
|
||||
];
|
||||
@ -289,6 +291,8 @@ final class Exporter
|
||||
$sheet->getColumnDimension($columnIndex)->setAutoSize(true);
|
||||
$sheet->getStyle($columnIndex . $rowIndex)->applyFromArray($this->headerStyles);
|
||||
$sheet->getStyle($columnIndex . $rowIndex)->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
|
||||
$row_height = ($this->headerStyles['font']['size'] ?? 13) + 5;
|
||||
$sheet->getRowDimension($rowIndex)->setRowHeight($row_height);
|
||||
}
|
||||
elseif ($columnIndex === 'A')
|
||||
{
|
||||
|
@ -76,7 +76,7 @@
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
'color' => ['rgb' => '1171A3'],
|
||||
'size' => 12,
|
||||
'size' => 13,
|
||||
'name' => 'Verdana'
|
||||
]
|
||||
];
|
||||
@ -260,6 +260,8 @@
|
||||
$sheet->getColumnDimension($columnIndex)->setAutoSize(true);
|
||||
$sheet->getStyle($columnIndex . $rowIndex)->applyFromArray($this->headerStyles);
|
||||
$sheet->getStyle($columnIndex . $rowIndex)->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
|
||||
$row_height = ($this->headerStyles['font']['size'] ?? 13) + 5;
|
||||
$sheet->getRowDimension($rowIndex)->setRowHeight($row_height);
|
||||
}
|
||||
elseif ($columnIndex === 'A')
|
||||
{
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"add_head": "0",
|
||||
"add_head": "1",
|
||||
"add_licensing_template": "2",
|
||||
"extends": "",
|
||||
"guid": "e250638e-4a50-41f9-9172-db3e7f174d26",
|
||||
@ -19,7 +19,7 @@
|
||||
"namespace": "[[[NamespacePrefix]]]\\Joomla\\[[[ComponentNamespace]]].Spreadsheet.Exporter",
|
||||
"description": "Spreadsheet Exporter Class\r\n\r\n@since 3.2.0",
|
||||
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
|
||||
"head": "",
|
||||
"head": "use Joomla\\CMS\\Factory;\r\nuse Joomla\\CMS\\User\\User;",
|
||||
"composer": {
|
||||
"composer0": {
|
||||
"access_point": "phpspreadsheet\/vendor\/autoload.php",
|
||||
|
@ -332,7 +332,7 @@
|
||||
"47a63728-cd5d-4d53-99cf-2409bd1c744c": {
|
||||
"name": "SessionHelper",
|
||||
"type": "abstract class",
|
||||
"namespace": "VDM\\Joomla\\Componentbuilder\\Utilities",
|
||||
"namespace": "VDM\\Joomla\\Utilities",
|
||||
"code": "src\/47a63728-cd5d-4d53-99cf-2409bd1c744c\/code.php",
|
||||
"power": "src\/47a63728-cd5d-4d53-99cf-2409bd1c744c\/code.power",
|
||||
"settings": "src\/47a63728-cd5d-4d53-99cf-2409bd1c744c\/settings.json",
|
||||
@ -747,6 +747,17 @@
|
||||
"spk": "Super---95c02df3_fe0a_405b_b506_b7a5b8605b66---Power",
|
||||
"guid": "95c02df3-fe0a-405b-b506-b7a5b8605b66"
|
||||
},
|
||||
"993fe913-8e36-4800-a5f7-544aa728ee48": {
|
||||
"name": "DateHelper",
|
||||
"type": "abstract class",
|
||||
"namespace": "VDM\\Joomla\\Utilities",
|
||||
"code": "src\/993fe913-8e36-4800-a5f7-544aa728ee48\/code.php",
|
||||
"power": "src\/993fe913-8e36-4800-a5f7-544aa728ee48\/code.power",
|
||||
"settings": "src\/993fe913-8e36-4800-a5f7-544aa728ee48\/settings.json",
|
||||
"path": "src\/993fe913-8e36-4800-a5f7-544aa728ee48",
|
||||
"spk": "Super---993fe913_8e36_4800_a5f7_544aa728ee48---Power",
|
||||
"guid": "993fe913-8e36-4800-a5f7-544aa728ee48"
|
||||
},
|
||||
"9ae018a5-9064-40ed-ad69-9c1ed2a459f5": {
|
||||
"name": "ChunkReadFilter",
|
||||
"type": "final class",
|
||||
|
Loading…
Reference in New Issue
Block a user