Coder Social home page Coder Social logo

laravel-persian-datetime-helper's Introduction

Laravel Persian DateTime Helper

GitHub code size in bytes GitHub

Install

Composer

Installing with composer is recommended and it simply works :

composer require novaday-co/laravel-persian-datetime-helper

Download

You can download latest version from the Github: Download

Quick start

To use in your project, just import DateTimeHelper class :

$instance = DateTimeHelper::parse('1400-04-13 15:16:10') : Jalalian
$instance = DateTimeHelper::parse('1400/04/13 15:16:10') : Jalalian
$instance = DateTimeHelper::parse('1400_04_13 15:16:10') : Jalalian

DateTimeHelper::parse('1400-04-13 15:16:10')->format('Y-m-d') : string
// 1400-04-13

DateTimeHelper::parse('1400/04/13 15:16:10')->format('Y/m/d') : string
// 1400/04/13

// Accept H:i Format

DateTimeHelper::parse('1400/04/13 15:16')->format('Y-m-d H:i:s') :  string ('Y-m-d H:i:s')
// 1400-04-13 15:16:00

// Clone

$jalaliDateTime = DateTimeHelper::parse('1400-04-13 15:16:10');
$cloneJalaliDateTime = DateTimeHelper::copy($jalaliDateTime)->format('Y-m-d H:i:s');
// 1400-04-13 15:16:10
// $jalaliDateTime == $cloneJalaliDateTime
// $jalaliDateTime !== $cloneJalaliDateTime

//ignore multiple space from input

$instance = DateTimeHelper::parse('1400-04-13   15:16:10')->format('Y-m-d H:i:s') : string
// 1400-04-13 15:16:10

DateTimeHelper::jalaliToGregorian('1400-04-13 15:16:10') : string ('Y-m-d H:i:s')
// 2021-07-04 15:16:10

DateTimeHelper::jalaliToGregorian('1400-04-13') : string ('Y-m-d H:i:s')
// 2021-07-04 00:00:00

DateTimeHelper::jalaliDiffInMonths('1400-02-23 10:27:52', '1400-04-23 15:16:10') : int
// 2

DateTimeHelper::jalaliDiffInMonths('1400-02-23', '1400-04-23') : int
// 2

DateTimeHelper::jalaliDiffInDays('1400-02-13 15:16:10', '1400-02-23 10:27:52') : int
// 9

DateTimeHelper::jalaliDiffInDays('1400-02-13', '1400-02-23') : int
// 10

DateTimeHelper::jalaliDiffInHours('1400-04-23 15:16:10', '1400-04-23 22:27:52') : int
// 7

DateTimeHelper::jalaliDiffInHours('15:16:10', '22:27:52') : int
// 7

DateTimeHelper::jalaliDiffInMinutes('1400-04-23 15:16:10', '1400-04-23 22:27:52') : int
// 431

DateTimeHelper::jalaliDiffInMinutes('15:16:10', '22:27:52') : int
// 431

DateTimeHelper::clearTime('1400-04-23 15:16:10') :  string ('Y-m-d H:i:s')
// 1400-04-23 00:00:00

DateTimeHelper::getMinutes('1400-04-23 15:16:10') :  int
// 916 = 15*60 + 16

DateTimeHelper::firstDayOfMonth('1400-04-23 15:16:10') :  string ('Y-m-d H:i:s')
// 1400-04-01 00:00:00

DateTimeHelper::firstDayOfMonth('1400-04-23') :  string ('Y-m-d H:i:s')
// 1400-04-01 00:00:00

DateTimeHelper::lastDayOfMonth('1400-04-23 15:16:10') :  string ('Y-m-d H:i:s')
// 1400-04-31 00:00:00

DateTimeHelper::lastDayOfMonth('1400-08-23') :  string ('Y-m-d H:i:s')
// 1400-08-30 00:00:00

DateTimeHelper::firstDayOfYear() :  string ('Y-m-d H:i:s')
// 1400-01-01 00:00:00

DateTimeHelper::lastDayOfYear() :  string ('Y-m-d H:i:s')
// 1400-12-29 23:59:59

License

MIT

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.