Giter Site home page Giter Site logo

eshwaranad / timestamp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wikimedia/mediawiki-libs-timestamp

0.0 1.0 0.0 85 KB

Timestamp parsing and formatting in PHP. This is a mirror from gerrit.wikimedia.org. See https://www.mediawiki.org/wiki/Developer_access for contributing.

Home Page: https://www.mediawiki.org/wiki/Timestamp

License: GNU General Public License v2.0

PHP 99.74% Shell 0.26%

timestamp's Introduction

Latest Stable Version License

Convertible Timestamp for PHP

This library provides a convenient wrapper around DateTime to create, parse, and format timestamps.

Additional documentation about the library can be found on MediaWiki.org.

Supported formats

On input, the following formats are recognized:

  • A subset of ISO 8601 basic and extended formats:
    • Years before 0000 or after 9999 are not supported.
    • Week and ordinal dates are not supported.
    • Accuracy to seconds is required. Fractions of a second are supported to microsecond resolution.
    • If the timezone is omitted, UTC is assumed.
    • As an extension, the 'T' may be replaced with a single space.
  • As a signed integer (up to 13 digits) representing seconds since the Unix epoch.
    • Optionally with decimal seconds to microsecond resolution, using '.' as the decimal separator.
  • RFC 2822 format, including obsolete syntax.
    • CFWS tokens are not fully supported, use only FWS.
    • Note, per the RFC, all military timezones are considered as -0000.
    • As an extension, the timezone may be omitted entirely in which case UTC is assumed.
    • As an extension, anything after the first semicolon in the string is ignored.
  • RFC 850 format.
  • asctime format.
  • The TS_MW, TS_DB, TS_POSTGRES, TS_ORACLE, and TS_EXIF formats described below.

For output, the following conversions are predefined:

  • TS_DB: MySQL datetime format: "2012-07-31 19:01:08"
  • TS_EXIF: Exif 2.2 format: "2012:07:31 19:01:08"
  • TS_ISO_8601: ISO 8601 expanded format: "2012-07-31T19:01:08Z"
  • TS_ISO_8601_BASIC: ISO 8601 basic format: "20120731T190108Z"
  • TS_MW: A 14-digit string: "20120731190108"
  • TS_ORACLE: A default Oracle timestamp format: "31-07-2012 19:01:08.000000"
  • TS_POSTGRES: PostgreSQL default timestamptz format: "2012-07-31 19:01:08+00"
  • TS_RFC2822: RFC 2822 format using an obsolete timezone: "Tue, 31 Jul 2012 19:01:08 GMT"
  • TS_UNIX: Seconds since the Unix epoch (1970-01-01T00:00:00Z): "1343761268".
  • TS_UNIX_MICRO: Seconds since the Unix epoch with microseconds: "1343761268.000000".

Usage

$ts = new ConvertibleTimestamp( '2012-07-31T19:01:08Z' );
$formatted = $ts->getTimestamp( TS_UNIX );

// Shorthand
$formatted = ConvertibleTimestamp::convert(
    TS_UNIX, '2012-07-31T19:01:08Z'
);

// Format using PHP date formatting codes
$formatted = $ts->format( 'Y-m-d H:i:s O' );

Running tests

composer install --prefer-dist
composer test

timestamp's People

Contributors

legoktm avatar anomiex avatar umherirrender avatar jdforrester avatar krinkle avatar ayg avatar daimona avatar dannys712 avatar tgr avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.