All Projects → andanhm → go-prettytime

andanhm / go-prettytime

Licence: MIT license
Format GoLang dates in a “pretty” way. ex : just now, a minute ago, 2 hours ago , 3 minutes ago

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to go-prettytime

vue-date-fns
Date filter for Vue based on the date-fns.
Stars: ✭ 21 (-8.7%)
Mutual labels:  date, date-formatting
format-date
📆 A small library (around 400 B when gziped & minified) to format JavaScript `Date` object using same tokens as moment.
Stars: ✭ 25 (+8.7%)
Mutual labels:  date, date-formatting
Dayjs
⏰ Day.js 2kB immutable date-time library alternative to Moment.js with the same modern API
Stars: ✭ 37,373 (+162391.3%)
Mutual labels:  date, date-formatting
Caterpillar
🐛 Caterpillar: Type-safe date formats in Swift, no more "yyyy-MM-dd'T'HH:mm:ssZ"
Stars: ✭ 49 (+113.04%)
Mutual labels:  date, date-formatting
dayjs
Extended fork of Day.js - 2KB immutable date library alternative to Moment.js
Stars: ✭ 36 (+56.52%)
Mutual labels:  date, date-formatting
Swiftdate
🐔 Toolkit to parse, validate, manipulate, compare and display dates, time & timezones in Swift.
Stars: ✭ 6,661 (+28860.87%)
Mutual labels:  date, date-formatting
Time
Building a better date/time library for Swift
Stars: ✭ 1,983 (+8521.74%)
Mutual labels:  date, date-formatting
jodaTime
Format and Parse date and time with joda layout
Stars: ✭ 67 (+191.3%)
Mutual labels:  date
date-extractor
Extract dates from text
Stars: ✭ 58 (+152.17%)
Mutual labels:  date
SonataTimelineBundle
[Abandoned] Integrates SpyTimelineBundle into Sonata
Stars: ✭ 24 (+4.35%)
Mutual labels:  date
nativescript-datetimepicker
Plugin with date and time picking fields
Stars: ✭ 26 (+13.04%)
Mutual labels:  date
react-modern-datepicker
A modern date picker for react library
Stars: ✭ 19 (-17.39%)
Mutual labels:  date
duration
Parse iso8601 duration strings, and use to shift dates/times.
Stars: ✭ 51 (+121.74%)
Mutual labels:  date
iso8601
A fast ISO8601 date parser for Go
Stars: ✭ 122 (+430.43%)
Mutual labels:  date
persiantools
Jalali date and datetime with other tools
Stars: ✭ 101 (+339.13%)
Mutual labels:  date
ptera
Ptera is DateTime library for Deno
Stars: ✭ 62 (+169.57%)
Mutual labels:  date
time machine
A date and time API for Dart
Stars: ✭ 120 (+421.74%)
Mutual labels:  date
timelite
String date and time utilities 🕙
Stars: ✭ 17 (-26.09%)
Mutual labels:  date
Chocobo-Date-Range-Picker
🗓️ Component - The Date Range Picker easier to use in AngularJS.
Stars: ✭ 23 (+0%)
Mutual labels:  date
fmtdate
MS Excel (TM) syntax for Go time/date
Stars: ✭ 95 (+313.04%)
Mutual labels:  date

Go Pretty Time

Go Report Card Build Status GoDoc CodeCov

Format Go date time in a pretty way. ex : just now, a minute ago, 2 hours ago , 3 minutes ago

Inspired by the John Resig Pretty Date plug-in for JQuery

prettytime.Format("2008-01-28T20:24:17Z") // => "2 hours ago"
prettytime.Format("2008-01-27T22:24:17Z") // => "Yesterday"
prettytime.Format("2008-01-26T22:24:17Z") // => "2 days ago"
prettytime.Format("2008-01-14T22:24:17Z") // => "2 weeks ago"

Install

go get github.com/andanhm/go-prettytime

Example

package main

import (
	"log"
	"time"

	"github.com/andanhm/go-prettytime"
)

const (
	layout = "2006-01-02T15:04:05Z"
)

func main() {
	t, err := time.Parse(layout, "2008-01-28T20:24:17Z")
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("%s \n", prettytime.Format(t))
}
// Output: 13 years ago

i18n support

go-prettytime uses go-i18n to provide i18n capabilities.

Translating a new language

Create an empty message file for the language that you want to add (e.g. translate.es.toml).

Run goi18n merge en.toml translate.es.toml to populate translate.es.toml with the messages to be translated.

After translate.es.toml has been translated, rename it to es.toml

Load es.toml into the time.go file via

bundle.MustLoadMessageFile("es.toml")

Contributions

Feel free to fork and add features, fix bugs and your pull request is more than welcome

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