<commit_before>package org.javarosa.xpath.expr;

import org.javarosa.core.model.condition.EvaluationContext;
import org.javarosa.core.model.instance.DataInstance;
import org.javarosa.xform.util.CalendarUtils;
import org.javarosa.xpath.XPathUnsupportedException;
import org.javarosa.xpath.parser.XPathSyntaxException;

import java.util.Date;

public class XPathFormatDateForCalendarFunc extends XPathFuncExpr {
    public static final String NAME = "format-date-for-calendar";
    private static final int EXPECTED_ARG_COUNT = 2;

    public XPathFormatDateForCalendarFunc() {
        name = NAME;
        expectedArgCount = EXPECTED_ARG_COUNT;
    }

    public XPathFormatDateForCalendarFunc(XPathExpression[] args) throws XPathSyntaxException {
        super(NAME, args, EXPECTED_ARG_COUNT, true);
    }

    @Override
    public Object evalBody(DataInstance model, EvaluationContext evalContext) {
        return formatDateForCalendar(evaluatedArgs[0], evaluatedArgs[1]);
    }

    /**
     * Given a date and format, return that date as a string formatted for that calendar
     * Accepted calendars are Ethiopian and Nepali
     *
     * @param dateObject The Object (String, Date, or XPath) to be evaluated into a date
     * @param format     The calendar format (nepali or ethiopian)
     */
    private static String formatDateForCalendar(Object dateObject, Object format) {

        Date date = FunctionUtils.expandDateSafe(dateObject);
        if (date == null) {
            return "";
        }
        if ("ethiopian".equals(format)) {
            return CalendarUtils.ConvertToEthiopian(date);
        } else if ("nepali".equals(format)) {
            return CalendarUtils.convertToNepaliString(date);
        } else {
            throw new XPathUnsupportedException("Unsupported calendar type: " + format);
        }
    }

    @Override
    public String getDocumentation() {
        return "?";
    }
}<commit_msg>add format-date-for-calendar docs<commit_after>package org.javarosa.xpath.expr;

import org.javarosa.core.model.condition.EvaluationContext;
import org.javarosa.core.model.instance.DataInstance;
import org.javarosa.xform.util.CalendarUtils;
import org.javarosa.xpath.XPathUnsupportedException;
import org.javarosa.xpath.parser.XPathSyntaxException;

import java.util.Date;

public class XPathFormatDateForCalendarFunc extends XPathFuncExpr {
    public static final String NAME = "format-date-for-calendar";
    private static final int EXPECTED_ARG_COUNT = 2;

    public XPathFormatDateForCalendarFunc() {
        name = NAME;
        expectedArgCount = EXPECTED_ARG_COUNT;
    }

    public XPathFormatDateForCalendarFunc(XPathExpression[] args) throws XPathSyntaxException {
        super(NAME, args, EXPECTED_ARG_COUNT, true);
    }

    @Override
    public Object evalBody(DataInstance model, EvaluationContext evalContext) {
        return formatDateForCalendar(evaluatedArgs[0], evaluatedArgs[1]);
    }

    /**
     * Given a date and format, return that date as a string formatted for that calendar
     * Accepted calendars are Ethiopian and Nepali
     *
     * @param dateObject The Object (String, Date, or XPath) to be evaluated into a date
     * @param format     The calendar format (nepali or ethiopian)
     */
    private static String formatDateForCalendar(Object dateObject, Object format) {

        Date date = FunctionUtils.expandDateSafe(dateObject);
        if (date == null) {
            return "";
        }
        if ("ethiopian".equals(format)) {
            return CalendarUtils.ConvertToEthiopian(date);
        } else if ("nepali".equals(format)) {
            return CalendarUtils.convertToNepaliString(date);
        } else {
            throw new XPathUnsupportedException("Unsupported calendar type: " + format);
        }
    }

    @Override
    public String getDocumentation() {
        return getDocHeader()
                + "Behavior: Converts a Gregorian formatted date to a different calendar format. \n"
                + "Return: a String of the input date formatted for the specified calendar. \n"
                + "Arguments: The date to be converted and the format to convert to "
                    + "(currently 'ethiopian' or 'nepali'). \n"
                + "Example: format-date-for-calendar('19070-01-1', 'nepali')";
    }
}
{'fraction_non_alphanumeric': 0.08583988894030542, 'fraction_numerical': 0.003239241092086997, 'mean_word_length': 3.0860113421550093, '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': '986261', 'n_tokens_mistral': 1221, 'n_tokens_neox': 1179, 'n_words': 316}