All Projects → yaa110 → go-persian-calendar

yaa110 / go-persian-calendar

Licence: MIT license
The implementation of Persian (Solar Hijri) Calendar in Go

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to go-persian-calendar

JalaliCalendar
Jalali Calendar for java
Stars: ✭ 76 (-35.59%)
Mutual labels:  persian-calendar, jalali
flutter date picker timeline
Gregorian and Jalali customizable date picker as a horizontal timeline
Stars: ✭ 29 (-75.42%)
Mutual labels:  persian-calendar, jalali
gahshomar
A Persian (Jalali/Farsi) calendar for Linux
Stars: ✭ 69 (-41.53%)
Mutual labels:  persian-calendar, jalali
MoalemYar
A personal project for class management, using various technologies like WPF, Entityframwork, CodeFirst, Sqlite, Migration and more
Stars: ✭ 53 (-55.08%)
Mutual labels:  persian-calendar
vue2-persian-datepicker
A vue component that provides datepicker for persian developers
Stars: ✭ 100 (-15.25%)
Mutual labels:  persian-calendar
ShamsiCalendar
تقویم فارسی و شمسی - Shamsi & Persian Calendar 📆
Stars: ✭ 39 (-66.95%)
Mutual labels:  persian-calendar
PersianDateRangePicker
Select range of date and time in the Persian
Stars: ✭ 41 (-65.25%)
Mutual labels:  persian-calendar
PrimeCalendar
PrimeCalendar provides all of the java.util.Calendar functionalities for Persian, Hijri, and ... dates. It is also possible to convert dates to each other.
Stars: ✭ 45 (-61.86%)
Mutual labels:  persian-calendar
wp-parsidate
Integrates the Solar Hijri (Persian) calendar in WordPress
Stars: ✭ 36 (-69.49%)
Mutual labels:  jalali
datium
⏰ The flexible DataTime Package written in PHP
Stars: ✭ 18 (-84.75%)
Mutual labels:  jalali
Blazor.PersianDatePicker
A free JavaScript Jalali (Persian) and Gregorian (Miladi) dual datepicker library for Blazor applications
Stars: ✭ 40 (-66.1%)
Mutual labels:  persian-calendar
iranian-calendar-events
Fetch Iranian calendar events (Jalali, Hijri and Gregorian) from time.ir website
Stars: ✭ 28 (-76.27%)
Mutual labels:  jalali
thumbai
Go Mod Repository, Go Vanity Server and Proxy Server
Stars: ✭ 84 (-28.81%)
Mutual labels:  golang-module
react-calendar-datetime-picker
A simple and fast date and time picker component for React
Stars: ✭ 58 (-50.85%)
Mutual labels:  persian-calendar
mds-angular-datetime-picker-package
Angular 2+ And Bootstrap 4+ DateTimePicker
Stars: ✭ 18 (-84.75%)
Mutual labels:  persian-calendar
JDate
A Jalali to Gregorian converter in Javascript with support of formatting output
Stars: ✭ 83 (-29.66%)
Mutual labels:  jalali
go-jalaali
Go implementation for converting Jalaali and Gregorian calendar systems to each other.
Stars: ✭ 35 (-70.34%)
Mutual labels:  jalali
pcal
Command line tool to convert Gregorian calendar dates to Persian calendar dates
Stars: ✭ 22 (-81.36%)
Mutual labels:  persian-calendar
currency
A currency computations package.
Stars: ✭ 52 (-55.93%)
Mutual labels:  golang-module
raycaster-go
Golang raycaster engine using the Ebitengine 2D Game Library
Stars: ✭ 88 (-25.42%)
Mutual labels:  golang-module

Go Persian Calendar

godoc Build Status goreportcard License

Go Persian Calendar provides functionality for conversion among Persian (Solar Hijri) and Gregorian calendars. A Julian calendar is used as an interface for all conversions. The package name is ptime and it is compatible with the package time. All months are available with both Iranian and Dari Persian names. This source code is licensed under MIT license that can be found in the LICENSE file.

Installation

go get github.com/yaa110/go-persian-calendar

Getting started

1- Import the package ptime. Most of the time you need to import time and fmt packages, too.

import (
    ptime "github.com/yaa110/go-persian-calendar"
    "time"
    "fmt"
)

2- Convert Gregorian calendar to Persian calendar.

// Create a new instance of time.Time
var t time.Time = time.Date(2016, time.January, 1, 12, 1, 1, 0, ptime.Iran())

// Get a new instance of ptime.Time using time.Time
pt := ptime.New(t)

// Get the date in Persian calendar
fmt.Println(pt.Date()) // output: 1394 دی 11

3- Convert Persian calendar to Gregorian calendar.

// Create a new instance of ptime.Time
var pt ptime.Time = ptime.Date(1394, ptime.Mehr, 2, 12, 59, 59, 0, ptime.Iran())

// Get a new instance of time.Time
t := pt.Time()

// Get the date in Gregorian calendar
fmt.Println(t.Date()) // output: 2015 September 24

4- Get the current time.

// Get a new instance of ptime.Time representing the current time
pt := ptime.Now()

// Get year, month, day
fmt.Println(pt.Date()) // output: 1394 بهمن 11
fmt.Println(pt.Year(), pt.Month(), pt.Day()) // output: 1394 بهمن 11

// Get hour, minute, second
fmt.Println(pt.Clock()) // output: 21 54 30
fmt.Println(pt.Hour(), pt.Minute(), pt.Second()) // output: 21 54 30

