All Projects → KnpLabs → Knptimebundle

KnpLabs / Knptimebundle

Licence: mit
Provides helpers for time manipulation

Labels

Projects that are alternatives of or similar to Knptimebundle

Human Interval
Human readable time distances for javascript
Stars: ✭ 360 (-21.57%)
Mutual labels:  time, date
react-ago-component
A component for React that renders the approximate time ago in words from a specific past date using an HTML5 time element.
Stars: ✭ 25 (-94.55%)
Mutual labels:  time, date
date4j
Lightweight alternative to Java's built-in date-time classes. Android-friendly. Compiles under JDK 1.5.
Stars: ✭ 36 (-92.16%)
Mutual labels:  time, date
vue-timeselector
🕒 Simply customizable powerful time picker for Vue.js
Stars: ✭ 41 (-91.07%)
Mutual labels:  time, date
Timestamp
⏰ A better macOS menu bar clock.
Stars: ✭ 296 (-35.51%)
Mutual labels:  time, date
nepali-datetime
Python's core datetime inspired nepali datetime (BS date & NPT) package 🇳🇵
Stars: ✭ 36 (-92.16%)
Mutual labels:  time, date
edtf.js
Extended Date Time Format (ISO 8601-2 / EDTF) Parser for JavaScript
Stars: ✭ 44 (-90.41%)
Mutual labels:  time, date
chronos
One library to rule the time
Stars: ✭ 17 (-96.3%)
Mutual labels:  time, date
React Datetime Picker
A datetime picker for your React app.
Stars: ✭ 294 (-35.95%)
Mutual labels:  time, date
Awesome Falsehood
😱 Falsehoods Programmers Believe in
Stars: ✭ 16,614 (+3519.61%)
Mutual labels:  time, date
moment-cache
⏱ Simple utility to cache moment.js results and speed up moment calls.
Stars: ✭ 29 (-93.68%)
Mutual labels:  time, date
Time
Simple time handling in Rust
Stars: ✭ 334 (-27.23%)
Mutual labels:  time, date
react-picky-date-time
A react component for date time picker. Online demo examples
Stars: ✭ 41 (-91.07%)
Mutual labels:  time, date
dayjs
Extended fork of Day.js - 2KB immutable date library alternative to Moment.js
Stars: ✭ 36 (-92.16%)
Mutual labels:  time, date
rescript-date
📆 Date manipulation in ReScript.
Stars: ✭ 101 (-78%)
Mutual labels:  time, date
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 (-94.77%)
Mutual labels:  time, date
popoPicker
popoPicker是一个移动端3D滚轮日期时间和单项的选择器,支持无限循环滚动,不依赖第三方库
Stars: ✭ 26 (-94.34%)
Mutual labels:  time, date
time-formater
在javascript中显示日期。
Stars: ✭ 44 (-90.41%)
Mutual labels:  time, date
Md Date Time Picker
An implementation of Material Design Picker components in vanilla CSS, JS, and HTML
Stars: ✭ 272 (-40.74%)
Mutual labels:  time, date
Maya
Datetimes for Humans™
Stars: ✭ 3,298 (+618.52%)
Mutual labels:  time, date

Friendly ago dates ("5 minutes ago")!

This bundle does one simple job: takes dates and gives you friendly "2 hours ago"-type messages. Woh!

Last edited {{ post.updatedAt|ago }}
<-- Last edited 1 week ago -->

Want to see it used in a screencast 🎥? Check out SymfonyCasts: https://symfonycasts.com/screencast/symfony-doctrine/ago

The date formatted can be translated into any language, and many are supported out of the box.

INSTALLATION

Use Composer to install the library:

composer require knplabs/knp-time-bundle

Woo! You did it! Assuming your project uses Symfony Flex, the bundle should be configured and ready to go. If not, you can enable Knp\Bundle\TimeBundle\KnpTimeBundle manually.

USAGE

In Twig:

{{ someDateTimeVariable|ago }}

... or use the equivalent function:
{{ time_diff(someDateTimeVariable) }}

Note: the "ago" filter works fine for dates in the future, too.

In controllers

You can also "ago" dates inside PHP by autowiring the Knp\Bundle\TimeBundle\DateTimeFormatter service:

use Knp\Bundle\TimeBundle\DateTimeFormatter;
// ...

public function yourAction(DateTimeFormatter $dateTimeFormatter)
{
    $someDate = new \DateTime('2017-02-11'); //or $entity->publishedDate()
    $now = new \DateTime();
    
    $agoTime = $dateTimeFormatter->formatDiff($someDate, $now);
    return $this->json([
        ...
        'published_at' => $agoTime
        ...
    ]);
}

Controlling the Translation Locale

The bundle will automatically use the current locale when translating the "ago" messages. However, you can override the locale:

{{ someDateTimeVariable|ago(locale='es') }}

TESTS

If you want to run tests, please check that you have installed dev dependencies.

./vendor/bin/simple-phpunit

Maintainers

Anyone can contribute to this repository (and it's warmly welcomed!). The following people maintain and can merge into this library:

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].