npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wx-datetime-picker

v1.1.0

Published

基于微信小程序原生多列选择器的日期时间选择器,用于选择日期时间,支持同时选择日期和时间。

Downloads

6

Readme

wx-datetime-picker

A Datetime Picker based on Wechat Miniprogram's native MultiSelector Picker. Used to select time, support date and time dimensions.

Install

npm

Before using npm, please checkout the npm surpport for Wechat Miniprogram.

# install via npm
npm i wx-datetime-picker -S --production

Build npm package

Click the menu bar in Weixin DevTools, and go to Tools > Build npm, then check the Use npm module option. The npm package can be used once built.

Usage

Declare Component

Declare at app.json for global usage

{
  "usingComponents": {
    "datetime-picker": "wx-datetime-picker/index"
  }
}

Declare at page.json for side usage

{
  "usingComponents": {
    "datetime-picker": "wx-datetime-picker/index"
  }
}

Using Component

<datetime-picker
  box-class="custom-class"
  min="{{min}}"
  max="{{max}}"
  fields="{{fields}}"
  value="{{value}}"
  disabled="{{disabled}}"
>
  <text>Choose Datetime</text>
</datetime-picker>

Example

Basic Usage

<datetime-picker
  box-class="cell"
  value="{{value}}"
  bindchange="setValue"
>
  <view class="cell-title">Choose Datetime</view>
  <view class="cell-value">{{value}}</view>
</datetime-picker>

Disabled Selection

<datetime-picker
  box-class="cell"
  value="{{value}}"
  bindchange="setValue"
  disabled
>
  <view class="cell-title">Choose Datetime</view>
  <view class="cell-value">{{value}}</view>
</datetime-picker>

Custom Valid Range

<datetime-picker
  box-class="cell"
  min="{{min}}"
  max="{{max}}"
  value="{{value}}"
  bindchange="setValue"
>
  <view class="cell-title">Choose Datetime</view>
  <view class="cell-value">{{value}}</view>
</datetime-picker>

Choose Year-Month-Day

<datetime-picker
  box-class="cell"
  value="{{value}}"
  bindchange="setValue"
  fields="day"
>
  <view class="cell-title">Choose Year-Month-Day</view>
  <view class="cell-value">{{value}}</view>
</datetime-picker>

Choose Year-Month

<datetime-picker
  box-class="cell"
  value="{{value}}"
  bindchange="setValue"
  fields="month"
>
  <view class="cell-title">Choose Year-Month</view>
  <view class="cell-value">{{value}}</view>
</datetime-picker>

Choose Year-Month-Day Hour

<datetime-picker
  box-class="cell"
  value="{{value}}"
  bindchange="setValue"
  fields="hour"
>
  <view class="cell-title">Choose Year-Month-Day Hour</view>
  <view class="cell-value">{{value}}</view>
</datetime-picker>

Choose Year-Month-Day Hour:Minute

<datetime-picker
  box-class="cell"
  value="{{value}}"
  bindchange="setValue"
  fields="minute"
>
  <view class="cell-title">Choose Year-Month-Day Hour:Minute</view>
  <view class="cell-value">{{value}}</view>
</datetime-picker>

Nested Style

<datetime-picker
  box-class="picker"
  value="{{value}}"
  mode="picker-view"
  bindchange="setValue"
/>

API

Props

| Attribute | Type | Description | Default | | :------------ | :-------------------------------------------------- | :------------------------------------------------------- | :-------------------- | | mode | 'picker'\|'picker-view' | How the component place in page | picker | | min | string | The min of the valid date range, any valid Date string | 1900-01-01 00:00:00 | | max | string | The max of the valid date range, any valid Date string | 2099-12-31 23:59:59 | | value | string | The selected datetime, any valid Date string | - | | fields | 'year'\|'month'\|'day'\|'hour'\|'minute'\|'second' | The granularity of the picker | minute | | disabled | boolean | Specifies whether to disable the component | false | | headerText | string | Selector Title, available for Android only |

  •                 |

Events

| Event | Description | Arguments | | :-------- | :---------------------------------------------------------------------------- | :--------------------------- | | column | Triggered when the column changes (available when mode is picker only) | Changed column and its value | | change | Triggered when the value is changed | Changed value | | cancel | Triggered when selection is canceled (available when mode is picker only) | - |

External Classes

| Class | Description | | :---------------- | :------------------------------------------------------------------------------------ | | box-class | ClassName of the root node (<picker /> or <picker-view />) | | indicator-class | ClassName of the checkbox in the picker (available when mode is picker-view only) | | mask-class | ClassName of the mask in the picker (available when mode is picker-view only) | | column-class | ClassName of every column in the picker (available when mode is picker-view only) | | unit-class | ClassName of every unit in columns (available when mode is picker-view only) |

