New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@persian-tools/persian-mobile-datepicker

Package Overview
Dependencies
Maintainers
3
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@persian-tools/persian-mobile-datepicker

Modern Persian mobile date picker

  • 0.0.6
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created
Source

Persian Mobile Date and Time picker

This library provides a component that can set year, month, day, hour, minute and second by sliding up or down.

  • Note: There is no need to use the moment-jalaali or any other Jalali libraries and every function you need has been documented and if you need a function that we don't have, let us know to implement it.

Demo

All functionalities and demos have documented here: Demo

Theme

Light theme

Dark theme

Getting Started

Install

Using npm:

$ npm install --save @persian-tools/persian-mobile-datepicker

Using yarn:

$ yarn add --save @persian-tools/persian-mobile-datepicker

Import what you need

The following guide assumes you have some sort of ES2015 build set up using babel and/or webpack/browserify/gulp/grunt/etc.

import {
  Picker,
  DateConfigValuesModel,
  DateConfigTypes,
} from '@persian-tools/persian-mobile-datepicker';
const config: Partial<Record<DateConfigTypes, DateConfigValuesModel>> = {
  year: {
    caption: {
      text: 'سال',
    },
  },
  month: {
    caption: {
      text: 'ماه',
    },
  },
  day: {
    caption: {
      text: 'روز',
    },
  },
};
const App = () => {
  return <Picker
    config={config}
    minDate={sub(new Date(), { years: 2 })}
    maxDate={new Date()}
    onSubmit={handleSubmit}
    isOpen={showPicker}
    highlightWeekends
    />
  }

PropTypes

PropertyTypeDescription
configDatePickerConfigconfiguration of datepicker
classNamePrefixstringclassName of the datepicker
initialValueDateinitial date of datepicker
valueWheelPickerSelectEventvalue of datepicker
titlestringtitle of datepicker
onChange(selected: WheelPickerSelectEvent) => voidGets called when value of the picker changes
minDateDateSpecifies the minimum selectable day by user
maxDateDateSpecifies the maximum selectable day by user
endYearnumberThe Minimum selectable year(Picker will calculate the StartYear by this approach: currentYear + startYear)
startYearnumberThe Maximum selectable year(Picker will calculate the StartYear by this approach: currentYear + startYear)
highlightWeekendsbooleanDetermines whether to mark weekend days with red or not. (weekend day is Friday)
highlightHolidaysbooleanDetermines whether to mark holidays in day column.

Custom date unit

set config to configure year, month, day.

config = {
  year: {
    caption: {
      text: 'سال',
    },
  },
  month: {
    caption: {
      text: 'ماه',
    },
  },
  day: {
    caption: {
      text: 'روز',
    },
  },
};

datePickerConfig

[key in DateConfigTypes]: DateConfigValuesModel

where the DateConfigTypes is one of "year", "month", "day", "hour", "minute", "second"

DateConfigValuesModel

PropertyTypeDescription
captionObjectand object with the props text string and style regular react style object
formatterFunctiona function of PickerExtraDateInfo to format the date
classnameFunctiona function of PickerExtraDateInfo for specifiying the classNames
shouldRenderFunctiona function of PickerExtraDateInfo to specify which functionalities should render
columnStyleCSSPropertiesthe inline style of columns of datepicker
itemStyleCSSPropertiesthe inline style of each of cell items
selectedItemStyleCSSPropertiesthe inline style of selected cell item

WheelPickerSelectEvent

PropertyTypeDescription
objectPickerDateModeland object with the props text string and style regular react style object
eventsArraythe array of events
dateDatethe value of date

PickerExtraDateInfo

PropertyTypeDescription
weekDaynumberthe number of day of week
weekDayTextstringcan have these values: شنبه , یک‌شنبه , دو‌شنبه , سه‌شنبه , چهار‌شنبه , پنج‌شنبه , جمعه or other names if you prefer
monthTextstringis the text of months for e.g. فروردین
dayOfYearnumbernumber of day in a year
isLeapYearbooleanwhether the year is a leap year or not
isHolidaybooleanwhether the day is a holiday or not
yearnumbercurrent year
monthnumbercurrent month
daynumbercurrent day
hournumbercurrent hour
minutenumbercurrent minute
secondnumbercurrent second

Usage Examples

Changing the months text

You can do it with the help of formatter props of month in config