// Get Unix timestamp (the number of seconds since January 1, 1970 UTC)
fmt.Println(pt.Unix()) // output: 1454277270

// Get yesterday, today and tomorrow
fmt.Println(pt.Yesterday().Weekday()) // output: شنبه
fmt.Println(pt.Weekday()) // output: یک‌شنبه
fmt.Println(pt.Tomorrow().Weekday()) // output: دوشنبه

// Get First and last day of week
fmt.Println(pt.FirstWeekDay().Date()) // output: 1394 بهمن 10
fmt.Println(pt.LastWeekday().Date()) // output: 1394 بهمن 16

// Get First and last day of month
fmt.Println(pt.FirstMonthDay().Weekday()) // output: پنج‌شنبه
fmt.Println(pt.LastMonthDay().Weekday()) // output: جمعه

// Get First and last day of year
fmt.Println(pt.FirstYearDay().Weekday()) // output: شنبه
fmt.Println(pt.LastYearDay().Weekday()) // output: شنبه

// Get the week of month
fmt.Println(pt.MonthWeek()) // output: 3

// Get the week of year
fmt.Println(pt.YearWeek()) // output: 46

// Get the number of remaining weeks of the year
fmt.Println(pt.RYearWeek()) // output: 6

5- Format the time.

// Get a new instance of ptime.Time using Unix timestamp
pt := ptime.Unix(1454277270, 0)

fmt.Println(pt.Format("yyyy/MM/dd E hh:mm:ss a")) // output: 1394/11/11 یک‌شنبه 09:54:30 ب.ظ

// yyyy, yyy, y     year (e.g. 1394)
// yy               2-digits representation of year (e.g. 94)
// MMM              the Persian name of month (e.g. فروردین)
// MMI              the Dari name of month (e.g. حمل)
// MM               2-digits representation of month (e.g. 01)
// M                month (e.g. 1)
// rw               remaining weeks of year
// w                week of year
// W                week of month
// RD               remaining days of year
// D                day of year
// rd               remaining days of month
// dd               2-digits representation of day (e.g. 01)
// d                day (e.g. 1)
// E                the Persian name of weekday (e.g. شنبه)
// e                the Persian short name of weekday (e.g. ش)
// A                the Persian name of 12-Hour marker (e.g. قبل از ظهر)
// a                the Persian short name of 12-Hour marker (e.g. ق.ظ)
// HH               2-digits representation of hour [00-23]
// H                hour [0-23]
// kk               2-digits representation of hour [01-24]
// k                hour [1-24]
// hh               2-digits representation of hour [01-12]
// h                hour [1-12]
// KK               2-digits representation of hour [00-11]
// K                hour [0-11]
// mm               2-digits representation of minute [00-59]
// m                minute [0-59]
// ss               2-digits representation of seconds [00-59]
// s                seconds [0-59]
// ns               nanoseconds
// S                3-digits representation of milliseconds (e.g. 001)
// z                the name of location
// Z                zone offset (e.g. +03:30)

6- Format the time using standard format.

pt := ptime.Date(1394, 7, 2, 14, 7, 8, 0, Iran())

fmt.Println(pt.TimeFormat("2 Jan 2006")) // output: 2 مهر 1394

// 2006        four digit year (e.g. 1399)
// 06          two digit year (e.g. 99)
// 01          two digit month (e.g. 01)
// 1           one digit month (e.g. 1)
// Jan         month name (e.g. آذر)
// January     month name (e.g. آذر)
// 02          two digit day (e.g. 07)
// 2           one digit day (e.g. 7)
// _2          right justified two character day (e.g.  7)
// Mon         weekday (e.g. شنبه)
// Monday      weekday (e.g. شنبه)
// 03          two digit 12 hour format (e.g. 03)
// 3           one digit 12 hour format (e.g. 3)
// 15          two digit 24 hour format (e.g. 15)
// 04          two digit minute (e.g. 03)
// 4           one digit minute (e.g. 03)
// 05          two digit minute (e.g. 09)
// 5           one digit minute (e.g. 9)
// .000        millisecond (e.g. .120)
// .000000     microsecond (e.g. .123400)
// .000000000  nanosecond (e.g. .123456000)
// .999        trailing zeros removed millisecond (e.g. .12)
// .999999     trailing zeros removed microsecond (e.g. .1234)
// .999999999  trailing zeros removed nanosecond (e.g. .123456)
// PM          full 12-Hour marker (e.g. قبل از ظهر)
// pm          short 12-Hour marker (e.g. ق.ظ)
// MST         the name of location
// -0700       zone offset (e.g. +0330)
// -07         zone offset (e.g. +03)
// -07:00      zone offset (e.g. +03:30)
// Z0700       zone offset (e.g. +0330)
// Z07:00      zone offset (e.g. +03:30)

Changelog

v1.0.0

  • Remove loc *time.Location argument from ptime.Unix(), ptime.SetUnix() and ptime.Now()

v0.6.0

  • Support standard time format

v0.5.0

  • Add BeginningOfWeek, BeginningOfMonth and BeginningOfYear methods.
  • Format UTC timezone by Z instead of +00:00

v0.4.1

  • Refactor code

v0.4.0

  • Change module import name

v0.3.1

  • Use Go modules

v0.3

  • ptime.Iran and ptime.Afghanistan changed to ptime.Iran() and ptime.Afghanistan(), respectively.

Documentation

Use GoDoc documentation for more information about methods and functionality available for ptime.Time, ptime.Month, ptime.Weekday and ptime.AmPm.

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