Ticket #13606: 0001-Implement-functions-to-get-long-short-day-name-and-s.patch

File 0001-Implement-functions-to-get-long-short-day-name-and-s.patch, 3.3 KB (added by akshay, 7 years ago)
  • headers/os/locale/DateFormat.h

    From 658253a9b9664a2f64b3647dd5a6248b2a1fb706 Mon Sep 17 00:00:00 2001
    From: Akshay Agarwal <agarwal.akshay.akshay8@gmail.com>
    Date: Sun, 16 Jul 2017 08:07:05 +0530
    Subject: [PATCH] Implement functions to get long/short day name and short
     month name.
    
    ---
     headers/os/locale/DateFormat.h |  3 ++
     src/kits/locale/DateFormat.cpp | 87 ++++++++++++++++++++++++++++++++++++++++++
     2 files changed, 90 insertions(+)
    
    diff --git a/headers/os/locale/DateFormat.h b/headers/os/locale/DateFormat.h
    index 76a0567..039f37d 100644
    a b public:  
    7272
    7373            status_t            GetStartOfWeek(BWeekday* weekday) const;
    7474            status_t            GetMonthName(int month, BString& outName);
     75            status_t            GetShortMonthName(int month, BString& outName);
     76            status_t            GetDayName(int day, BString& outName);
     77            status_t            GetShortDayName(int day, BString& outName);
    7578
    7679                                // parsing
    7780
  • src/kits/locale/DateFormat.cpp

    diff --git a/src/kits/locale/DateFormat.cpp b/src/kits/locale/DateFormat.cpp
    index 2a386a5..d3b5810 100644
    a b BDateFormat::GetMonthName(int month, BString& outName)  
    327327
    328328
    329329status_t
     330BDateFormat::GetShortMonthName(int month, BString& outName)
     331{
     332    DateFormat* format = _CreateDateFormatter(B_LONG_DATE_FORMAT);
     333
     334    SimpleDateFormat* simpleFormat = dynamic_cast<SimpleDateFormat*>(format);
     335    if (simpleFormat == NULL) {
     336        delete format;
     337        return B_ERROR;
     338    }
     339
     340    const DateFormatSymbols* symbols = simpleFormat->getDateFormatSymbols();
     341
     342    int32_t count;
     343    const UnicodeString* names = symbols->getShortMonths(count);
     344
     345    if (month > count || month <= 0) {
     346        delete simpleFormat;
     347        return B_BAD_DATA;
     348    }
     349
     350    BStringByteSink stringConverter(&outName);
     351    names[month - 1].toUTF8(stringConverter);
     352
     353    delete simpleFormat;
     354    return B_OK;
     355}
     356
     357
     358status_t
     359BDateFormat::GetDayName(int day, BString& outName)
     360{
     361    DateFormat* format = _CreateDateFormatter(B_LONG_DATE_FORMAT);
     362
     363    SimpleDateFormat* simpleFormat = dynamic_cast<SimpleDateFormat*>(format);
     364    if (simpleFormat == NULL) {
     365        delete format;
     366        return B_ERROR;
     367    }
     368
     369    const DateFormatSymbols* symbols = simpleFormat->getDateFormatSymbols();
     370
     371    int32_t count;
     372    const UnicodeString* names = symbols->getWeekdays(count);
     373
     374    if (day >= count || day <= 0) {
     375        delete simpleFormat;
     376        return B_BAD_DATA;
     377    }
     378
     379    BStringByteSink stringConverter(&outName);
     380    names[day].toUTF8(stringConverter);
     381
     382    delete simpleFormat;
     383    return B_OK;
     384}
     385
     386
     387status_t
     388BDateFormat::GetShortDayName(int day, BString& outName)
     389{
     390    DateFormat* format = _CreateDateFormatter(B_LONG_DATE_FORMAT);
     391
     392    SimpleDateFormat* simpleFormat = dynamic_cast<SimpleDateFormat*>(format);
     393    if (simpleFormat == NULL) {
     394        delete format;
     395        return B_ERROR;
     396    }
     397
     398    const DateFormatSymbols* symbols = simpleFormat->getDateFormatSymbols();
     399
     400    int32_t count;
     401    const UnicodeString* names = symbols->getShortWeekdays(count);
     402
     403    if (day >= count || day <= 0) {
     404        delete simpleFormat;
     405        return B_BAD_DATA;
     406    }
     407
     408    BStringByteSink stringConverter(&outName);
     409    names[day].toUTF8(stringConverter);
     410
     411    delete simpleFormat;
     412    return B_OK;
     413}
     414
     415
     416status_t
    330417BDateFormat::Parse(BString source, BDateFormatStyle style, BDate& output)
    331418{
    332419    // FIXME currently this parses a date in any timezone (or the local one if