Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ambitus

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ambitus - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

54

ambitus.js

@@ -14,4 +14,4 @@ /*global define*/

var config = self.config,
beforeChange = config.onBeforeChange,
change = config.onChange,
onbeforeChange = config.onBeforeChange,
onChange = config.onChange,
current = self.get(),

@@ -23,3 +23,3 @@ potential = {

if (typeof beforeChange === 'function' && beforeChange(potential, current) === false) {
if (typeof onbeforeChange === 'function' && onbeforeChange(potential, current) === false) {
return current;

@@ -31,4 +31,4 @@ }

if (typeof change === 'function') {
change(potential, current);
if (typeof onChange === 'function') {
onChange(potential, current);
}

@@ -45,4 +45,3 @@

// config.weekStart
// config.utc
self.m = config.moment || moment;

@@ -54,3 +53,3 @@ self._interval = self.config.interval || 'month';

intervals.forEach(function (interval) {
self.ranges[interval] = moment().range(moment().startOf(interval), moment().endOf(interval));
self.ranges[interval] = self.m().range(self.m().startOf(interval), self.m().endOf(interval));
});

@@ -66,3 +65,3 @@

var self = this,
today = moment(),
today = self.m(),
oldRange = self.ranges[self._interval],

@@ -78,14 +77,14 @@ potentialRange = self.ranges[interval],

if (interval === self._interval) {
return self.ranges[interval];
return self.get();
}
if (!self.config.ignoreToday && oldRange.contains(today)) {
start = moment(today).startOf(interval);
end = moment(today).endOf(interval);
start = self.m(today).startOf(interval);
end = self.m(today).endOf(interval);
} else if (oldRange.contains(potentialRange.start) || oldRange.contains(potentialRange.end)) {
start = moment(potentialRange.start);
end = moment(potentialRange.end);
start = self.m(potentialRange.start);
end = self.m(potentialRange.end);
} else {
start = moment(oldRange.start).startOf(interval);
end = moment(oldRange.start).endOf(interval);
start = self.m(oldRange.start).startOf(interval);
end = self.m(oldRange.start).endOf(interval);
}

@@ -99,4 +98,4 @@

value = self.get(),
start = moment(value.range.end).add(1, 'ms'),
end = moment(start).endOf(value.interval);
start = self.m(value.range.end).add(1, 'ms'),
end = self.m(start).endOf(value.interval);

@@ -109,4 +108,4 @@ return change(self, start, end);

value = self.get(),
end = moment(value.range.start).add(-1, 'ms'),
start = moment(end).startOf(value.interval);
end = self.m(value.range.start).add(-1, 'ms'),
start = self.m(end).startOf(value.interval);

@@ -117,18 +116,21 @@ return change(self, start, end);

today: function () {
var interval = this._interval;
var self = this;
var interval = self._interval;
return change(this, moment().startOf(interval), moment().endOf(interval));
return change(self, self.m().startOf(interval), self.m().endOf(interval));
},
go: function (date) {
var interval = this._interval;
var self = this;
var interval = self._interval;
return change(this, moment(date).startOf(interval), moment(date).endOf(interval));
return change(self, self.m(date).startOf(interval), self.m(date).endOf(interval));
},
get: function () {
var interval = this._interval;
var self = this;
var interval = self._interval;
return {
interval: interval,
range: this.ranges[interval]
range: self.ranges[interval]
};

@@ -135,0 +137,0 @@ }

{
"name": "ambitus",
"version": "0.3.0",
"version": "0.4.0",
"description": "A calendar interval controller",

@@ -5,0 +5,0 @@ "main": "ambitus.js",

@@ -33,8 +33,7 @@ Ambitus

// First day of week (TODO)
// weekstart: 0,
// Custom moment getter
moment: function (input) {
return moment(input).utc().locale('da');
},
// Use UTC time (TODO)
// utc: false,
// Callback that is fired before the internal state changes

@@ -65,3 +64,35 @@ // Return false to block the change

All methods return the same state object that get passed into the `onBeforeChange` and `onChange` event handlers:
```javascript
{
interval: 'week', // Possible values: ['day', 'week', 'month']
range: moment.range(start, end) // Range desribing the current interval start end end date
}
```
Locales and Timezones
---------------------
Ambitus will default to use the globally configured moment constructors. So if you already have your moment constructor set up, Ambitus will do what you want.
If you need Ambitus to use a different time zone or locale than your globally defined one, you can pass in the `moment` configuration option. This should be a function that takes a normal moment input and returns your preferred moment instance.
Examples
~~~~~~~~
**UTC**: `function (input) { return moment(input).utc(); }`
**Danish locale**: `function (input) { return moment(input).locale('da'); }`
**UTC and German locale**: `function (input) { return moment(input).utc().locale('de'); }`
Setting the locale like in these examples requires that the locale you want to switch to is already installed. Please refer to the [moment-timezone documentation](http://momentjs.com/docs/#/i18n/instance-locale/)
Week start and Week number
--------------------------
The first day of a week and week numbering can be configured through the `moment.locale` settings. See the section above
Dependencies

@@ -72,11 +103,4 @@ ------------

Todo
----
* Config: UTC dates
* Config: First day of week
License
-------
MIT
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