Demo

Clone this repo, Run npm i & npm run dev. Import miniprogram_dev to Wechat Developer Tool.

Sample Preview

demo.png

Sample Code

<!-- index.html -->
<view class="container">
  <view class="label">基础用法</view>
  <datetime-picker
    box-class="cell"
    value="{{value}}"
    bindchange="setValue"
    data-field="value"
  >
    <view class="cell-title">选择时间日期</view>
    <view class="cell-value">{{value}}</view>
  </datetime-picker>
  <datetime-picker
    box-class="cell cell-disabled"
    value="{{now}}"
    bindchange="setValue"
    data-field="now"
    disabled
  >
    <view class="cell-title">禁用状态</view>
    <view class="cell-value">{{now}}</view>
  </datetime-picker>
  <datetime-picker
    box-class="cell"
    min="{{min}}"
    max="{{max}}"
    value="{{customize}}"
    bindchange="setValue"
    data-field="customize"
  >
    <view class="cell-title">自定可选范围</view>
    <view class="cell-value">{{customize}}</view>
  </datetime-picker>
  <view class="label">自定义选择器粒度</view>
  <datetime-picker
    box-class="cell"
    value="{{year}}"
    bindchange="setValue"
    data-field="year"
    fields="year"
  >
    <view class="cell-title">年为粒度</view>
    <view class="cell-value">{{year}}</view>
  </datetime-picker>
  <datetime-picker
    box-class="cell"
    value="{{month}}"
    bindchange="setValue"
    data-field="month"
    fields="month"
  >
    <view class="cell-title">月为粒度</view>
    <view class="cell-value">{{month}}</view>
  </datetime-picker>
  <datetime-picker
    box-class="cell"
    value="{{day}}"
    bindchange="setValue"
    data-field="day"
    fields="day"
  >
    <view class="cell-title">日为粒度</view>
    <view class="cell-value">{{day}}</view>
  </datetime-picker>
  <datetime-picker
    box-class="cell"
    value="{{hour}}"
    bindchange="setValue"
    data-field="hour"
    fields="hour"
  >
    <view class="cell-title">时为粒度</view>
    <view class="cell-value">{{hour}}</view>
  </datetime-picker>
  <datetime-picker
    box-class="cell"
    value="{{minute}}"
    bindchange="setValue"
    data-field="minute"
    fields="minute"
  >
    <view class="cell-title">分为粒度</view>
    <view class="cell-value">{{minute}}</view>
  </datetime-picker>
  <datetime-picker
    box-class="cell"
    value="{{second}}"
    bindchange="setValue"
    data-field="second"
    fields="second"
  >
    <view class="cell-title">秒为粒度</view>
    <view class="cell-value">{{second}}</view>
  </datetime-picker>
  <view class="label">嵌入式选择器</view>
  <view class="cell">
    <view class="cell-title">下方选中时间日期</view>
    <view class="cell-value">{{view}}</view>
  </view>
  <datetime-picker
    box-class="cell-picker"
    value="{{view}}"
    mode="picker-view"
    bindchange="setValue"
    data-field="view"
  />
</view>
/* index.js */
const formatNumber = (n) => (
  n = n.toString(),
  n[1] ? n : 0 + n
);

const now = new Date();
const nowYear = now.getFullYear();
const nowMonth = formatNumber(now.getMonth() + 1);
const nowDay = formatNumber(now.getDate());
const nowHour = formatNumber(now.getHours());
const nowMinute = formatNumber(now.getMinutes());
const nowSecond = formatNumber(now.getSeconds());
const nowDatetime = `${nowYear}-${nowMonth}-${nowDay} ${nowHour}:${nowMinute}:${nowSecond}`;

Page({
  data: {
    min: '2010-01-01 00:00:00',
    max: '2030-12-31 23:59:59',
    now: nowDatetime.slice(0, nowDatetime.lastIndexOf(':')),
    value: nowDatetime.slice(0, nowDatetime.lastIndexOf(':')),
    customize: nowDatetime.slice(0, nowDatetime.lastIndexOf(':')),
    year: nowDatetime.slice(0, nowDatetime.indexOf('-')),
    month: nowDatetime.slice(0, nowDatetime.lastIndexOf('-')),
    date: nowDatetime.slice(0, nowDatetime.indexOf(' ')),
    hour: nowDatetime.slice(0, nowDatetime.indexOf(':')),
    minute: nowDatetime.slice(0, nowDatetime.lastIndexOf(':')),
    second: nowDatetime,
    view: nowDatetime.slice(0, nowDatetime.lastIndexOf(':')),
  },
  setValue(e) {
    const { field } = e.currentTarget.dataset;
    this.setData({
      [`${field}`]: e.detail.value,
    });
  },
});

License

MIT