Giter Site home page Giter Site logo

subeshb1 / nepali-date Goto Github PK

View Code? Open in Web Editor NEW
51.0 2.0 15.0 1.03 MB

ЁЯУЕ A small JS Library to convert English Date to Nepali and Vice Versa

Home Page: https://subeshb1.github.io/Nepali-Date/

License: MIT License

TypeScript 100.00%
nepali datetime nepali-date-converter nepali-calendar nepal bikram-samwat-converter bikram-samvat bikram-samwat bs ad-bs

nepali-date's Introduction

Nepali-Date

A small Javascript/Typescript Library to convert English Date to Nepali and Vice Versa.

Publish Release version

Installation

CDN:

<script src="https://cdn.jsdelivr.net/npm/nepali-date-converter/dist/nepali-date-converter.umd.js"></script>

Node JS:

npm i nepali-date-converter
import NepaliDate from 'nepali-date-converter'
// or

const NepaliDate = require('nepali-date-converter');

Deno:

import NepaliDate from 'https://cdn.jsdelivr.net/npm/nepali-date-converter/dist/nepali-date-converter.es5.js'

Basic Usage

// NepaliDate (year,month,date)
let date1 = new NepaliDate(2054, 5, 24)
// Javascript Date object
new NepaliDate(2051, 5, 24).toJsDate()
// formatting
date1.format('ddd, DD MMMM YYYY') // 'Monday, 24 Aswin 2051'
// update date
date1.setDate(10)
date1.setMonth(1)
date1.setYear(2054)

API

Constructors

constructor(value?: string | number | Date)

String

Provide a valid Nepali date string. The current supported formats are:

YYYY/MM/DD
YYYY-MM-DD
YYYY MM DD
DD/MM/YYYY
DD-MM-YYYY
DD MM YYYY

Example:

new NepaliDate('2051/02/01') // YYYY/MM/DD
new NepaliDate('2051-02-01')
new NepaliDate('2051 02 01')
new NepaliDate('01/02/2051') // DD/MM/YYYY
new NepaliDate('01-02-2051')
new NepaliDate('01 02 2051')

Number

The number value represents the UTC timestamp that will be converted to Nepali date.

Example:

new NepaliDate(1589638162879)

Date

Javascript Date object

Example:

new NepaliDate(new Date(2020, 10, 10))

Empty constructor

If no values are provided, the current day date will be converted to Nepali date.

new NepaliDate()

constructor(year: number, monthIndex: number, date: number)

This constructor takes year, monthIndex i.e 0-11, and date.

Example:

new NepaliDate(2051, 0, 1) // This date represents Baisakh 1, 2051

getYear(): number

Get Nepali date year.

getMonth(): number

Get Nepali month index.

Baisakh => 0
Jestha => 1
Asar => 2
Shrawan => 3
Bhadra => 4
Aswin => 5
Kartik => 6
Mangsir => 7
Poush => 8
Magh => 9
Falgun => 10
Chaitra => 11

getDate(): number

Get Nepali date for the month

getDay(): number

Get Week day index for the date.

toJsDate(): Date

Returns Javascript Date converted from nepali date.

getBS(): IYearMonthDate

Returns Nepali date fields in an object implementing IYearMonthDate

{
    year: 2052,
    month: 10,
    date: 10,
    day: 0
}

getAD(): IYearMonthDate

Returns AD date fields in an object implementing IYearMonthDate

Example:

{
    year: 2019,
    month: 10,
    date: 10,
    day: 0
}

getDateObject(): IAdBs

Returns an object with AD and BS object implementing IYearMonthDate

Example:

{
    BS: {
        year: 2052,
        month: 10,
        date: 10,
        day: 0
    },
    AD: {
        year: 2019,
        month: 10,
        date: 10,
        day: 0
    },

}

format(formatString: string, language: 'np' | 'en'): string

Format Nepali date string based on format string.

