Giter Site home page Giter Site logo

amitgaru2 / nepali-datetime Goto Github PK

View Code? Open in Web Editor NEW
58.0 2.0 25.0 1.25 MB

Python's core datetime inspired Bikram Sambat (BS date) & Nepal Time (NPT) packageЁЯЗ│ЁЯЗ╡

Home Page: https://pypi.org/project/nepali-datetime/

License: MIT License

Python 100.00%
nepali datetime nepali-date nepal bikram date bs samvat sambat bikram-sambat

nepali-datetime's Introduction

Nepali Datetime (Bikram Sambat Date & Nepal Time)

The package inspired from Python's core datetime package that operates on top of Bikram Sambat (B.S) Date & Nepal Time (NPT) +05:45.

Supports: Python 3.5+

Basic Usage

# importing
>>> import datetime
>>> import nepali_datetime

# today's date
>>> datetime.date.today()
>>> nepali_datetime.date.today()

# now datetime
>>> datetime.datetime.now()
>>> nepali_datetime.datetime.now()

# creating date object
>>> datetime.date(2020, 9, 4)
>>> nepali_datetime.date(2077, 5, 19)

# creating datetime object
>>> datetime.datetime(2020, 9, 4, 8, 26, 10, 123456)
>>> nepali_datetime.datetime(2077, 5, 19, 8, 26, 10, 123456)

# date/datetime formatting
>>> nepali_datetime.datetime(2077, 5, 19, 8, 26, 10, 123456).strftime("%d %B %Y")
# 19 Bhadau 2077

# datetime parsed from string (strptime)
>>> nepali_datetime.datetime.strptime('2077-09-12', '%Y-%m-%d')
# nepali_datetime.datetime(2077, 9, 12, 0, 0)

# date/datetime formatting with Nepali unicode support
>>> nepali_datetime.date(1977, 10, 25).strftime('%K-%n-%D (%k %N %G)')
# резрепренрен-резреж-реирел (ренрен рдорд╛рдШ рдЖрдЗрддрдмрд╛рд░)

# datetime.timedelta addition/subtraction
>>> nepali_datetime.date(1990, 5, 10) + datetime.timedelta(days=350)
# nepali_datetime.date(1991, 4, 26)
>>> nepali_datetime.datetime(1990, 5, 10, 5, 10, 20) + datetime.timedelta(hours=3, minutes=15)
# nepali_datetime.date(1990, 5, 10, 8, 25, 20)

# convert B.S to A.D date and vice-versa
>>> nepali_datetime.date(1999, 7, 25).to_datetime_date()
# datetime.date(1942, 11, 10)
>>> nepali_datetime.date.from_datetime_date(datetime.date(1942, 11, 10))
# nepali_datetime.date(1999, 7, 25)

# Bikram Sambat monthly calendar
>>> nepali_datetime.date(2078, 1, 1).calendar()

          Baishakh 2078
Sun  Mon  Tue  Wed  Thu  Fri  Sat
                1    2    3    4
5     6    7    8    9   10   11
12   13   14   15   16   17   18
19   20   21   22   23   24   25
26   27   28   29   30   31

Installation

$ pip install nepali-datetime

Documentation

Complete usage documentations can be found here.

Contribution

Any contributions are most welcome. Do check this guidelines CONTRIBUTING.md for code contribution.

nepali-datetime's People

Contributors

amitgaru2 avatar bixash 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

nepali-datetime's Issues

Neep Help

Sorry for this question, I know this is not a good platform for asking question. Actually I want to build a calendar using django same as below.
image.

I've no idea, how to achieve this one. So can you please share some idea, or guide , that can help me to achieve this. and the last question is how can i use this package in my project. Please give me some idea, I wan't to learn some things in this lock down period.

I'm using django, and python default HTML Calendar modules and here is my progress.
Screenshot_20200504_222010

Getting `day of month out of range` error.

Hi. I have been getting this day of month out of range error when trying to convert date to nepali; and format time.

While rendering Jestha 31, 2077

import nepali_datetime
from datetime import timedelta, datetime

somedate = datetime(2020, 6, 13, 19, 15, 20, 231407) 
jeth_31 = nepali_datetime.date.from_datetime_date(somedate.date())
jeth_31.strftime("%d %N %Y")            
# 31 рдЬреЗрд╖реНрда

Meanwhile Jestha 32, 2077

otherdate = datetime(2020, 6, 14, 19, 15, 20, 231407) 
jeth_32 = nepali_datetime.date.from_datetime_date(otherdate.date())
jeth_32.strftime("%d %N %Y") 
# day of month out of range error

Dunno if this is related with (Nepali) months with 32 date or something in the package itself.
If it helps, I am using Python 3.9, nepali-datetime 1.0.4.

Edit:: Update: Getting same error for Shrawan 32.

Adding Nepali Dates after 2100

I looked into the code of the project and noticed that there the date limited to 2100 bs. I need to implement dates greater than 2100 B.S. for a project. I will be implementing those dates. I will be willing to contribute. Let me know what you think.

calendar and Nepali unicode not rendering properly

Hi. There are some weird characters in the calendar CLI (I am using terminus in sublime3)
and the datetime.date objects to Nepali month conversion throws some error.

image
cmd output
image

edit: got this too "The string that could not be encoded/decoded was: %d рдХрд╛рд░реНрддрд┐рдХ"

Addition of unicode time directives

Currently doesn't support nepali unicode Time directives.
i.e. so Time is displayed only in english literals like 01:22PM and not режрез:реиреи

`%N` directive not working with strptime

So, I checked and found that while using the strptime() method, the %N directive does not work.

