-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtenor-calculator.min.js
18 lines (17 loc) · 3.42 KB
/
tenor-calculator.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/**
* Copyright © 2019 The Derivatives Service Bureau Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
"use strict";(function(){function b(d,e,g){function a(j,i){if(!e[j]){if(!d[j]){var f="function"==typeof require&&require;if(!i&&f)return f(j,!0);if(h)return h(j,!0);var c=new Error("Cannot find module '"+j+"'");throw c.code="MODULE_NOT_FOUND",c}var k=e[j]={exports:{}};d[j][0].call(k.exports,function(b){var c=d[j][1][b];return a(c||b)},k,k.exports,b,d,e,g)}return e[j].exports}for(var h="function"==typeof require&&require,c=0;c<g.length;c++)a(g[c]);return a}return b})()({1:[function(a,b,c){'use strict';function d(a,b){var c=new Date(Date.UTC(b.getFullYear(),b.getMonth(),0)),d=b.getDate()-a.getDate(),e=b.getMonth()-a.getMonth()-(0>d?1:0),f=b.getFullYear()-a.getFullYear(),g=d+(0>d?c.getDate():0),h=e+(0>e?12:0),i=f-(0>e?1:0),j=15>g?0:1;return 12*i+h+j}function e(a,b,c){var e=Math.round;for(;999<a.value;)switch(a.unit){case"DAYS":a={value:e(a.value/7),unit:"WEEK",basis:"Overflow Weeks"};break;case"WEEK":a={value:d(b,c),unit:"MNTH",basis:"Overflow Months"};break;case"MNTH":a={value:e(a.value/12),unit:"YEAR",basis:"Overflow Years"};break;default:throw{name:"InvalidException",message:"Invalid Input: Input Dates exceed maximum input range of 999 Years."};}return a}function f(a,b){return"".concat(a.getMonth(),"-").concat(a.getDate())==="".concat(b.getMonth(),"-").concat(b.getDate())?{value:b.getFullYear()-a.getFullYear(),unit:"YEAR",basis:"Whole Years"}:a.getDate()===b.getDate()?{value:12*b.getFullYear()+b.getMonth()+1-(12*a.getFullYear()+a.getMonth()+1),unit:"MNTH",basis:"Whole Months"}:a.getDay()===b.getDay()?{value:(b.valueOf()-a.valueOf())/604800000,unit:"WEEK",basis:"Whole Weeks"}:{value:(b.valueOf()-a.valueOf())/86400000,unit:"DAYS",basis:"Whole Days"}}function g(a){var b=new Date("".concat(a,"T00:00:00.000Z"));if(isNaN(b)||!/^\d{4}-\d{2}-\d{2}$/.test(a))throw{name:"InvalidException",message:"Given date:\"".concat(a,"\" is not a valid Date of format YYYY-MM-DD")};return b}c.calculateTenor=function(a,b){var c=!!(2<arguments.length&&arguments[2]!==void 0)&&arguments[2],d=g(a),h=g(b);if(d>=h)throw{name:"InvalidException",message:"Invalid Input: Expiry Date must be greater than Effective Date."};if(d<g("1970-01-01"))throw{name:"InvalidException",message:"Illegal contract tenor."};var i=f(d,h);return 1e3>i.value?i:e(i,d,h)}},{}],2:[function(a){window&&(window.TenorCalculator=a("./tenor-calculator"))},{"./tenor-calculator":3}],3:[function(a,b,c){'use strict';c.calculateTenor=function(b,c){var d=2<arguments.length&&arguments[2]!==void 0?arguments[2]:"ESMA",e=!!(3<arguments.length&&arguments[3]!==void 0)&&arguments[3];if(!1!==e)throw{name:"InvalidException",message:"Given \"Adjusted Expiry Date\" is not yet supported."};switch(d){case"ESMA":return a("./tenor-calculator-esma").calculateTenor(b,c,e);}throw{name:"InvalidException",message:"Given \"Calculation Method\" is not yet supported."}}},{"./tenor-calculator-esma":1}]},{},[2]);