YYYY - 4 digit of year (2077)
YYY  - 3 digit of year (077)
YY   - 2 digit of year (77)
M    - month number (1 - 12)
MM   - month number with 0 padding (01 - 12)
MMM  - short month name (Bai, Jes, Asa, Shr, etc.)
MMMM - full month name (Baisakh, Jestha, Asar, ...)
D    - Day of Month (1, 2, ... 31, 32)
DD   - Day of Month with zero padding (01, 02, ...)
d    - Week day (0, 1, 2, 3, 4, 5, 6)
dd   - Week day in short format (Sun, Mon, ..)
ddd  - Week day in long format (Sunday, Monday, ...)

Set language to 'np' for nepali format. The strings can be combined in any way to create desired format.

let a = new NepaliDate(2054, 10, 10)
a.format('YYYY/MM/DD') // '2054/11/10'
a.format('YYYY MM DD') // '2054 11 10'
a.format('YYYY') // '2054'
a.format('ddd DD, MMMM YYYY') // 'Sunday 10, Falgun 2054'
a.format('To\\day is ddd DD, MMMM YYYY') // 'Today is Sunday 10, Falgun 2054', Note: use '\\' to escape [YMDd]
a.format('DD/MM/YYYY', 'np') //' резреж/резрез/реирежрелрек'
a.format('dd', 'np') // 'рдЖрдЗрддрдмрд╛рд░'
a.format('ddd DD, MMMM YYYY', 'np') // 'рдЖрдЗрддрдмрд╛рд░ резреж, рдлрд╛рд▓реНрдЧреБрдг реирежрелрек'
// Set static variable to 'np' for default Nepali language
NepaliDate.language = 'np'
a.format('ddd DD, MMMM YYYY') // 'рдЖрдЗрддрдмрд╛рд░ резреж, рдлрд╛рд▓реНрдЧреБрдг реирежрелрек'

setYear(year: number)

Set year in the current date object. It only takes positive value i.e Nepali Year

Example:

let a = new NepaliDate(2054, 10, 10)
a.setYear(2053) // will make date NepaliDate(2053,10,15);

setMonth(month: number)

Set month in the current date object. It can be positive or negative. Positive values within the month will update the month only and more then month mill increment month and year. Negative value will deduct month and year depending on the value. It is similar to javascript Date API.

Example:

let a = new NepaliDate(2054, 10, 10)
a.setMonth(1) // will make date NepaliDate(2054,1,10);
a.setMonth(-1) // will make date NepaliDate(2053,11,10); To go back to previous month(s) in same or previous year 
a.setMonth(12) // will make date NepaliDate(2054,0,10); To go ahead to coming month(s) in same or coming year

setDate(date: number)

Set date in the current date object. It can be positive or negative. Positive values within the month will update the date only and more then month mill increment month and year. Negative value will deduct month and year depending on the value. It is similar to javascript Date API.

Example:

let a = new NepaliDate(2054, 10, 10)
a.setDate(11) // will make date NepaliDate(2054,10,11);
a.setDate(-1) // will make date NepaliDate(2054,9,29); To go back to dates from previous months
a.setDate(45) // will make date NepaliDate(2054,10,15); To go ahead to dates in coming months

static parse(dateString: string): NepaliDate

Returns new Nepali Date from the string date format Similar to calling constructor with string parameter

static now(): NepaliDate

Returns new Nepali Date converted form current day date. Similar to calling empty constructor

static fromAD(date: Date): NepaliDate

Returns new converted Nepali Date from the provided Javascript Date. It is similar to passing string as constructor

Contributing Guide

# Fork the repo
https://github.com/subeshb1/Nepali-Date

# Clone your forked repo
$ git clone [email protected]:subeshb1/Nepali-Date.git

$ npm install

# Create a new branch for you.
$ git pull origin master # Pull the latest master
$ git checkout new-branch # Checkout to your new branch

# Run test
npm run test

# Commit the changes
$ npm run commit

# Push your changes and
$ git push

