All Projects → opencafe → datium

opencafe / datium

Licence: BSD-3-Clause license
⏰ The flexible DataTime Package written in PHP

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to datium

jalali-pandas
A pandas extension that solves all problems of Jalai/Iraninan/Shamsi dates
Stars: ✭ 29 (+61.11%)
Mutual labels:  datetime, jalali-calendar, jalali
nepali utils
A pure dart package with collection of Nepali Utilities like Date converter, Date formatter, DateTime, Nepali Numbers, Nepali Unicode, Nepali Moments and many more.
Stars: ✭ 22 (+22.22%)
Mutual labels:  datetime, date-converter
persiantools
Jalali date and datetime with other tools
Stars: ✭ 101 (+461.11%)
Mutual labels:  datetime, jalali
Date
Fix all needs to date in php
Stars: ✭ 32 (+77.78%)
Mutual labels:  datetime, jalali
JalaliCalendar
Jalali Calendar for java
Stars: ✭ 76 (+322.22%)
Mutual labels:  jalali-calendar, jalali
elm-date-extra
Extra functions for working with Date
Stars: ✭ 41 (+127.78%)
Mutual labels:  date-format, date-parser
shamsi date
A Flutter and Dart package for using Jalali (Shamsi, Solar, Persian or Jalaali) calendar. You can convert, format and manipulate Jalali and Gregorian (Miladi) date and times.
Stars: ✭ 59 (+227.78%)
Mutual labels:  datetime, jalali
gahshomar
A Persian (Jalali/Farsi) calendar for Linux
Stars: ✭ 69 (+283.33%)
Mutual labels:  jalali-calendar, jalali
iranian-calendar-events
Fetch Iranian calendar events (Jalali, Hijri and Gregorian) from time.ir website
Stars: ✭ 28 (+55.56%)
Mutual labels:  jalali-calendar, jalali
date-extractor
Extract dates from text
Stars: ✭ 58 (+222.22%)
Mutual labels:  datetime, kurdish
libcalendars
Collection of calendar arithmetic algorithms
Stars: ✭ 38 (+111.11%)
Mutual labels:  jalali-calendar, jalali
Time
Building a better date/time library for Swift
Stars: ✭ 1,983 (+10916.67%)
Mutual labels:  datetime, calendars
format-date
📆 A small library (around 400 B when gziped & minified) to format JavaScript `Date` object using same tokens as moment.
Stars: ✭ 25 (+38.89%)
Mutual labels:  datetime, date-format
date-php
这是一个Javascript模仿PHP日期时间格式化函数,使用方法和PHP非常类似,有丰富的模板字符,并在原来的基础上增加了一些模板字符。 This is a date function that implement PHP in Javascript. It is very similar to PHP, has rich template characters, and enhances some template characters on the basis of the original.
Stars: ✭ 24 (+33.33%)
Mutual labels:  datetime, date-format
Timeago.js
🕗 ⌛ timeago.js is a tiny(2.0 kb) library used to format date with `*** time ago` statement.
Stars: ✭ 4,670 (+25844.44%)
Mutual labels:  datetime, date-format
hawking
A Natural Language Date Time Parser that Extract date and time from text with context and parse to the required format
Stars: ✭ 168 (+833.33%)
Mutual labels:  datetime, date-parser
react-calendar-datetime-picker
A simple and fast date and time picker component for React
Stars: ✭ 58 (+222.22%)
Mutual labels:  datetime
Itinerary
Lazy time scheduling toolset for .NET
Stars: ✭ 28 (+55.56%)
Mutual labels:  datetime
lit-date
Light-weight, faster datetime formatter for modern browsers.
Stars: ✭ 33 (+83.33%)
Mutual labels:  datetime
angular-datetime-inputs
📅 Angular directives for datetime inputs
Stars: ✭ 20 (+11.11%)
Mutual labels:  datetime

Datium

Build Status Scrutinizer Code Quality Latest Stable Version Total Downloads Join the chat at https://gitter.im/opencafe/datium npm

Awesome DateTime package written in PHP, with generalization support in calendar and translation, which makes Datium powerful and simple.

  • Simplicity in code and logic
  • Expandable in every part
  • Hijri, Jalali, Julian and Kurdish Calendars support

Support

  • ^PHP:5.4
  • PHP:7

Installation

Via Composer

composer require opencafe/datium

Manual

Just require Datium.php in your project and use Datium namespace as following example:

require_once 'src/Datium.php';

use OpenCafe\Datium;

