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

alexa-date-converter

v1.0.3

Published

A library to help convert AMAZON dot DATE strings to useful objects

Downloads

2

Readme

Coverage Status

alexa-date-converter

A library to help convert AMAZON.DATE (reference) strings to useful objects.

Cases Covered

This library can convert the following date strings. Note: output in the examples below is the product of the new AlexaDateConverter().convertToDay function.

| Type Of Date String | Example Input From Alexa | Example Object After Conversion | | ------------- | ------------- | ------------- | | "specific day" | "2019-12-25" | output.toString(); // "2019-12-25" | | "specific week" | "2009-W01" | output.toString(); // "2008-12-29" (see note below) | | "weekend for a specific week" | "2009-W01-WE" | output.toString(); // "2009-01-10" | | "month of year" | "2019-12" | output.toString(); // "2019-12-01" | | "year" | "2019" | output.toString(); // "2019-01-01" | | "decade" | "200X" | output.toString(); // "2000-01-01" | | "season" | "2009-SU" | output.toString(); // "2009-06-01" |

Note on "specific week": Since Alexa provides ISO week format, the result can be strange (at first glance) since the day appears outside of the Gregorian calendar year. However, this can be clarified by looking at the math behind the ISO Calendar:

the "first week of the ISO calendar year is the earliest week that contains at least four days of the month of January"

You can read more about ISO calendar here: https://www.staff.science.uu.nl/~gent0113/calendar/isocalendar_text_2.htm

Examples

Basic Example

Standard ISO day string to LocalDate:

If an Alexa user utters the phrase "next Tuesday" then Alexa might send you an ISO Date string like "2019-10-01". If so, this library will turn that into an object that is easy to work with:

import { AlexaDateConverter } from 'alexa-date-converter';

const day = new AlexaDateConverter().convertToDay("2009-06-01");
console.log(day); // "2009-06-01"

But since Alexa could send you many other types of date strings, you will probably be most interested in the examples below.

When Alexa provides a date for a specific "season"

Since Alexa can translate an utterance of "next summer" into "2009-SU" you need a way to reference the first day of the upcoming summer. Here's how you would do that.

import { AlexaDateConverter } from 'alexa-date-converter';

const day = new AlexaDateConverter().convertToDay("2009-SU");
console.log(day); // "2009-06-01"

Note: You can change the specific start days that AlexaDateConverter uses by specifying that option in the AlexaDateConverter's constructor. It defaults to the seasons of northern hemisphere as specified by the meteorological calendar.

When Alexa provides a date for a specific "week of the year"

Since Alexa can translate an utterance of "next week" into "

import { AlexaDateConverter } from 'alexa-date-converter';
import { DayOfWeek } from "js-joda";

const dateConverter = new AlexaDateConverter();
const day = dateConverter.convertToDay("2009-W01");
console.log(day); // 2009-01-06

More Examples

Visit src\index.spec.ts to see all of the ways that this library can be used