# Make a pull request of your newly changed branch
[https://github.com/subeshb1/Nepali-Date/compare](https://github.com/subeshb1/Nepali-Date/compare)

Maintainer

nepali-date's People

Contributors

alina02 avatar dependabot[bot] avatar pabin avatar rajivsah avatar subeshb1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

nepali-date's Issues

The automated release is failing ЁЯЪи

ЁЯЪи The automated release from the master branch failed. ЁЯЪи

I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. IтАЩm sure you can fix this ЁЯТк.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here are some links that can help you:

If those donтАЩt help, or if this issue is reporting something you think isnтАЩt right, you can always ask the humans behind semantic-release.


Cannot push to the Git repository.

semantic-release cannot push the version tag to the branch master on the remote Git repository with URL https://[secure]@github.com/subeshb1/Nepali-Date.

This can be caused by:


Good luck with your project тЬи

Your semantic-release bot ЁЯУжЁЯЪА

Security Vulnerability

Problem Statement

There are vulnerable packages being used in this project, we need to fix them

Acceptance criteria

  • Identify whether the packages are required or not.
  • Eliminate the package or update them to safe version.

Update Read me

Problem Statement

The read me doesn't provide much information currently. We need to update it so that it provides the information listed in acceptance criteria.

Acceptance Criteria

  • Installation method
  • NPM package version in top
  • Basic Usage documentaion
  • Contributing guide

The automated release is failing ЁЯЪи

ЁЯЪи The automated release from the master branch failed. ЁЯЪи

I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. IтАЩm sure you can fix this ЁЯТк.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here are some links that can help you:

If those donтАЩt help, or if this issue is reporting something you think isnтАЩt right, you can always ask the humans behind semantic-release.


Cannot push to the Git repository.

semantic-release cannot push the version tag to the branch master on the remote Git repository with URL https://[secure]@github.com/subeshb1/Nepali-Date.

This can be caused by:


Good luck with your project тЬи

Your semantic-release bot ЁЯУжЁЯЪА

Wrong value when parsing nepali date string

When parsing invalid date 2020/20/20 it gives 20/08/2021.

The value should be the same when the string is sent to the constructor.

The reason, this bug exists is because it uses the same logic as number constructor.

Acceptance Criteria
The string value should be parsed as it is or not parsed at all.

Wrong Day Of Week

It is giving the wrong day of the week .

let a = new NepaliDate(2077,05,08);

a.format('ddd DD, MMMM YYYY', 'np')
// "рдмрд┐рд╣рд┐рдмрд╛рд░ режрео, рдЖрд╢реНрд╡рд┐рди реирежренрен" <-- output

// "рд╕реЛрдордмрд╛рд░ режрео, рднрд╛рджреНрд░ реирежренрен" <-- Actual Date in Nepali

The automated release is failing ЁЯЪи

ЁЯЪи The automated release from the master branch failed. ЁЯЪи

I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. IтАЩm sure you can fix this ЁЯТк.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here are some links that can help you:

If those donтАЩt help, or if this issue is reporting something you think isnтАЩt right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two Factor Authentication for your account, set its level to "Authorization only" in your account settings. semantic-release cannot publish with the default "
Authorization and writes" level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project тЬи

Your semantic-release bot ЁЯУжЁЯЪА

current date issue

is't it supposed to print the Nepali date (2077/03/11) of input new NepaliDate(new Date(2020, 06, 25)) instead I am getting (2077/03/10) neither I am getting expected output of new NepaliDate() which is current date or am I missing something?

output

Js Date stored in Instance Object is a day behind the date object.

When I am passing a JS Date object as a constructor to NepaliDate, the stored Js date, in the instance, is 1 day behind the original JS date object. This is an example of the problem.

Original Date:  2021-06-08T18:15:00.000Z
Nepali Instance:  NepaliDate {
  [Symbol(Year)]: 2078,
  [Symbol(MonthIndex)]: 1,
  [Symbol(Date)]: 25,
  [Symbol(Day)]: 2,
  [Symbol(JsDate)]: 2021-06-07T18:30:00.000Z
}
Formatted Original:  2021-06-09
Formatted Nepali Date:  2021-06-08

The format is done using Intl.DateTimeFormat.

let formatted = new Intl.DateTimeFormat('en-GB', {timeZone: process.env.TZ, month: '2-digit', day: "2-digit", year: "numeric"}).format(d);

Where process.env.TZ = 'Asia/Kathmandu'

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.