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

@nowzoo/ngx-date-time

v8.0.3

Published

Simple, extensible date and time controls and utilities. Forgiving and (more or less) locale-aware.

Downloads

6

Readme

@nowzoo/ngx-date-time

Simple date and time controls and utilities.

  • Extensible.
  • Forgiving of multiple date and time input formats.
  • (More or less) locale-aware.

Stackblitz demo

Installation

Install the library and its dependencies (moment and lodash).

npm i --save @nowzoo/ngx-date-time moment lodash

Usage

Import the library module...

import { NgxDateTimeModule } from '@nowzoo/ngx-date-time';
@NgModule({
  imports: [
    NgxDateTimeModule
  ]
})
export class MyModule { }

The ngx-date-control and ngx-time-control components are now available for you to use:

<ngx-date-control
  [inputId]="formId + 'date'"
  inputClass="form-control"
  [(ngModel)]="date"></ngx-date-control>
<ngx-time-control
  [inputId]="formId + 'time'"
  inputClass="form-control"
  [(ngModel)]="time"></ngx-time-control>

Public API

Constants

  • const MODEL_DATE_FORMAT = 'YYYY-MM-DD'
    The format for dates.
  • const MODEL_TIME_FORMAT = 'HH:mm'
    The format for times.

Interfaces

interface IDateParseResult

  • year: number
  • month: number
  • date: number

interface ITimeParseResult

  • hour: number
  • minute: number

Classes

class NgxDateTimeParser

Static methods to "guess" dates and times from a variety of strings the user may input.

  • static parseDate(dateStr: string): IDateParseResult
  • static parseTime(timeStr: string): ITimeParseResult

class NgxDateValidators

Date control validation designed to work with MODEL_DATE_FORMAT; that is, both the control value and the min/max constraint are expected to be strings in the format YYYY-MM-DD.

  • static minDate(min: string): ValidatorFn
    If the control value is a day before min, the function will return {minDate: true}

  • static maxDate(min: string): ValidatorFn
    If the control value is a day after max, the function will return {maxDate: true}

abstract class NgxAbstractDateControl implements ControlValueAccessor

An abstract base class for a date control that

  • accepts a variety of user inputs,
  • "guesses" the date,
  • normalizes the model value to MODEL_DATE_FORMAT, and
  • sets the displayed input value to a format of your choosing.

Note that the actual value of your control will always be in the format MODEL_DATE_FORMAT -- not the format displayed to the user. If the value you pass in cannot be parsed -- if it's not formatted to MODEL_DATE_FORMAT -- then the control value will be the current day.

  • abstract displayFormat: string
    A Moment format, like 'LL'. This is the format that will be displayed in the text box. Your implementation must set this.

abstract class NgxAbstractTimeControl implements ControlValueAccessor

An abstract base class for a time control that

  • accepts a variety of user inputs,
  • "guesses" the time,
  • normalizes the model value to MODEL_TIME_FORMAT, and
  • sets the displayed input value to a format of your choosing.

Note that the actual value of your control will always be in the format MODEL_TIME_FORMAT -- not the format displayed to the user. If the value you pass in cannot be parsed -- if it's not formatted to MODEL_TIME_FORMAT -- then the control value will be set to the current time.

  • abstract displayFormat: string
    A moment format, like 'LT'. This is the format that will be displayed in the text box. Your implementation must set this.

Components

DateControlComponent extends NgxAbstractDateControl

An implementation of NgxAbstractDateControl.

Selector: ngx-date-control

Inputs:

  • displayFormat: string
    The format that will be displayed to the user. See Moment's formatting docs. Default: LL
  • inputClass: string
    The class to be applied to the text input. Pass any error classes here. Default: form-control.
  • inputPlaceholder: string
    The placeholder to be applied to the text input. Default: Enter date....
  • inputId: string
    The id to be applied to the text input.

TimeControlComponent extends NgxAbstractTimeControl

An implementation of NgxAbstractTimeControl.

Selector: ngx-time-control

Inputs:

  • displayFormat: string
    The format that will be displayed to the user. See Moment's formatting docs. Default: LT
  • inputClass: string
    The class to be applied to the text input. Pass any error classes here. Default: form-control.
  • inputPlaceholder: string
    The placeholder to be applied to the text input. Default: Enter time....
  • inputId: string
    The id to be applied to the text input.

Development

Contributions are welcome.

git clone https://github.com/nowzoo/ngx.git
npm i

The library code is located in projects/ngx-date-time.

To run tests:

  • ng test ngx-date-time
  • or use the wallaby.js file at projects/ngx-date-time/wallaby.js

Build the library with ng build ngx-date-time.

License

MIT