echo Datium::now()->get();

Usage

Simply get what you want:

As datium output

Datium::now()->get(); // ex: 2016-01-01 00:00:00

Datium::now()->timestamp(); // ex: 1420057800

Datium::now()->get('timestamp'); // ex: 1420057800

Or working with date as simple as you need:

Datium::now()->add('1 day')->get(); // ex: 2016-01-02 00:00:00

Get

Get Datium as DateTime PHP object:

Datium::now()->object();

Or return it as simple date and time string:

Datium::now()->get();

And even with custom PHP YMD format:

Datium::now()->get( 'l jS F Y h:i:s A' );

Timestamp format:

Datium::create(2016,10,16)->get('timestamp');
// Result : 1476563400

Easy usage:

Datium::now()->all();

// Result
object(stdClass)#5 (6) {
  ["second"]=>
  string(2) "03"
  ["minute"]=>
  string(2) "10"
  ["hour"]=>
  string(2) "15"
  ["day"]=>
  string(2) "12"
  ["month"]=>
  string(2) "10"
  ["year"]=>
  string(4) "2016"
}

Datium::now()->all()->year;    // 2016
Datium::now()->all()->month;   // 10
Datium::now()->all()->day;     // 12
Datium::now()->all()->hour;    // 15
Datium::now()->all()->minute;  // 10
Datium::now()->all()->second;  // 03

Create

You can also simply create new time:

// Create with YMD
Datium::create( 2016, 1, 1, 12, 56, 13 )->get(); //ouput: 2016-01-01 12:56:13

// Create with YMD without time
Datium::create( 2016, 1, 1 )->get(); // output: 2016-01-01 12:56:13

// Create with timestamp
Datium::createTimestamp( 1420057800 )->get() // output => 2015-01-01 00:00:00

Add Date

This method allow you add some year, month, week, day, hour, minute and second to current date.

// If current date is 2016-01-01 00:00:00 then:

// Add 3 years
Datium::now()->add('3 year')->get();
// output => 2019-01-01 00:00:00

// Add 1 week
Datium::create(2016, 1, 1)->add('1 week')->get();
// output => 2016-01-08 00:00:00

// Add one month
Datium::now()->add('1 month')->get()
// output => 2016-02-01 00:00:00

// Add 1 year, 3 month and 2 days
Datium::now()->add('1 year')
             ->add('3 month')
             ->add('2 day')
             ->add('1 hour')
             ->add('2 minute')
             ->add('3 second')
             ->get();
// output => 2017-04-03 01:02:03

Sub Date

Sub some year, month, day, hour, minute and second from current date.

// If current date is 2016-01-01 00:00:00 then:


// Sub 3 years
Datium::now()->sub('3 year')->get();
// output => 2013-01-01 00:00:00

// Sub 1 week
Datium::create(2016, 1, 8)->sub('1 week')->get();
// output => 2016-01-01 00:00:00

// Sub one month
Datium::now()->sub('1 month')->get()
// output => 2015-12-01 00:00:00

// Sub 1 year, 3 month and 2 days
Datium::now()->sub('1 year')
             ->sub('3 month')
             ->sub('2 day')
             ->get();
// output => 2014-09-29 00:00:00

Date Difference

This method will return the difference between two specific date with php date interval type.

// current generated date difference with next 5000 days
$diff = Datium::diff(
    Datium::now()->object(),
    Datium::now()->add('5000 day')->object()
);

echo $diff->days;
// output => 5000
echo $diff->year . ' year, ' .  $diff->month . ' month, ' . $diff->day . ' day ';
// ouput => 13 year, 8 month, 7 day

Human readable time difference

Datium also supports human readable date and time difference.

// current generated date difference with next 5000 days
$diff = Datium::diff(
    Datium::now()->object(),
    Datium::now()->add('5000 day')->object()
)->simple->get();

// result => 13 years ago

// current generated date difference with next 5000 days
$diff = Datium::diff(
    Datium::now()->object(),
    Datium::now()->sub('5000 day')->object()
)->simple->get();

// result => 13 years remaining

// current generated date difference with next 5000 days
$diff = Datium::diff(
    Datium::now()->object(),
    Datium::now()->add('5000 day')->object()
)->simple->lang('fa')->get();

// result => ۱۳ سال پیش

Leap year

Define leap year of current year with generalization support.

// If current date was 2016

// Is 2016 a leap year?
Datium::now()->leap()->get();
// output => FALSE

// Is 2017 a leap year?
Datium::now()->add('1 year')->leap()->get();
// output => TRUE