{
  year: {
    caption: {
      text: "سال",
    }
  },
  month: {
    caption: {
      text: "ماه",
    },
    formatter: ({ month, monthText }) => (month === 5 ? "امرداد" : monthText),
  },
  day: {
    caption: {
      text: "روز",
    }
  }


Removing a day

If for whatever reason you want to remove some cells you can do so with the use of shouldRender

the following config code will remove the 6th day of 3rd month

{
  year: {
    caption: {
      text: "سال",
    }
  },
  month: {
    caption: {
      text: "ماه",
    }
  },
  day: {
    caption: {
      text: "روز",
    },
    shouldRender: ({ month, day }) => !(month === 3 && day === 6),
  }

Styling columns

If you want to change the inline style of columns or cells of datepicker you can use columnStyle, itemStyle and selectedItemStyle

{
  year: {
    caption: {
      text: "سال",
    },
  },
  month: {
    caption: {
      text: "ماه",
    },
    columnStyle: { background: "#aaa", color: "green" },
    itemStyle: { color: "green" },
    selectedItemStyle: { color: "blue" },
  },
  day: {
    caption: {
      text: "روز",
    },
  }

Date helpers

  • newDate: Convert Jalaali Date to Gregorian and returns a Date instance
import { newDate } from '@persian-tools/persian-mobile-datepicker';

newDate({
  year: 1400,
  month: 1,
  day: 0,
}); // Sun Mar 21 2021 00:00:00 GMT+0330 (Iran Standard Time)
  • convertDateInstanceToDateObject: Convert entered date to an object
import { convertDateInstanceToDateObject } from '@persian-tools/persian-mobile-datepicker';

convertDateInstanceToDateObject(new Date()); // {year: 1400, month: 5, day: 15, hour: 22, minute: 20,second: 10}
  • daysInMonth: Get the number of days in a month of a year
import { daysInMonth } from '@persian-tools/persian-mobile-datepicker';

daysInMonth(1400, 1); // 31
  • getWeekDay: Get the day of the week of the given date. Returns number starts from 0, 0 means the first day of Week and 6 means the last day of Week
import { getWeekDay } from '@persian-tools/persian-mobile-datepicker';

getWeekDay(1400, 5, 15); // 6
  • getDayOfYear: Get the day of the year of the given date.
import { getDayOfYear } from '@persian-tools/persian-mobile-datepicker';

getDayOfYear(1400, 5, 15); // 139
  • isWeekend: Return true if the Date is at the Weekend
import { isWeekend } from '@persian-tools/persian-mobile-datepicker';

isWeekend(1400, 5, 22); // true -> because it is friday
isWeekend(1400, 5, 23); // false -> it is Saturday
  • getWeekDayText: Get Name the days of the week
import { getWeekDayText } from '@persian-tools/persian-mobile-datepicker';

getWeekDayText(1400, 5, 22); // جمعه
getWeekDayText(1400, 5, 23); // شنبه
  • isValidJalaaliDate: Is the given Jalaali date valid?
import { isValidJalaaliDate } from '@persian-tools/persian-mobile-datepicker';

isValidJalaaliDate(1399, 12, 30); // true -> because 1399 is leap
isValidJalaaliDate(1400, 12, 30); // false
  • isBefore: Is the first date before the second one?
import { isBefore, newDate } from '@persian-tools/persian-mobile-datepicker';

const firstDate = newDate(1399, 12, 30);
const secondtDate = newDate(1400, 2, 1);

isBefore(firstDate, secondtDate); // true
  • isAfter: Is the first date after the second one?
import { isAfter, newDate } from '@persian-tools/persian-mobile-datepicker';

isAfter(newDate(1361,10,10), newDate(1372,10,10)); // false
isAfter(newDate(1372,10,10), newDate(1361,10,10)); // false
  • format: Returns the formatted date string in the given format. The result may vary by locale.
import { format } from '@persian-tools/persian-mobile-datepicker';

format(new Date('2020-10-10'), 'yyyy/MM/dd'); // 1399/07/19
  • isEqual: Are the given dates equal?
import { isEqual, newDate } from '@persian-tools/persian-mobile-datepicker';

isEqual(newDate(1361,10,10), newDate(1372,10,10)); // false
isEqual(newDate(1361,10,10), newDate(1361,10,10)); // true
  • getCurrentYear: Get the year of the current date.
import { getCurrentYear } from '@persian-tools/persian-mobile-datepicker';

getCurrentYear(); // 1400
  • currentDateObject: Converts date instance to an object.
import { currentDateObject } from '@persian-tools/persian-mobile-datepicker';

currentDateObject(); // {day: 16, hour: 5, minute: 51, month: 5, second: 1, year: 1400}
  • isLeapYear: Check if the entered year is Leap
import { isLeapYear } from '@persian-tools/persian-mobile-datepicker';

isLeapYear(1399); // true
isLeapYear(1400); // false

Roadmap

  • Add hour, minute and seconds
  • Implement react native component

Keywords

FAQs

Package last updated on 07 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc