<commit_before>var ko = require('knockout');
var moment = require('moment');
require('pikaday');
require('pikaday-css');
var bootbox = require('bootbox');
var $ = require('jquery');
var $osf = require('js/osfHelpers');
var language = require('js/osfLanguage').registrations;

var template = require('raw!templates/registration-modal.html');
$(document).ready(function() {
    $('body').append(template);
});

var MAKE_PUBLIC = {
    value: 'immediate',
    message: 'Make registration public immediately'
};
var MAKE_EMBARGO = {
    value: 'embargo',
    message: 'Enter registration into embargo'
};
var today = new Date();
var todayMinimum = moment().add(2, 'days');
var todayMaximum = moment().add(4, 'years');

var RegistrationViewModel = function(confirm, prompts, validator) {

    var self = this;


    // Wire up the registration options.

    self.registrationOptions = [
        MAKE_PUBLIC,
        MAKE_EMBARGO
    ];
    self.registrationChoice = ko.observable(MAKE_PUBLIC.value);


    // Wire up the embargo option.

    self.requestingEmbargo = ko.computed(function() {
        var choice = self.registrationChoice();
        return choice === MAKE_EMBARGO.value;
    });
    self.requestingEmbargo.subscribe(function(requestingEmbargo) {
        self.showEmbargoDatePicker(requestingEmbargo);
    });
    self.showEmbargoDatePicker = ko.observable(false);
    self.pikaday = ko.observable(today);  // interacts with a datePicker from koHelpers.js


    // Wire up embargo validation.
    // ---------------------------
    // All registrations undergo an approval process before they're made public
    // (though details differ based on the type of registration). We try to
    // require (for some reason) that the embargo lasts at least as long as the
    // approval period. On the other hand, we don't want (for some reason)
    // embargos to be *too* long.

    self.embargoEndDate = ko.computed(function() {
        return moment(new Date(self.pikaday()));
    });

    self.embargoIsLongEnough = function (x, y, embargoLocalDateTime) {
        var min = getMinimumDate(embargoLocalDateTime),
            end = self.embargoEndDate();
        return end.isSameOrAfter(min) && end.isSameOrAfter(todayMinimum);
    };

    self.embargoIsShortEnough = function (x, y, embargoLocalDateTime) {
        var max = getMaximumDate(embargoLocalDateTime),
            end = self.embargoEndDate();
        return end.isSameOrBefore(max) && end.isSameOrBefore(todayMaximum);
    };

    var validation = [{
        validator: self.embargoIsLongEnough,
        message: 'Embargo end date must be at least three days in the future.'
    }, {
        validator: self.embargoIsShortEnough,
        message: 'Embargo end date must be less than four years in the future.'
    }];
    if(validator) {
        validation.unshift(validator);
    }
    self.pikaday.extend({
        validation: validation
    });


    // Wire up the modal actions.<commit_msg>Fix behavior on edge case to match test<commit_after>var ko = require('knockout');
var moment = require('moment');
require('pikaday');
require('pikaday-css');
var bootbox = require('bootbox');
var $ = require('jquery');
var $osf = require('js/osfHelpers');
var language = require('js/osfLanguage').registrations;

var template = require('raw!templates/registration-modal.html');
$(document).ready(function() {
    $('body').append(template);
});

var MAKE_PUBLIC = {
    value: 'immediate',
    message: 'Make registration public immediately'
};
var MAKE_EMBARGO = {
    value: 'embargo',
    message: 'Enter registration into embargo'
};
var today = new Date();
var todayMinimum = moment().add(2, 'days');
var todayMaximum = moment().add(4, 'years');

var RegistrationViewModel = function(confirm, prompts, validator) {

    var self = this;


    // Wire up the registration options.

    self.registrationOptions = [
        MAKE_PUBLIC,
        MAKE_EMBARGO
    ];
    self.registrationChoice = ko.observable(MAKE_PUBLIC.value);


    // Wire up the embargo option.

    self.requestingEmbargo = ko.computed(function() {
        var choice = self.registrationChoice();
        return choice === MAKE_EMBARGO.value;
    });
    self.requestingEmbargo.subscribe(function(requestingEmbargo) {
        self.showEmbargoDatePicker(requestingEmbargo);
    });
    self.showEmbargoDatePicker = ko.observable(false);
    self.pikaday = ko.observable(today);  // interacts with a datePicker from koHelpers.js


    // Wire up embargo validation.
    // ---------------------------
    // All registrations undergo an approval process before they're made public
    // (though details differ based on the type of registration). We try to
    // require (for some reason) that the embargo lasts at least as long as the
    // approval period. On the other hand, we don't want (for some reason)
    // embargos to be *too* long.

    self.embargoEndDate = ko.computed(function() {
        return moment(new Date(self.pikaday()));
    });

    self.embargoIsLongEnough = function (x, y, embargoLocalDateTime) {
        var min = getMinimumDate(embargoLocalDateTime),
            end = self.embargoEndDate();
        return end.isAfter(min) && end.isSameOrAfter(todayMinimum);
    };

    self.embargoIsShortEnough = function (x, y, embargoLocalDateTime) {
        var max = getMaximumDate(embargoLocalDateTime),
            end = self.embargoEndDate();
        return end.isBefore(max) && end.isSameOrBefore(todayMaximum);
    };

    var validation = [{
        validator: self.embargoIsLongEnough,
        message: 'Embargo end date must be at least three days in the future.'
    }, {
        validator: self.embargoIsShortEnough,
        message: 'Embargo end date must be less than four years in the future.'
    }];
    if(validator) {
        validation.unshift(validator);
    }
    self.pikaday.extend({
        validation: validation
    });


    // Wire up the modal actions.
{'fraction_non_alphanumeric': 0.1265993265993266, 'fraction_numerical': 0.0006734006734006734, 'mean_word_length': 3.102900552486188, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '116340', 'n_tokens_mistral': 1773, 'n_tokens_neox': 1670, 'n_words': 460}