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

@datatypes/moment

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@datatypes/moment - npm Package Compare versions

Comparing version 0.4.0 to 0.5.0

29

build/classes/Moment.js

@@ -107,3 +107,3 @@ 'use strict';

value: function toString() {
return this.isoString;
return this.string;
}

@@ -113,3 +113,3 @@ }, {

value: function toJSON() {
return this.isoString;
return this.string;
}

@@ -122,10 +122,2 @@ }, {

}, {
key: 'precision',
get: function get() {
return this._precision;
},
set: function set(precision) {
this._precision = precision;
}
}, {
key: 'lowerLimit',

@@ -147,3 +139,3 @@ get: function get() {

}, {
key: 'isoString',
key: 'string',
get: function get() {

@@ -157,2 +149,17 @@ if (!this._isoString) {

}, {
key: 'isoString',
get: function get() {
return this.string;
}
}, {
key: 'intervalString',
get: function get() {
return this.lowerLimit.toISOString() + '--' + this.upperLimit.toISOString();
}
}, {
key: 'duration',
get: function get() {
return new _duration2.default().setMilliseconds(this.upperLimit - this.lowerLimit).normalize();
}
}, {
key: 'object',

@@ -159,0 +166,0 @@ get: function get() {

@@ -43,2 +43,11 @@ 'use strict';

var _Instant = require('./classes/Instant');
Object.defineProperty(exports, 'Instant', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_Instant).default;
}
});
var _Year = require('./classes/Year');

@@ -45,0 +54,0 @@

{
"name": "@datatypes/moment",
"version": "0.4.0",
"version": "0.5.0",
"description": "ISO 8601 based time and date module",

@@ -5,0 +5,0 @@ "main": "build/index",

@@ -15,8 +15,25 @@ # Moment

There are classes for every level of precision.
These classes are all subclasses of the `Moment` base class.
```js
import Moment from '@datatypes/moment'
import momentFromString, {Moment, Instant, Year, Month, Day,
Hour, Minute, Second, Millisecond} from '@datatypes/moment'
new Moment('2015-11-24T21:32:43Z')
const year = new Year('2015')
const month = new Month('2015-11')
const day = new Day('2015-11-24')
const hour = new Hour('2015-11-24T21')
const minute = new Minute('2015-11-24T21:32')
// …
// If the precision is not known before instantiation or may vary
const moment = momentFromString('2015-11-24T21:32:45')
// Returns `new Second('2015-11-24T21:32:45')`
```
The `Instant` class is a simple wrapper for the native `Date` class
in order to be consistent with the ISO 8601 naming schema.
Possible formats for the time-string

@@ -58,6 +75,69 @@ (when a string can be interpreted as a date or a time, date takes precedence)

## Properties
Implemented with setters & getters.
Therefore some properties are static and some are dynamically created.
```js
const minute = new Minute('2015-11-24T21:37')
console.log(minute.day, minute.month, minute.day, minute.hour, minute.minute)
// 2015 11 24 21 37
console.log(minute.string)
// 2015-11-24T21:37Z
console.log(minute.object)
// { string: '2015-11-24T21:37Z',
// lowerLimit: new Instant('2015-11-24T21:37:00.000Z'),
// upperLimit: new Instant('2015-11-24T21:38:00.000Z') }
console.log(minute.lowerLimit.toISOString())
// 2015-11-24T21:37:00.000Z
console.log(minute.upperLimit.toISOString())
// 2015-11-24T21:38:00.000Z
console.log(minute.intervalString)
// Returns an interval string with start and end properties
// from a moment with upperLimit and lowerLimit properties.
//
// 2015-11-24T21:37:00.000Z--2015-11-24T21:38:00.000Z
console.log(minute.duration)
// new Duration('PT1M0.0S')
```
Setters for properties are available as native setters and as methods:
```js
const minute = new Minute('2015-11-24T21:37')
minute.minute = 42
minute.setMinute(32)
```
This allows for easy chaining:
```js
const moment = new Moment()
.setYear(2015)
.setMonth(11)
.setDay(24)
.setHour(21)
.setMinute(37)
```
## Methods
### `toObject`
### `toString()` or `toJSON()` (alias for `.string`)
```js
new Day('2015-11-24').toString() === '2015-11-24'
```
### `toObject()` (alias for `.object`)
Returns a plain-object representation of the Moment instance.

@@ -67,6 +147,6 @@ The lower limit is always inclusive and the upper limit exclusive.

```js
new Moment('2015-11-24T21:37:42.123Z').toObject() === {
new Millisecond('2015-11-24T21:37:42.123Z').toObject() === {
string: '2015-11-24T21:37:42.123Z',
lowerLimit: new Date('2015-11-24T21:37:42.123Z'),
upperLimit: new Date('2015-11-24T21:37:42.124Z'),
lowerLimit: new Instant('2015-11-24T21:37:42.123Z'),
upperLimit: new Instant('2015-11-24T21:37:42.124Z'),
precision: 'millisecond'

@@ -77,22 +157,12 @@ }

### `toJSON`
### `startOfYear()`, `startOfMonth()`, `startOfDay()`, …
Returns a JSON representation of the Hour instance.
### `maximumOffset(anotherMoment)`
```js
new Moment('2015-11-24').toJSON() === '{' +
'"string":"2015-11-24",' +
'"precision":"day",' +
'"lowerLimit":"2015-11-24T00:00:00.000Z",' +
'"upperLimit":"2015-11-25T00:00:00.000Z"' +
'}'
```
### `isBefore(anotherMoment)`
### `isAfter(anotherMoment)`
### `toString`
### `isSimultaneous(anotherMoment)`
Returns the ISO 8601 representation of the Hour instance.
```js
new Moment('2015-11-24T21:37:42.123Z').toString() === '2015-11-24T21:37:42.123Z'
```
### `clone()`
import runTest from 'ava'
import expect from 'unexpected'
import Duration from '@datatypes/duration'
import momentFromString, {Moment, Year, Month, Day,

@@ -39,1 +41,22 @@ Hour, Minute, Second, Millisecond} from '../source/index'

})
runTest('interval string', test => {
const day = new Day('2015-11-24')
expect(
day.intervalString,
'to equal',
'2015-11-24T00:00:00.000Z--2015-11-25T00:00:00.000Z'
)
const minute = new Minute('2015-11-24T17:34')
expect(
minute.intervalString,
'to equal',
'2015-11-24T17:34:00.000Z--2015-11-24T17:35:00.000Z'
)
})
runTest('duration', test => {
const day = new Day('2015-11-24')
expect(day.duration, 'to equal', new Duration('P24H0M0.0S'))
})
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