Laravel Developer
David Carr
Web Developer
All Posts Archives Categories Authors
About Books Packages Templates Contact
Blog
All Posts Archives Categories Authors
About Books Packages Templates Contact
Laravel Xero
Laravel Packages
Laravel Microsoft Graph Laravel Xero Laravel Sent Emails Laravel Dropbox Laravel Box Laravel Companies House Laravel Countries Laravel Eventbrite Laravel Blade Components
PHP Packages
PDO Wrapper PHP find and replace JSON SQL Import IMAP Export CSV Pagination
v1
Navigation
  • Introduction
  • Install
  • Commands
  • Middleware
  • Is Connected
  • Disconnect
  • Tenant
  • Helpers
  • DTOs
  • Enums
  • Contacts
  • Credit Notes
  • Invoices
  • Webhooks
Navigation
  • Introduction
  • Install
  • Commands
  • Middleware
  • Is Connected
  • Disconnect
  • Tenant
  • Helpers
  • DTOs
  • Enums
  • Contacts
  • Credit Notes
  • Invoices
  • Webhooks

Helpers

Available Methods

formatDate()

Parses and formats date strings, with special handling for Microsoft JSON date format.

Signature

public static function formatDate(string $date, string $format = 'Y-m-d H:i:s'): string

Parameters

  • $date (string): The date string to format
  • $format (string, optional): The desired output format using PHP date format characters. Default: 'Y-m-d H:i:s'

Return Value

  • string: The formatted date string, or an empty string if the date cannot be parsed

Usage Examples

  1. Formatting a standard date string:
$formattedDate = Xero::formatDate('2023-09-15');
// Returns: '2023-09-15 00:00:00'

$formattedDate = Xero::formatDate('2023-09-15', 'd/m/Y');
// Returns: '15/09/2023'
  1. Handling Microsoft JSON date format:
$formattedDate = Xero::formatDate('/Date(1663257600000+0100)/');
// Returns the date formatted as 'Y-m-d H:i:s' with proper timezone handling

$formattedDate = Xero::formatDate('/Date(1663257600000+0100)/', 'Y-m-d');
// Returns just the date portion
  1. Error handling:
$formattedDate = Xero::formatDate('invalid-date');
// Returns: '' (empty string instead of throwing an exception)

formatQueryStrings()

Formats an array of parameters into a properly encoded query string for API requests.

Signature

public static function formatQueryStrings(array $params): string

Parameters

  • $params (array): Associative array of query parameters

Return Value

  • string: URL-encoded query string following RFC3986 standards

Usage Examples

  1. Basic parameter formatting:
$queryString = Xero::formatQueryStrings([
    'page' => 1,
    'limit' => 20
]);
// Returns: 'page=1&limit=20'
  1. Handling special characters:
$queryString = Xero::formatQueryStrings([
    'search' => 'Company & Partners',
    'status' => 'active'
]);
// Returns: 'search=Company%20%26%20Partners&status=active'
  1. Nested arrays:
$queryString = Xero::formatQueryStrings([
    'filter' => ['status' => 'ACTIVE', 'type' => 'ACCREC'],
    'order' => 'Date DESC'
]);
// Returns properly encoded query string with nested parameters

Notes

  • The formatDate() method is particularly useful when working with date responses from the Xero API, which may use Microsoft's JSON date format
  • The formatQueryStrings() method ensures proper URL encoding for all API requests, preventing issues with special characters
Table of Contents
  • Available Methods
    • formatDate()
      • Signature
      • Parameters
      • Return Value
      • Usage Examples
    • formatQueryStrings()
      • Signature
      • Parameters
      • Return Value
      • Usage Examples
  • Notes

DCBlog

Practical tutorials, code snippets, and in-depth guides for modern web development. Helping developers build better applications since 2009.

Subscribe to my newsletter for the latest updates on my books and digital products.

© 2009 - 2025 DC Blog. All rights reserved.

Privacy Policy • Terms of Service