Datium::now()->to('hijri')->leap()->get();

Get day of date

This method returns day of week or day of year with generalization support, you can add this feature to your custom calendars like other supported calendars in Datium.

Day of Year

What the day is in current year:

// If current date was 2015-09-03

Datium::now()->dayOf()->year();
// output => 246

// Day of year to Gregorian
Datium::now()->dayOf()->year();

// Day of year to Jalali
Datium::now()->to( 'jalali' )->dayOf()->year();

// Day of year to Hijri
Datium::now()->to( 'hijri' )->dayOf()->year();

// Day of year to kurdish
Datium::now()->to( 'kurdish' )->dayOf()->year();

Day of Week

What day of week is current day:

// If current date 'll be 2015-09-09 Thursday
Datium::now()->dayOf()->week();
// output => 5

// Day of week to Gregorian
Datium::now()->dayOf()->week();

// Day of week to Jalali
Datium::now()->to( 'jalali' )->dayOf()->week();

// Day of week to Hijri
Datium::now()->to( 'hijri' )->dayOf()->week();

// Day of week to Kurdish
Datium::now()->to( 'kurdish' )->dayOf()->week();

Last Day of Month

How many days is current month

// Last Day of Current Month to Gregorian
Datium::now()->dayOf()->lastDayMonth();

// Last Day of Current Month to Jalali
Datium::now()->to( 'jalali' )->dayOf()->lastDayMonth();

// Last Day of Current Month to Hijri
Datium::now()->to( 'hijri' )->dayOf()->lastDayMonth();

// Last Day of Current Month to Kurdish
Datium::now()->to( 'kurdish' )->dayOf()->lastDayMonth();

Generalization

Calendar generalization

Datium supports calendar generalization, you can add customized calendars to Datium and used them as it's own default calendars.

Datium::create( 2015, 11, 9 )->to( 'jalali' )->get()
//Convert Gregorian to Jalali calendar: 1394-08-18 00:00:00

Datium::create( 2015, 11, 9 )->to( 'hijri' )->get()
//Convert Gregorian to Hijri calendar: 1437-01-26 00:00:00

Datium::create( 2015, 11, 9 )->to( 'kurdish' )->get()
//Convert Gregorian to Kurdish calendar: 2715-08-18 00:00:00

Convert all calendars which supported on Datium or event your customized calendars as simple as possible:

Datium::create( 1395, 7, 25 )->from( 'jalali' )->get(); // Gregorian is default value for destination calendar.
// result: 2016-10-16 00:00:00

Datium::create( 1395, 7, 25 )->from( 'jalali' )->to( 'hijri' )->get();
// result: 1438-01-14 00:00:00

Translation Generalization

Generalization in translation is another Datium generalization support.

Datium::create( 2016, 6, 25, 12, 0, 0 )->to( 'jalali' )->lang( 'fa' )->get('l jS F Y h:i:s A');
// ex: شنبه ۵ تیر ۱۳۹۵ ۱۲:۰۰:۰۰ ب.ظ

Datium::create( 2016, 6, 25, 12, 0, 0 )->to( 'jalali' )->get('l jS F Y h:i:s A');
// ex: Shanbe 5th Tir 1395 12:00:00 PM

Datium::create(2016, 6, 25, 12, 0, 0)->to('hijri')->get('l jS F Y h:i:s A');
// ex: as-Sabt 19th Ramadan 1437 12:00:00 PM

Datium::create(2016, 6, 25, 12, 0, 0)->to('kurdish')->get('l jS F Y h:i:s A');
// ex: Şeme 5th Puşper 2716 12:00:00 PM

Datium::create(2016, 6, 25, 12, 0, 0)->get('l jS F Y h:i:s A');
// ex: Saturday 25th June 2016 12:00:00 PM

Change Configuration

You can change any configuration after initialize Datium object.

$datium = Datium::create(
                $date->format('Y'),
                $date->format('m'),
                $date->format('d'),
                $date->format('h'),
                $date->format('i'),
                $date->format('s')
            );
$datium->setConfig(['timezone'=>'Europe/Istanbul']);

Default configuration

[
  'timezone' => 'Asia/Tehran',
  'language' =>     'en',
  'default_calendar' => 'gregorian',
  'date_interval' => [ 'D', 'M', 'Y', 'HT', 'MT', 'ST' ],
  'date_simple' => [ 'day', ' month', ' year', ' hour', ' minute', ' second' ],
]
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].