Giter VIP home page Giter VIP logo

dateranger's Introduction

dateranger

Introduction

This is a tool that takes a string representing a date range and returns a dictionary or it can translate it to a date range. The interesting thing is this library can take many different strings representing different ranges or time periods and return the appropriate date range.

Takes a string representing some sort of date or date range in the form of:

- A 4 digit year -> yyyy -> 0000 - 9999

- An isoyear-iso month (yyyy-mm)

- Isoweek (yyyyWnn), week (01 - 53)
    - assumes it is a week in the past of the current year

- Isodate - a date in iso format (yyyy-mm-dd)

- Week number - 1 to 53
    - Assumes current year

- Week offset (0, -1, -2)
    - The relative week less than or equal to 0,

- date range
    - that is one yyyy-mm-dd to another ("yyyy-mm-dd to yyyy-mm-dd")

It will return a dictionary with one of the following keys:

- 'year' -> returns an integer

- 'year-month' -> tuple(int(year), int(mm))

- 'year-month-day' -> tuple(int(year), int(mm), int(dd))

- 'year-week' -> tuple(int(year), int(week))

- 'week-offset' -> int

- 'week-number' -> int

- 'date-range' -> tuple(tuple(int(year), int(mm), int(dd)), tuple(int(year), int(mm), int(dd)))
    - first element is the start date, second element is the end date

QuickStart

  1. Install Rye
  2. Installation and Configuration
  3. Activate

Installation and Configuration

To get this project up and running from the repository, it uses Rye as the build/dependency manager. There are instructions for installing Rye on many different systems. This set of instructions are for Linux and windows. See the installation guide for other operating systems.

You have to download Rye to your system. Follow the installation guide for your operating system.

Why Rye? That is a good question. Python is a great language but it is tough to create a reproducible environment. You have to have the correct version of Python installed or available. You have to have the correct tools configured. If you are on Linux/BSD you have to make sure that your work doesn't mess up your system Python installation. It is fairly trivial if you are experienced, but annoying enough to have to do it over-and-over again. If you are new, it can be extremely difficult.

Rye takes care of handling the different versions of Python and managing the tools you need for a reproducible environment, particularly if you are doing cross-platform work.

Linux

For Linux, you can use the following:

curl -sSf https://rye-up.com/get | bash

There are also good guides to configuring Rye for your shell. Here is what I had to do to get it working in ZSH on my system.

Edit .zshrc:

vi ~/.zshrc

Add the following:

source "$HOME/.rye/env"

Restart the terminal and type rye. To add shell completion, you can:

mkdir $ZSH_CUSTOM/plugins/rye
rye self completion -s zsh > $ZSH_CUSTOM/plugins/rye/_rye

Windows

For windows, download the installer listed in the installation guide link.

Basic Rye Usage

Rye Update

Update rye:

rye self update

Rye Sync

Once you have rye properly installed, you can run rye sync, to build (or update) the virtual environment.

Create/Update Virtual Environment

rye sync

NOTE: This needs to be run from within the repository. If you add new dependencies or modify the pyproject.toml you should run rye sync.

Activate Virtual Environment - Traditional Approach

You can add the following alias to your .zshrc or .bashrc, or you can run the activate script directly:

# Python Virtual Environment Alias
alias activate="source .venv/bin/activate"

NOTE: On Windows, there is an activate.ps1, a PowerShell script that you can execute.

Usage

BuiUse the module like:

>>> from dateranger.dateranger import date_range_str

>>> date_range_str('2020-01-01 - 2020-07-31')
(date(2020,1,1),date(2020,7,31))

>>> date_range_str('2022W03')
(date(2022,1,17),date(2022,1,23))

License

Please refer to LICENSE.md.

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.