DateTime

MaplePHP Format Date Class with Translations Library

This PHP library, named MaplePHP\DTO\Format\DateTime, extends the DateTime class and provides additional functionality for formatting dates with translations. Below is a guide to the methods available in this library.

Date Formatting Methods

format(string $format): string

  • Formats the date according to the specified format and translates month and day names.

  • Parameters:

    • $format: The format string.

  • Returns:

    • The formatted date string.

Translation Methods

getTranslations(): array

  • Gets all acceptable translation data.

  • Returns:

    • An array of translation data.

setTranslation(string $key, array $arr): self

  • Creates or updates a translation for a specific language key.

  • Parameters:

    • $key: Language key.

    • $arr: Array of translations.

  • Returns:

    • An instance of the date format.

setLanguage(string $lang): self

  • Changes the expected language for translations.

  • Parameters:

    • $lang: Language key.

  • Returns:

    • An instance of the date format.

  • Throws:

    • Exception if the translation for the specified language does not exist.

Utility Methods

clone(): self

  • Creates a clone of the current date format instance.

  • Returns:

    • A new instance of the date format.

withValue(string $value): self

  • Creates a new instance of the date format with a different date value.

  • Parameters:

    • $value: The new date value.

  • Returns:

    • A new instance of the date format.

Magic Methods

__toString(): string

  • Gets the string representation of the date in the format "Y/m/d H:i".

__unserialize(array $data): void

  • Unserializes the data for the date format.

Constants

DEFAULT_LANG

  • Default language key.

LANG

  • Array of month, day, and weekday name translations for different languages.

Last updated