Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/common/rivetsExtra.es6
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,10 @@ rv.binders.slider = {
}
}

rv.binders.datepicker_mindate = {
routine: (el, value) => $(el).datepicker('option', 'minDate', value)
}

/* trun input element in jquery-ui-datepicker */
rv.binders.datepicker = {
priority: 94,
Expand Down
17 changes: 17 additions & 0 deletions src/trade/tradeDialog.es6
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ function validateMinute({ hour, minute, today_times, selected_date_unix }) {
return (hour > open_hour && hour < close_hour) || hour < close_hour || hour > open_hour;
}

function hasIntradayUnit(duration_unit_array) {
return duration_unit_array.some(unit => ['minutes', 'hours'].indexOf(unit) !== -1);
}

function init_state(available,root, dialog, symbol, contracts_for_spot) {
var state = {
duration: {
Expand Down Expand Up @@ -286,6 +290,7 @@ function init_state(available,root, dialog, symbol, contracts_for_spot) {
value_hour: moment.utc().format('HH:mm'), /* now utc in hh:mm format */
value: 0, /* epoch value of date+hour */
today_times: { open: '--', close: '--', disabled: false }, /* trading times for today */
min_date: 0,
onHourShow: function(hour) { /* for timepicker */
return validateHour({
hour,
Expand Down Expand Up @@ -580,19 +585,31 @@ function init_state(available,root, dialog, symbol, contracts_for_spot) {
/* contracts that are more not today must end at the market close time */
const { value_date } = state.date_expiry;
const is_today = !moment.utc(value_date).isAfter(moment.utc(), 'day');
const is_daily_contracts = state.duration_unit.array[0] && !hasIntradayUnit(state.duration_unit.array);

if (!is_today) {
state.date_expiry.today_times.disabled = true;
trading_times_for(value_date, state.proposal.symbol)
.then(function(times){
if (state.duration.value === 'Duration') {
state.date_expiry.value_date = moment.utc().format('YYYY-MM-DD');
}

const value_hour = times.close !== '--' ? times.close : '23:59:59';
state.date_expiry.min_date = is_daily_contracts ? 1 : 0;
state.date_expiry.value_hour = moment.utc(value_hour, 'HH:mm:ss').format('HH:mm');
state.date_expiry.value = moment.utc(state.date_expiry.value_date + ' ' + value_hour).unix();
state.barriers.update();

debounce(state.date_expiry.value, state.proposal.onchange);
});
}
else {
if (date_or_hour !== state.date_expiry.value_hour) { state.date_expiry.update_times(); }
if (is_daily_contracts) {
state.date_expiry.min_date = 1;
state.date_expiry.value_date = moment.utc().add(1, 'days').format('YYYY-MM-DD');
}
state.date_expiry.value = moment.utc(state.date_expiry.value_date + ' ' + state.date_expiry.value_hour).unix();
state.barriers.update();
debounce(state.date_expiry.value, state.proposal.onchange);
Expand Down
1 change: 1 addition & 0 deletions src/trade/tradeDialog.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
<li rv-show="duration.value | eq 'End Time' ">
<input type="text" class="date-expiry-date" readonly
numberOfMonths="1" marginTop="0px" marginLeft="-100px"
rv-datepicker_mindate="date_expiry.min_date"
rv-datepicker="date_expiry.value_date | notify date_expiry.update" />
</li>
<li rv-if="duration.value | eq 'End Time' ">
Expand Down