Here are some snippets of the error

>>> d = "рдЪреИрддреНрд░"
>>> e = ndt.datetime.now().strftime("%N")
>>> d
'рдЪреИрддреНрд░'
>>> e
'рдЪреИрддреНрд░'
>>> z = ndt.datetime.strptime(d, "%N")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/sthasam/Programming/investo_backend/.venv/lib/python3.8/site-packages/nepali_datetime/__init__.py", line 828, in strptime
    return _custom_strptime._strptime_datetime(cls, date_string, format)
  File "/home/sthasam/Programming/investo_backend/.venv/lib/python3.8/site-packages/nepali_datetime/_custom_strptime.py", line 295, in _strptime_datetime
    tt, fraction = _strptime(data_string, format)
  File "/home/sthasam/Programming/investo_backend/.venv/lib/python3.8/site-packages/nepali_datetime/_custom_strptime.py", line 135, in _strptime
    raise ValueError("'%s' is a bad directive in format '%s'" %
ValueError: 'N' is a bad directive in format '%N'
>>> d == e
True
>>> z = ndt.datetime.strptime(e, "%N")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/sthasam/Programming/.venv/lib/python3.8/site-packages/nepali_datetime/__init__.py", line 828, in strptime
    return _custom_strptime._strptime_datetime(cls, date_string, format)
  File "/home/sthasam/Programming/.venv/lib/python3.8/site-packages/nepali_datetime/_custom_strptime.py", line 295, in _strptime_datetime
    tt, fraction = _strptime(data_string, format)
  File "/home/sthasam/Programming/.venv/lib/python3.8/site-packages/nepali_datetime/_custom_strptime.py", line 135, in _strptime
    raise ValueError("'%s' is a bad directive in format '%s'" %
ValueError: 'N' is a bad directive in format '%N'

As you can see, I tried two strings with the strptime

  1. Directly storing the unicode in d
  2. Deriving month name from inbuilt strftime method

Both do not work with strptime.

>>> f = "рд╡реИрд╢рд╛рдЦ"
>>> g = ndt.datetime(2000,1,1).strftime("%N")
>>> f
'рд╡реИрд╢рд╛рдЦ'
>>> g
'рд╡реИрд╢рд╛рдЦ'
>>> f==g
True
>>> m = ndt.datetime.strptime(f, "%N")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/sthasam/Programming/.venv/lib/python3.8/site-packages/nepali_datetime/__init__.py", line 828, in strptime
    return _custom_strptime._strptime_datetime(cls, date_string, format)
  File "/home/sthasam/Programming/.venv/lib/python3.8/site-packages/nepali_datetime/_custom_strptime.py", line 295, in _strptime_datetime
    tt, fraction = _strptime(data_string, format)
  File "/home/sthasam/Programming/.venv/lib/python3.8/site-packages/nepali_datetime/_custom_strptime.py", line 135, in _strptime
    raise ValueError("'%s' is a bad directive in format '%s'" %
ValueError: 'N' is a bad directive in format '%N'

Same example as above but with a different month.

'%y' behaviour needs alteration

Currently, %y for any year 'xx' > 68 gives 19xx.

While the open group spec does suggest the range [69, 99] to be the year 1900s, it feels a tad bit foolish in the case of Nepali year, no? We're at 2077 currently; so I think that suggestion should be disregarded and updated accordingly.

Need to fix name of months

Firstly, this is a great package. thanks for development. I just want to give a feedback from this thread.
Nepali months name is incorrectly displayed. I believe this is how they should be named.

Also, what about adding some more mathematical operations on the Nepali date and time?

Need to add datetime converter (AD to BS) and vice versa

hello there. I have also had experience with this package also (Nepali: v 0.4.1) in pip.
however I love this module and seen how this has evolved..!

If its not asking too much, can we have more features -
AD to BS and vice versa converter,,
months' name in Nepali (unicode) also..
strfdate and time nepali (unicode) as well..
render nepali calendar with tabbed/spacing month view (np/en)...

thanks for adding more datetime operations.. I have starred this project for your effort.

strftime to support nepali unicode completely

  • support for days name ( like рдЖрдЗрддрдмрд╛рд░ рд╕реЛрдордмрд╛рд░ рдордВрдЧрд▓рдмрд╛рд░ рдмреБрдзрд╡рд╛рд░ рдмрд┐рд╣рд┐рдмрд╛рд░ рд╢реБрдХреНрд░рдмрд╛рд░ рд╢рдирд┐рдмрд╛рд░ )
  • support for days & years digits ( like режрезреирейрекрелремренреореп, реирежренрел, реирежренрем, реирежренрен, ... )

[feature request] get AD dates of Nepali fiscal year

a feature to get AD version of current Nepali fiscal year.
(basically AD dates of gone Shrawan 1 and upcoming Asar masantar).

  • feature display current year's Baisakh 1 in AD and chaitra masantar in AD.

  • feature to display current F/Y's start and end date (fy_start, fy_end in AD).

  • feature to display current F/Y's N months (fy start, fy N months):
    example when N = 10, return date (AD) of gone Shrawan 1 and coming Baisakh masantar (i.e the last date of N=10).

  • add flag to return (i) dates (fy start, fy end as above), OR (ii) a list of months (e.g. [Shrawan, Bharda, ... , Baisakh])

  • similarly, display previous and next fiscal years start and end AD dates.

please feel free to improvise the suggestion/request. Thanks

Implementation of timestamp

As I see, the timestamp() has not been implemented as of yet. Putting this issue out there so devs out there can contribute to this issue.

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.