Giter Club home page Giter Club logo

utc-date's Introduction

๐Ÿšจ No longer maintained. Moved to @reallyland/node_mod. ๐Ÿšจ

utc-date

Generate JavaScript's UTC dates with various offsets


Buy Me A Coffee tippin.me Follow me

Version Node version MIT License

Downloads Total downloads Packagephobia Bundlephobia

CircleCI Dependency Status codecov Coverage Status

codebeat badge Codacy Badge Code of Conduct

Returns a JavaScript date object using the UTC timezone with optional offsets to adjust the year, month, or date.

Table of contents

Pre-requisites

Setup

Install

# Install via NPM
$ npm install --save @motss/utc-date

Usage

TypeScript or ES Modules

import {
  utcDate,
  // utcDateSync,
} from '@motss/utc-date';

void async function main() {
  /** NOTE: Assuming today's date is '2020-02-02', */
  const defaultUTCDate = await utcDate();
  const defaultUTCDateWithOffsets = await utcDate({
    offset: {
      year: 2,
      month: 1,
      day: 0,
    },
  });
  const specifiedUTCDate = await utcDate({
    startDate: '2030-03-02',
  });
  
  assert(defaultUTCDate, new Date('2020-02-02T00:00:00.000Z')); // OK
  assert(defaultUTCDateWithOffsets, new Date('2022-03-02T00:00:00.000Z')); // OK
  assert(specifiedUTCDate, new Date('2030-03-02T00:00:00.000Z')); // OK
}();

Node.js

const {
  utcDate,
  // utcDateSync,
} = require('@motss/utc-date');

void async function main() {
  /** NOTE: Assuming today's date is '2020-02-02', */
  const defaultUTCDate = await utcDate(); // utcDateSync();
  const defaultUTCDateWithOffsets = await utcDate({
    offset: {
      year: 2,
      month: 1,
      day: 0,
    },
  });
  const specifiedUTCDate = await utcDate({
    startDate: '2030-03-02',
  });

  assert(defaultUTCDate, new Date('2020-02-02T00:00:00.000Z')); // OK
  assert(defaultUTCDateWithOffsets, new Date('2022-03-02T00:00:00.000Z')); // OK
  assert(specifiedUTCDate, new Date('2030-03-02T00:00:00.000Z')); // OK
}();

Browser

ES Modules

<script type="module">
  import { utcDate } from 'https://unpkg.com/@motss/utc-date@latest/dist/utc-date.js';

  utcDate()
    .then(console.log)
    .catch(console.error);
</script>

IIFE

<script src="https://unpkg.com/@motss/utc-date@latest/dist/utc-date.iife.js"></script>
<script>
  const { utcDate } = window.UTCDate;

  utcDate()
    .then(console.log)
    .catch(console.error);
</script>

API Reference

UTCDateParams

  • offsets <?Object> Optional offset values when returning a JavaScript Date object using the UTC timezone.
    • year <?number> Optional offset to adjust the year.
    • month <?number> Optional offset to adjust the month.
    • day <?number> Optional offset to adjust the day.
  • startDate <?string|?number|?Date> Optional starting date. Defaults to today's date if it is not given.

utcDate([UTCDateParams])

utcDateSync([UTCDateParams])

This methods works the same as utcDate([UTCDateParams]) except that this is the synchronous version.

Related works

  • utc-time - Manipulate UTC Time with ease in JavaScript

License

MIT License ยฉ Rong Sen Ng

utc-date's People

Contributors

motss avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

utc-date's Issues

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.