12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481 |
- /*
- Copyright (c) 2007-2022 Bruce A Henderson
- All rights reserved.
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- * Neither the name of the copyright holder nor the
- names of its contributors may be used to endorse or promote products
- derived from this software without specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- #include <blitz.h>
- #include "boost/date_time/posix_time/posix_time.hpp"
- #include "boost/date_time/local_time/local_time.hpp"
- #include "boost/locale.hpp"
- #include <iostream>
- #include <algorithm>
- #include <vector>
- using namespace boost::posix_time;
- using namespace boost::gregorian;
- using namespace boost::local_time;
- class MaxTimeZone;
- extern "C" {
- date * bmx_datetime_localday();
- date * bmx_datetime_universalday();
- date * bmx_datetime_newdate(int year, int month, int day);
- void bmx_datetime_free(date * d);
- int bmx_datetime_before(date * myDate, date * yourDate);
- int bmx_datetime_after(date * myDate, date * yourDate);
- int bmx_datetime_equals(date * myDate, date * yourDate);
-
- int bmx_datetime_year(date * d);
- int bmx_datetime_month(date * d);
- int bmx_datetime_day(date * d);
- void bmx_datetime_ymd(date * dt, int * y, int * m, int * d);
-
- date * bmx_datetime_fromstring(BBString * d);
- date * bmx_datetime_fromundelimitedstring(BBString * d);
-
- int bmx_datetime_day_of_week(date * d);
- int bmx_datetime_day_of_year(date * d);
- date * bmx_datetime_end_of_month(date * d);
- int bmx_datetime_week_number(date * d);
- date * bmx_datetime_date_add(date * d, int duration);
- date * bmx_datetime_date_subtract(date * d, int duration);
- int bmx_datetime_date_subdate(date * d1, date * d2);
-
- date_period * bmx_datetime_period_datedate(date * d1, date * d2);
- date_period * bmx_datetime_period_withdays(date * d, int length);
- void bmx_datetime_period_shift(date_period * p, int length);
- void bmx_datetime_period_free(date_period * p);
-
- date * bmx_datetime_period_begin(date_period * p);
- date * bmx_datetime_period_last(date_period * p);
- date * bmx_datetime_period_end(date_period * p);
- int bmx_datetime_period_length(date_period * p);
-
- BBString * bmx_datetime_to_simple_string(date * d);
- BBString * bmx_datetime_period_to_simple_string(date_period * p);
- BBString * bmx_datetime_to_iso_string(date * d);
- BBString * bmx_datetime_to_iso_extended_string(date * d);
- BBString * bmx_datetime_to_string(date * d, std::locale * loc, date_facet * facet);
- BBString * bmx_datetime_period_to_string(date_period * p);
-
- int bmx_datetime_period_isnull(date_period * p);
- int bmx_datetime_period_containsdate(date_period * p, date * d);
- int bmx_datetime_period_contains(date_period * p1, date_period * p2);
- int bmx_datetime_period_intersects(date_period * p1, date_period * p2);
- date_period * bmx_datetime_period_intersection(date_period * p1, date_period * p2);
- int bmx_datetime_period_adjacent(date_period * p1, date_period * p2);
- int bmx_datetime_period_after(date_period * p, date * d);
- int bmx_datetime_period_before(date_period * p, date * d);
- date_period * bmx_datetime_period_merge(date_period * p1, date_period * p2);
- date_period * bmx_datetime_period_span(date_period * p1, date_period * p2);
- int bmx_datetime_period_isless(date_period * p1, date_period * p2);
- int bmx_datetime_period_isgreater(date_period * p1, date_period * p2);
- int bmx_datetime_period_isequal(date_period * p1, date_period * p2);
-
- void bmx_datetime_iter_forward(date_iterator * d);
- void bmx_datetime_iter_backward(date_iterator * d);
- day_iterator * bmx_datetime_dayiter(date * d, int offset);
- month_iterator * bmx_datetime_monthiter(date * d, int offset);
- year_iterator * bmx_datetime_yeariter(date * d, int offset);
- void bmx_datetime_iter_free(date_iterator * d);
- int bmx_datetime_iter_before(date_iterator * myDate, date * yourDate);
- int bmx_datetime_iter_after(date_iterator * myDate, date * yourDate);
- int bmx_datetime_iter_equals(date_iterator * myDate, date * yourDate);
- int bmx_datetime_iter_year(date_iterator * d);
- int bmx_datetime_iter_month(date_iterator * d);
- int bmx_datetime_iter_day(date_iterator * d);
- void bmx_datetime_iter_ymd(date_iterator * dt, int * y, int * m, int * d);
- int bmx_datetime_iter_day_of_week(date_iterator * d);
- int bmx_datetime_iter_day_of_year(date_iterator * d);
- date * bmx_datetime_iter_end_of_month(date_iterator * d);
- int bmx_datetime_iter_week_number(date_iterator * d);
- date * bmx_datetime_iter_date_add(date_iterator * d, int duration);
- date * bmx_datetime_iter_date_subtract(date_iterator * d, int duration);
- int bmx_datetime_iter_date_subdate(date_iterator * d1, date * d2);
- BBString * bmx_datetime_iter_to_simple_string(date_iterator * d);
- BBString * bmx_datetime_iter_to_iso_string(date_iterator * d);
- BBString * bmx_datetime_iter_to_iso_extended_string(date_iterator * d);
- BBString * bmx_datetime_iter_to_string(date_iterator * d, std::locale * loc, date_facet * facet);
- BBString * bmx_datetime_iter_asformat(date_iterator * d, BBString * format, std::locale * loc, date_facet * facet);
-
- time_duration * bmx_time_duration(int hours, int minutes, int seconds, int fraction);
- void bmx_time_duration_free(time_duration * d);
- time_duration * bmx_time_duration_new_hours(int value);
- time_duration * bmx_time_duration_new_minutes(int value);
- time_duration * bmx_time_duration_new_seconds(int value);
- time_duration * bmx_time_duration_new_milliseconds(int value);
- int bmx_time_duration_hours(time_duration * d);
- int bmx_time_duration_minutes(time_duration * d);
- int bmx_time_duration_seconds(time_duration * d);
- int bmx_time_duration_total_seconds(time_duration * d);
- int bmx_time_duration_total_milliseconds(time_duration * d);
- int bmx_time_duration_fractional_seconds(time_duration * d);
- int bmx_time_duration_is_negative(time_duration * d);
- time_duration * bmx_time_duration_invert_sign(time_duration * d);
- BBString * bmx_time_duration_to_string(time_duration * d);
- BBString * bmx_time_duration_to_iso_string(time_duration * d);
- time_duration * bmx_time_duration_add(time_duration * d1, time_duration * d2);
- time_duration * bmx_time_duration_subtract(time_duration * d1, time_duration * d2);
- time_duration * bmx_time_duration_divide(time_duration * d1, int value);
- time_duration * bmx_time_duration_multiply(time_duration * d1, int value);
- int bmx_time_duration_less(time_duration * d1, time_duration * d2);
- int bmx_time_duration_greater(time_duration * d1, time_duration * d2);
- int bmx_time_duration_equal(time_duration * d1, time_duration * d2);
- BBString * bmx_time_duration_asformat(time_duration * d, BBString * format, std::locale * loc, time_facet * facet);
- int bmx_time_ticks_per_second();
- int bmx_time_num_fractional_digits();
-
- ptime * bmx_ptime_new(date * d, time_duration * t);
- void bmx_ptime_free(ptime * p);
- ptime * bmx_ptime_local_new();
- ptime * bmx_ptime_universal_new();
- ptime * bmx_ptime_local_microsecond_new();
- ptime * bmx_ptime_universal_microsecond_new();
- date * bmx_ptime_date(ptime * p);
- time_duration * bmx_ptime_time_of_day(ptime * p);
- BBString * bmx_ptime_to_simple_string(ptime * p);
- BBString * bmx_ptime_to_iso_string(ptime * p);
- BBString * bmx_ptime_to_iso_extended_string(ptime * p);
- BBString * bmx_ptime_to_string(ptime * p, std::locale * loc, time_facet * facet);
- ptime * bmx_ptime_add_days(ptime * p, int d);
- ptime * bmx_ptime_subtract_days(ptime * p, int d);
- ptime * bmx_ptime_add_duration(ptime * p, time_duration * d);
- ptime * bmx_ptime_subtract_duration(ptime * p, time_duration * d);
- time_duration * bmx_ptime_subtract(ptime * p1, ptime * p2);
- int bmx_ptime_less(ptime * p1, ptime * p2);
- int bmx_ptime_greater(ptime * p1, ptime * p2);
- int bmx_ptime_equal(ptime * p1, ptime * p2);
- ptime * bmx_ptime_from_time_t(std::time_t * t);
- BBString * bmx_ptime_asformat(ptime * p, BBString * f, std::locale * loc, time_facet * facet);
- partial_date * bmx_partial_date_new(int day, int month);
- date * bmx_partial_date_get_date(partial_date * p, int year);
- void bmx_partial_date_free(partial_date * p);
- last_day_of_the_week_in_month * bmx_last_day_of_week_in_month_new(int weekday, int month);
- date * bmx_last_day_of_week_in_month_get_date(last_day_of_the_week_in_month * p, int year);
- void bmx_last_day_of_week_in_month_free(last_day_of_the_week_in_month * p);
- first_day_of_the_week_in_month * bmx_first_day_of_week_in_month_new(int weekday, int month);
- date * bmx_first_day_of_week_in_month_get_date(first_day_of_the_week_in_month * p, int year);
- void bmx_first_day_of_week_in_month_free(first_day_of_the_week_in_month * p);
-
- BBString * bmx_weekday_to_string(int wd);
-
- date_facet * bmx_datefacet_new();
- BBString * bmx_date_asformat(date * d, BBString * format, std::locale * loc, date_facet * facet);
- std::locale * bmx_locale_new(date_facet * d, boost::locale::generator * gen, BBString * loc);
- time_facet * bmx_timefacet_new();
-
- void bmx_char_free(char * s);
-
- time_period * bmx_time_period_timetime(ptime * p1, ptime * p2);
- time_period * bmx_time_period_withduration(ptime * p, time_duration * d);
- void bmx_time_period_shift(time_period * tp, time_duration * d);
- void bmx_time_period_free(time_period * tp);
- ptime * bmx_time_period_begin(time_period * tp);
- ptime * bmx_time_period_last(time_period * tp);
- ptime * bmx_time_period_end(time_period * tp);
- time_duration * bmx_time_period_length(time_period * tp);
- int bmx_time_period_is_null(time_period * tp);
- int bmx_time_period_contains(time_period * tp, ptime * t);
- int bmx_time_period_containsPeriod(time_period * tp1, time_period * tp2);
- int bmx_time_period_intersects(time_period * tp1, time_period * tp2);
- time_period * bmx_time_period_intersection(time_period * tp1, time_period * tp2);
- time_period * bmx_time_period_merge(time_period * tp1, time_period * tp2);
- time_period * bmx_time_period_span(time_period * tp1, time_period * tp2);
- int bmx_time_period_isless(time_period * tp1, time_period * tp2);
- int bmx_time_period_isgreater(time_period * tp1, time_period * tp2);
- int bmx_time_period_isequal(time_period * tp1, time_period * tp2);
- BBString * bmx_time_period_to_simple_string(time_period * tp);
-
- MaxTimeZone * bmx_posix_time_zone(BBString * id);
- BBString * bmx_time_zone_dst_zone_abbrev(MaxTimeZone * tz);
- BBString * bmx_time_zone_std_zone_abbrev(MaxTimeZone * tz);
- BBString * bmx_time_zone_dst_zone_name(MaxTimeZone * tz);
- BBString * bmx_time_zone_std_zone_name(MaxTimeZone * tz);
- int bmx_time_zone_has_dst(MaxTimeZone * tz);
- ptime * bmx_time_zone_dst_local_start_time(MaxTimeZone * tz, int year);
- ptime * bmx_time_zone_dst_local_end_time(MaxTimeZone * tz, int year);
- time_duration * bmx_time_zone_base_utc_offset(MaxTimeZone * tz);
- time_duration * bmx_time_zone_dst_offset(MaxTimeZone * tz);
- BBString * bmx_time_zone_to_posix_string(MaxTimeZone * tz);
- void bmx_time_zone_free(MaxTimeZone * tz);
-
- tz_database * bmx_tz_database();
- tz_database * bmx_tz_load_from_file(BBString * filename);
- MaxTimeZone * bmx_tz_time_zone_from_region(tz_database * db, BBString * id);
- void bmx_tz_database_free(tz_database * db);
- void bmx_tz_database_add_record(tz_database * db, BBString * id, MaxTimeZone * tz);
- BBArray * bmx_tz_database_region_list(tz_database * db);
-
- local_date_time * bmx_local_date_time_new_sec_clock(MaxTimeZone * tz);
- local_date_time * bmx_local_date_time_new_time(ptime * p, MaxTimeZone * tz);
-
- BBString * bmx_month_to_string(int m);
- void bmx_date_facet_format(date_facet * f, BBString * fmt);
- void bmx_date_facet_set_iso_format(date_facet * f);
- void bmx_date_facet_set_iso_extended_format(date_facet * f);
-
- void bmx_date_facet_short_month_names(date_facet * f, BBArray * names);
- void bmx_date_facet_long_month_names(date_facet * f, BBArray * names);
- void bmx_date_facet_short_weekday_names(date_facet * f, BBArray * names);
- void bmx_date_facet_long_weekday_names(date_facet * f, BBArray * names);
- void bmx_date_facet_month_format(date_facet * f, BBString * fmt);
- void bmx_date_facet_weekday_format(date_facet * f, BBString * fmt);
- void bmx_time_facet_format(time_facet * f, BBString * fmt);
- void bmx_time_facet_set_iso_format(time_facet * f);
- void bmx_time_facet_set_iso_extended_format(time_facet * f);
- void bmx_time_facet_month_format(time_facet * f, BBString * fmt);
- void bmx_time_facet_weekday_format(time_facet * f, BBString * fmt);
- void bmx_time_facet_time_duration_format(time_facet * f, BBString * fmt);
-
- nth_day_of_the_week_in_month * bmx_nth_day_of_week_in_month_new(int nth, int weekday, int month);
- date * bmx_nth_day_of_week_in_month_get_date(nth_day_of_the_week_in_month * p, int year);
- void bmx_nth_day_of_week_in_month_free(nth_day_of_the_week_in_month * p);
- first_day_of_the_week_after * bmx_first_day_of_week_after_new(int weekday);
- date * bmx_first_day_of_week_after_get_date(first_day_of_the_week_after * p, date * d);
- void bmx_first_day_of_week_after_free(first_day_of_the_week_after * p);
- first_day_of_the_week_before * bmx_first_day_of_week_before_new(int weekday);
- date * bmx_first_day_of_week_before_get_date(first_day_of_the_week_before * p, date * d);
- void bmx_first_day_of_week_before_free(first_day_of_the_week_before * p);
- int bmx_days_until_weekday(date * d, int weekday);
- int bmx_days_before_weekday(date * d, int weekday);
- date * bmx_next_weekday(date * d, int weekday);
- date * bmx_previous_weekday(date * d, int weekday);
-
- MaxTimeZone * bmx_local_date_time_zone(local_date_time * ldt);
- int bmx_local_date_time_is_dst(local_date_time * ldt);
- ptime * bmx_local_date_time_utc_time(local_date_time * ldt);
- ptime * bmx_local_date_time_local_time(local_date_time * ldt);
-
- BBString * bmx_local_date_time_to_string(local_date_time * ldt);
- int bmx_local_date_time_less(local_date_time * ldt1, local_date_time * ldt2);
- int bmx_local_date_time_greater(local_date_time * ldt1, local_date_time * ldt2);
- int bmx_local_date_time_equal(local_date_time * ldt1, local_date_time * ldt2);
-
- local_date_time * bmx_local_date_time_add_days(local_date_time * ldt, int value);
- local_date_time * bmx_local_date_time_add_months(local_date_time * ldt, int value);
- local_date_time * bmx_local_date_time_add_years(local_date_time * ldt, int value);
- local_date_time * bmx_local_date_time_subtract_days(local_date_time * ldt, int value);
- local_date_time * bmx_local_date_time_subtract_months(local_date_time * ldt, int value);
- local_date_time * bmx_local_date_time_subtract_years(local_date_time * ldt, int value);
- local_date_time * bmx_local_date_time_add_duration(local_date_time * ldt, time_duration * td);
- local_date_time * bmx_local_date_time_subtract_duration(local_date_time * ldt, time_duration * td);
- void bmx_local_date_time_free(local_date_time * ldt);
-
- local_time_period * bmx_local_time_period_new(local_date_time * ldt1, local_date_time * ldt2);
- local_time_period * bmx_local_time_period_new_duration(local_date_time * ldt, time_duration * d);
- void bmx_local_time_period_free(local_time_period * ldt);
- local_date_time * bmx_local_time_period_begin(local_time_period * ldt);
- local_date_time * bmx_local_time_period_last(local_time_period * ldt);
- local_date_time * bmx_local_time_period_end(local_time_period * ldt);
- time_duration * bmx_local_time_period_length(local_time_period * ldt);
- int bmx_local_time_period_is_null(local_time_period * ldt);
- int bmx_local_time_period_contains_time(local_time_period * ldt, local_date_time * t);
- int bmx_local_time_period_contains(local_time_period * ldt1, local_time_period * ldt2);
- int bmx_local_time_period_intersects(local_time_period * ldt1, local_time_period * ldt2);
- local_time_period * bmx_local_time_period_intersection(local_time_period * ldt1, local_time_period * ldt2);
- local_time_period * bmx_local_time_period_merge(local_time_period * ldt1, local_time_period * ldt2);
- local_time_period * bmx_local_time_period_span(local_time_period * ldt1, local_time_period * ldt2);
- void bmx_local_time_period_shift(local_time_period * ldt, time_duration * d);
- int bmx_local_time_period_less(local_time_period * ldt1, local_time_period * ldt2);
- int bmx_local_time_period_greater(local_time_period * ldt1, local_time_period * ldt2);
- int bmx_local_time_period_equal(local_time_period * ldt1, local_time_period * ldt2);
-
- int bmx_end_of_month_day(int y, int m);
- }
- //static std::stringstream outputStringStream;
- class MaxTimeZone
- {
- public:
- MaxTimeZone(time_zone_ptr tz) : timeZone(tz) {}
- time_zone_ptr timeZone;
- };
- BBString * bmx_BBString_from_stream(std::stringstream & stream) {
- BBString * s = bbStringFromUTF8String((const unsigned char*)stream.str().c_str());
- // outputStringStream.str("");
- return s;
- }
- char * bmx_cstr_from_stream(std::stringstream & stream) {
- char * s = strdup(stream.str().c_str());
- // outputStringStream.str("");
- return s;
- }
- date * bmx_datetime_newdate(int year, int month, int day) {
- try {
- return new date(year, month, day);
- } catch (...) {
- return 0;
- }
- }
- void bmx_datetime_free(date * d) {
- delete d;
- }
- date * bmx_datetime_localday() {
- return new date(day_clock::local_day());
- }
- date * bmx_datetime_universalday() {
- return new date(day_clock::universal_day());
- }
- int bmx_datetime_before(date * myDate, date * yourDate) {
- return *myDate < *yourDate;
- }
- int bmx_datetime_after(date * myDate, date * yourDate) {
- return *myDate > *yourDate;
- }
- int bmx_datetime_equals(date * myDate, date * yourDate) {
- return *myDate == *yourDate;
- }
- int bmx_datetime_year(date * d) {
- return (int)d->year();
- }
- int bmx_datetime_month(date * d) {
- return (int)d->month();
- }
- int bmx_datetime_day(date * d) {
- return (int)d->day();
- }
- void bmx_datetime_ymd(date * dt, int * y, int * m, int * d) {
- date::ymd_type ymd = dt->year_month_day();
- *y = ymd.year;
- *m = ymd.month;
- *d = ymd.day;
- }
- date * bmx_datetime_fromstring(BBString * dt) {
- char * d = (char*)bbStringToUTF8String(dt);
- try {
- date * _date = new date(from_string(std::string(d)));
- bbMemFree(d);
- return _date;
- } catch (...) {
- bbMemFree(d);
- return 0;
- }
- }
- date * bmx_datetime_fromundelimitedstring(BBString * dt) {
- char * d = (char*)bbStringToUTF8String(dt);
- try {
- date * _date = new date(from_undelimited_string(std::string(d)));
- bbMemFree(d);
- return _date;
- } catch (...) {
- bbMemFree(d);
- return 0;
- }
- }
- int bmx_datetime_day_of_week(date * d) {
- return (int)d->day_of_week();
- }
- int bmx_datetime_day_of_year(date * d) {
- return (int)d->day_of_year();
- }
- date * bmx_datetime_end_of_month(date * d) {
- return new date(d->end_of_month());
- }
- int bmx_datetime_week_number(date * d) {
- return (int)d->week_number();
- }
- date * bmx_datetime_date_add(date * d, int duration) {
- return new date(*d + date_duration(duration));
- }
- date * bmx_datetime_date_subtract(date * d, int duration) {
- return new date(*d - date_duration(duration));
- }
- int bmx_datetime_date_subdate(date * d1, date * d2) {
- date_duration duration = *d1 - *d2;
- return duration.days();
- }
- date_period * bmx_datetime_period_datedate(date * d1, date * d2) {
- return new date_period(*d1, *d2);
- }
- date_period * bmx_datetime_period_withdays(date * d, int length) {
- return new date_period(*d, days(length));
- }
- void bmx_datetime_period_shift(date_period * p, int length) {
- p->shift(days(length));
- }
- void bmx_datetime_period_free(date_period * p) {
- delete p;
- }
- date * bmx_datetime_period_begin(date_period * p) {
- return new date(p->begin());
- }
- date * bmx_datetime_period_last(date_period * p) {
- return new date(p->last());
- }
- date * bmx_datetime_period_end(date_period * p) {
- return new date(p->end());
- }
- int bmx_datetime_period_length(date_period * p) {
- return p->length().days();
- }
- BBString * bmx_datetime_to_simple_string(date * d) {
- return bbStringFromUTF8String((const unsigned char*)to_simple_string(*d).c_str());
- }
- BBString * bmx_datetime_to_string(date * d, std::locale * loc, date_facet * facet) {
- std::stringstream outputStringStream;
- outputStringStream.imbue(std::locale(*loc, facet));
- outputStringStream << *d;
- BBString * ret = bmx_BBString_from_stream(outputStringStream);
- return ret;
- }
- BBString * bmx_datetime_period_to_simple_string(date_period * p) {
- return bbStringFromUTF8String((const unsigned char*)to_simple_string(*p).c_str());
- }
- BBString * bmx_datetime_to_iso_string(date * d) {
- return bbStringFromUTF8String((const unsigned char*)to_iso_string(*d).c_str());
- }
- BBString * bmx_datetime_to_iso_extended_string(date * d) {
- return bbStringFromUTF8String((const unsigned char*)to_iso_extended_string(*d).c_str());
- }
- BBString * bmx_datetime_period_to_string(date_period * p) {
- std::stringstream outputStringStream;
- outputStringStream << *p;
- return bmx_BBString_from_stream(outputStringStream);
- }
- int bmx_datetime_period_isnull(date_period * p) {
- return p->is_null();
- }
- int bmx_datetime_period_containsdate(date_period * p, date * d) {
- return p->contains(*d);
- }
- int bmx_datetime_period_contains(date_period * p1, date_period * p2) {
- return p1->contains(*p2);
- }
- int bmx_datetime_period_intersects(date_period * p1, date_period * p2) {
- return p1->intersects(*p2);
- }
- date_period * bmx_datetime_period_intersection(date_period * p1, date_period * p2) {
- return new date_period(p1->intersection(*p2));
- }
- int bmx_datetime_period_adjacent(date_period * p1, date_period * p2) {
- return p1->is_adjacent(*p2);
- }
- int bmx_datetime_period_after(date_period * p, date * d) {
- return p->is_after(*d);
- }
- int bmx_datetime_period_before(date_period * p, date * d) {
- return p->is_before(*d);
- }
- date_period * bmx_datetime_period_merge(date_period * p1, date_period * p2) {
- return new date_period(p1->merge(*p2));
- }
- date_period * bmx_datetime_period_span(date_period * p1, date_period * p2) {
- return new date_period(p1->span(*p2));
- }
- int bmx_datetime_period_isless(date_period * p1, date_period * p2) {
- return *p1 < *p2;
- }
- int bmx_datetime_period_isgreater(date_period * p1, date_period * p2) {
- return *p1 > *p2;
- }
- int bmx_datetime_period_isequal(date_period * p1, date_period * p2) {
- return *p1 == *p2;
- }
- day_iterator * bmx_datetime_dayiter(date * d, int offset) {
- return new day_iterator(*d, offset);
- }
- month_iterator * bmx_datetime_monthiter(date * d, int offset) {
- return new month_iterator(*d, offset);
- }
- year_iterator * bmx_datetime_yeariter(date * d, int offset) {
- return new year_iterator(*d, offset);
- }
- void bmx_datetime_iter_free(date_iterator * d) {
- delete d;
- }
- void bmx_datetime_iter_forward(date_iterator * d) {
- ++*d;
- }
- void bmx_datetime_iter_backward(date_iterator * d) {
- --*d;
- }
- int bmx_datetime_iter_before(date_iterator * myDate, date * yourDate) {
- return (*(day_iterator *)myDate) < *yourDate;
- }
- int bmx_datetime_iter_after(date_iterator * myDate, date * yourDate) {
- return (*(day_iterator *)myDate) > *yourDate;
- }
- int bmx_datetime_iter_equals(date_iterator * myDate, date * yourDate) {
- return (*(day_iterator *)myDate) == *yourDate;
- }
- int bmx_datetime_iter_year(date_iterator * d) {
- return (int)(*(day_iterator *)d)->year();
- }
- int bmx_datetime_iter_month(date_iterator * d) {
- return (int)(*(day_iterator *)d)->month();
- }
- int bmx_datetime_iter_day(date_iterator * d) {
- return (int)(*(day_iterator *)d)->day();
- }
- void bmx_datetime_iter_ymd(date_iterator * dt, int * y, int * m, int * d) {
- date::ymd_type ymd = (*(day_iterator *)dt)->year_month_day();
- *y = ymd.year;
- *m = ymd.month;
- *d = ymd.day;
- }
- int bmx_datetime_iter_day_of_week(date_iterator * d) {
- return (int)(*(day_iterator *)d)->day_of_week();
- }
- int bmx_datetime_iter_day_of_year(date_iterator * d) {
- return (int)(*(day_iterator *)d)->day_of_year();
- }
- date * bmx_datetime_iter_end_of_month(date_iterator * d) {
- return new date((*(day_iterator *)d)->end_of_month());
- }
- int bmx_datetime_iter_week_number(date_iterator * d) {
- return (int)(*(day_iterator *)d)->week_number();
- }
- date * bmx_datetime_iter_date_add(date_iterator * d, int duration) {
- date dd(**d);
- return new date(dd + date_duration(duration));
- }
- date * bmx_datetime_iter_date_subtract(date_iterator * d, int duration) {
- return new date(**d - date_duration(duration));
- }
- int bmx_datetime_iter_date_subdate(date_iterator * d1, date * d2) {
- date_duration duration = (**d1) - *d2;
- return duration.days();
- }
- BBString * bmx_datetime_iter_to_simple_string(date_iterator * d) {
- return bbStringFromUTF8String((const unsigned char*)to_simple_string((**d)).c_str());
- }
- BBString * bmx_datetime_iter_to_iso_string(date_iterator * d) {
- return bbStringFromUTF8String((const unsigned char*)to_iso_string((**d)).c_str());
- }
- BBString * bmx_datetime_iter_to_iso_extended_string(date_iterator * d) {
- return bbStringFromUTF8String((const unsigned char*)to_iso_extended_string((**d)).c_str());
- }
- BBString * bmx_datetime_iter_to_string(date_iterator * d, std::locale * loc, date_facet * facet) {
- std::stringstream outputStringStream;
- outputStringStream.imbue(std::locale(*loc, facet));
- outputStringStream << (**d);
- return bmx_BBString_from_stream(outputStringStream);
- }
- BBString * bmx_datetime_iter_asformat(date_iterator * d, BBString * format, std::locale * loc, date_facet * facet) {
- std::stringstream outputStringStream;
- char * f = (char*)bbStringToUTF8String(format);
- facet->format(f);
- outputStringStream.imbue(std::locale(*loc, facet));
- outputStringStream << **d;
- BBString * ret = bmx_BBString_from_stream(outputStringStream);
- bbMemFree(f);
- return ret;
- }
- time_duration * bmx_time_duration(int hours, int minutes, int seconds, int fraction) {
- return new time_duration(hours, minutes, seconds, fraction);
- }
- void bmx_time_duration_free(time_duration * d) {
- delete d;
- }
- time_duration * bmx_time_duration_new_hours(int value) {
- return new time_duration(hours(value));
- }
- time_duration * bmx_time_duration_new_minutes(int value) {
- return new time_duration(minutes(value));
- }
- time_duration * bmx_time_duration_new_seconds(int value) {
- return new time_duration(seconds(value));
- }
- time_duration * bmx_time_duration_new_milliseconds(int value) {
- return new time_duration(milliseconds(value));
- }
- int bmx_time_duration_hours(time_duration * d) {
- return d->hours();
- }
- int bmx_time_duration_minutes(time_duration * d) {
- return d->minutes();
- }
- int bmx_time_duration_seconds(time_duration * d) {
- return d->seconds();
- }
- int bmx_time_duration_total_seconds(time_duration * d) {
- return d->total_seconds();
- }
- int bmx_time_ticks_per_second() {
- return time_duration::ticks_per_second();
- }
- int bmx_time_num_fractional_digits() {
- return (int)time_duration::num_fractional_digits();
- }
- int bmx_time_duration_total_milliseconds(time_duration * d) {
- return d->total_milliseconds();
- }
- int bmx_time_duration_fractional_seconds(time_duration * d) {
- return d->fractional_seconds();
- }
- int bmx_time_duration_is_negative(time_duration * d) {
- return d->is_negative();
- }
- time_duration * bmx_time_duration_invert_sign(time_duration * d) {
- return new time_duration(d->invert_sign());
- }
- BBString * bmx_time_duration_to_string(time_duration * d) {
- return bbStringFromUTF8String((const unsigned char*)to_simple_string(*d).c_str());
- }
- BBString * bmx_time_duration_to_iso_string(time_duration * d) {
- return bbStringFromUTF8String((const unsigned char*)to_iso_string(*d).c_str());
- }
- time_duration * bmx_time_duration_add(time_duration * d1, time_duration * d2) {
- return new time_duration(*d1 + *d2);
- }
- time_duration * bmx_time_duration_subtract(time_duration * d1, time_duration * d2) {
- return new time_duration(*d1 - *d2);
- }
- time_duration * bmx_time_duration_divide(time_duration * d1, int value) {
- return new time_duration(*d1 / value);
- }
- time_duration * bmx_time_duration_multiply(time_duration * d1, int value) {
- return new time_duration(*d1 * value);
- }
- int bmx_time_duration_less(time_duration * d1, time_duration * d2) {
- return *d1 < *d2;
- }
- int bmx_time_duration_greater(time_duration * d1, time_duration * d2) {
- return *d1 > *d2;
- }
- int bmx_time_duration_equal(time_duration * d1, time_duration * d2) {
- return *d1 == *d2;
- }
- BBString * bmx_time_duration_asformat(time_duration * d, BBString * format, std::locale * loc, time_facet * facet) {
- std::stringstream outputStringStream;
- char * f = (char*)bbStringToUTF8String(format);
- facet->time_duration_format(f);
- outputStringStream.imbue(std::locale(*loc, facet));
- outputStringStream << *d;
- BBString * ret = bmx_BBString_from_stream(outputStringStream);
- bbMemFree(f);
- return ret;
- }
- ptime * bmx_ptime_new(date * d, time_duration * t) {
- return new ptime(*d, *t);
- }
- void bmx_ptime_free(ptime * p) {
- delete p;
- }
- ptime * bmx_ptime_local_new() {
- return new ptime(second_clock::local_time());
- }
- ptime * bmx_ptime_universal_new() {
- return new ptime(second_clock::universal_time());
- }
- ptime * bmx_ptime_local_microsecond_new() {
- return new ptime(microsec_clock::local_time());
- }
- ptime * bmx_ptime_universal_microsecond_new() {
- return new ptime(microsec_clock::universal_time());
- }
- date * bmx_ptime_date(ptime * p) {
- return new date(p->date());
- }
- time_duration * bmx_ptime_time_of_day(ptime * p) {
- return new time_duration(p->time_of_day());
- }
- BBString * bmx_ptime_to_simple_string(ptime * p) {
- return bbStringFromUTF8String((const unsigned char*)to_simple_string(*p).c_str());
- }
- BBString * bmx_ptime_to_string(ptime * p, std::locale * loc, time_facet * facet) {
- std::stringstream outputStringStream;
- outputStringStream.imbue(std::locale(*loc, facet));
- outputStringStream << (*p);
- return bmx_BBString_from_stream(outputStringStream);
- }
- BBString * bmx_ptime_to_iso_string(ptime * p) {
- return bbStringFromUTF8String((const unsigned char*)to_iso_string(*p).c_str());
- }
- BBString * bmx_ptime_to_iso_extended_string(ptime * p) {
- return bbStringFromUTF8String((const unsigned char*)to_iso_extended_string(*p).c_str());
- }
- ptime * bmx_ptime_add_days(ptime * p, int d) {
- return new ptime(*p + days(d));
- }
- ptime * bmx_ptime_subtract_days(ptime * p, int d) {
- return new ptime(*p - days(d));
- }
- ptime * bmx_ptime_add_duration(ptime * p, time_duration * d) {
- return new ptime(*p + *d);
- }
- ptime * bmx_ptime_subtract_duration(ptime * p, time_duration * d) {
- return new ptime(*p - *d);
- }
- time_duration * bmx_ptime_subtract(ptime * p1, ptime * p2) {
- return new time_duration(*p1 - *p2);
- }
- int bmx_ptime_less(ptime * p1, ptime * p2) {
- return *p1 < *p2;
- }
- int bmx_ptime_greater(ptime * p1, ptime * p2) {
- return *p1 > *p2;
- }
- int bmx_ptime_equal(ptime * p1, ptime * p2) {
- return *p1 == *p2;
- }
- BBString * bmx_ptime_asformat(ptime * p, BBString * format, std::locale * loc, time_facet * facet) {
- std::stringstream outputStringStream;
- char * f = (char*)bbStringToUTF8String(format);
- facet->format(f);
- outputStringStream.imbue(std::locale(*loc, facet));
- outputStringStream << *p;
- BBString * ret = bmx_BBString_from_stream(outputStringStream);
- bbMemFree(f);
- return ret;
- }
- partial_date * bmx_partial_date_new(int day, int month) {
- return new partial_date(day, month);
- }
- date * bmx_partial_date_get_date(partial_date * p, int year) {
- return new date(p->get_date(year));
- }
- void bmx_partial_date_free(partial_date * p) {
- delete p;
- }
- last_day_of_the_week_in_month * bmx_last_day_of_week_in_month_new(int weekday, int month) {
- return new last_day_of_the_week_in_month(weekday, month);
- }
- date * bmx_last_day_of_week_in_month_get_date(last_day_of_the_week_in_month * p, int year) {
- return new date(p->get_date(year));
- }
- void bmx_last_day_of_week_in_month_free(last_day_of_the_week_in_month * p) {
- delete p;
- }
- first_day_of_the_week_in_month * bmx_first_day_of_week_in_month_new(int weekday, int month) {
- return new first_day_of_the_week_in_month(weekday, month);
- }
- date * bmx_first_day_of_week_in_month_get_date(first_day_of_the_week_in_month * p, int year) {
- return new date(p->get_date(year));
- }
- void bmx_first_day_of_week_in_month_free(first_day_of_the_week_in_month * p) {
- delete p;
- }
- BBString * bmx_weekday_to_string(int wd) {
- std::stringstream outputStringStream;
- outputStringStream << greg_weekday((unsigned short)wd);
- return bmx_BBString_from_stream(outputStringStream);
- }
- date_facet * bmx_datefacet_new() {
- return new date_facet;
- }
- time_facet * bmx_timefacet_new() {
- return new time_facet;
- }
- BBString * bmx_date_asformat(date * d, BBString * format, std::locale * loc, date_facet * facet) {
- std::stringstream outputStringStream;
- char * f = (char*)bbStringToUTF8String(format);
- facet->format(f);
- outputStringStream.imbue(std::locale(*loc, facet));
- outputStringStream << *d;
- BBString * ret = bmx_BBString_from_stream(outputStringStream);
- bbMemFree(f);
- return ret;
- }
- std::locale * bmx_locale_new(date_facet * d, boost::locale::generator * gen, BBString * loc) {
- std::locale * _loc = 0;
- char * l = (char*)bbStringToUTF8String(loc);
- try {
- _loc = new std::locale(gen->generate(l), d);
- } catch (std::exception & e) {
- _loc = new std::locale(gen->generate(""), d);
- }
- bbMemFree(l);
- return _loc;
- }
- void bmx_char_free(char * s) {
- free(s);
- }
- time_period * bmx_time_period_timetime(ptime * p1, ptime * p2) {
- return new time_period(*p1, *p2);
- }
- time_period * bmx_time_period_withduration(ptime * p, time_duration * d) {
- return new time_period(*p, *d);
- }
- void bmx_time_period_shift(time_period * tp, time_duration * d) {
- tp->shift(*d);
- }
- ptime * bmx_time_period_begin(time_period * tp) {
- return new ptime(tp->begin());
- }
- void bmx_time_period_free(time_period * tp) {
- delete tp;
- }
- ptime * bmx_time_period_last(time_period * tp) {
- return new ptime(tp->last());
- }
- ptime * bmx_time_period_end(time_period * tp) {
- return new ptime(tp->end());
- }
- time_duration * bmx_time_period_length(time_period * tp) {
- return new time_duration(tp->length());
- }
- int bmx_time_period_is_null(time_period * tp) {
- return tp->is_null();
- }
- int bmx_time_period_contains(time_period * tp, ptime * t) {
- return tp->contains(*t);
- }
- int bmx_time_period_containsPeriod(time_period * tp1, time_period * tp2) {
- return tp1->contains(*tp2);
- }
- int bmx_time_period_intersects(time_period * tp1, time_period * tp2) {
- return tp1->intersects(*tp2);
- }
- time_period * bmx_time_period_intersection(time_period * tp1, time_period * tp2) {
- return new time_period(tp1->intersection(*tp2));
- }
- time_period * bmx_time_period_merge(time_period * tp1, time_period * tp2) {
- return new time_period(tp1->merge(*tp2));
- }
- time_period * bmx_time_period_span(time_period * tp1, time_period * tp2) {
- return new time_period(tp1->span(*tp2));
- }
- int bmx_time_period_isless(time_period * tp1, time_period * tp2) {
- return *tp1 < *tp2;
- }
- int bmx_time_period_isgreater(time_period * tp1, time_period * tp2) {
- return *tp1 > *tp2;
- }
- int bmx_time_period_isequal(time_period * tp1, time_period * tp2) {
- return *tp1 == *tp2;
- }
- BBString * bmx_time_period_to_simple_string(time_period * tp) {
- return bbStringFromUTF8String((const unsigned char*)to_simple_string(*tp).c_str());
- }
- ptime * bmx_ptime_from_time_t(std::time_t * t) {
- return new ptime(from_time_t(*t));
- }
- MaxTimeZone * bmx_posix_time_zone(BBString * id) {
- char * d = (char*)bbStringToUTF8String(id);
- time_zone_ptr _zone = time_zone_ptr(new posix_time_zone(std::string(d)));
- bbMemFree(d);
- return new MaxTimeZone(_zone);
- }
- BBString * bmx_time_zone_dst_zone_abbrev(MaxTimeZone * tz) {
- return bbStringFromUTF8String((const unsigned char*)tz->timeZone->dst_zone_abbrev().c_str());
- }
- BBString * bmx_time_zone_std_zone_abbrev(MaxTimeZone * tz) {
- return bbStringFromUTF8String((const unsigned char*)tz->timeZone->std_zone_abbrev().c_str());
- }
- BBString * bmx_time_zone_dst_zone_name(MaxTimeZone * tz) {
- return bbStringFromUTF8String((const unsigned char*)tz->timeZone->dst_zone_name().c_str());
- }
- BBString * bmx_time_zone_std_zone_name(MaxTimeZone * tz) {
- return bbStringFromUTF8String((const unsigned char*)tz->timeZone->std_zone_name().c_str());
- }
- int bmx_time_zone_has_dst(MaxTimeZone * tz) {
- return tz->timeZone->has_dst();
- }
- ptime * bmx_time_zone_dst_local_start_time(MaxTimeZone * tz, int year) {
- return new ptime(tz->timeZone->dst_local_start_time(year));
- }
- ptime * bmx_time_zone_dst_local_end_time(MaxTimeZone * tz, int year) {
- return new ptime(tz->timeZone->dst_local_end_time(year));
- }
- time_duration * bmx_time_zone_base_utc_offset(MaxTimeZone * tz) {
- return new time_duration(tz->timeZone->base_utc_offset());
- }
- time_duration * bmx_time_zone_dst_offset(MaxTimeZone * tz) {
- return new time_duration(tz->timeZone->dst_offset());
- }
- BBString * bmx_time_zone_to_posix_string(MaxTimeZone * tz) {
- return bbStringFromUTF8String((const unsigned char*)tz->timeZone->to_posix_string().c_str());
- }
- void bmx_time_zone_free(MaxTimeZone * tz) {
- delete tz;
- }
- tz_database * bmx_tz_database() {
- return new tz_database();
- }
- tz_database * bmx_tz_load_from_file(BBString * filename) {
- char * f = (char*)bbStringToUTF8String(filename);
- tz_database * db = new tz_database();
- db->load_from_file(std::string(f));
- bbMemFree(f);
- return db;
- }
- void bmx_tz_database_free(tz_database * db) {
- delete db;
- }
- void bmx_tz_database_add_record(tz_database * db, BBString * id, MaxTimeZone * tz) {
- char * n = (char*)bbStringToUTF8String(id);
- db->add_record(std::string(n), tz->timeZone);
- bbMemFree(n);
- }
- BBArray * bmx_tz_database_region_list(tz_database * db) {
- std::vector<std::string> list = db->region_list();
- int n=list.size();
- BBArray *p = bbArrayNew1D( "$",n );
- BBString **s = (BBString**)BBARRAYDATA( p,p->dims );
- for( int i = 0; i < n; ++i ){
- s[i] = bbStringFromUTF8String((unsigned char*)list[i].c_str());
- }
- return p;
- }
- MaxTimeZone * bmx_tz_time_zone_from_region(tz_database * db, BBString * id) {
- char * d = (char*)bbStringToUTF8String(id);
- time_zone_ptr p = db->time_zone_from_region(std::string(d));
- bbMemFree(d);
- return new MaxTimeZone(p);
- }
- local_date_time * bmx_local_date_time_new_sec_clock(MaxTimeZone * tz) {
- return new local_date_time(local_sec_clock::local_time(tz->timeZone));
- }
- local_date_time * bmx_local_date_time_new_time(ptime * p, MaxTimeZone * tz) {
- return new local_date_time(*p, tz->timeZone);
- }
- BBString * bmx_month_to_string(int m) {
- std::stringstream outputStringStream;
- outputStringStream << greg_month((unsigned short)m);
- return bmx_BBString_from_stream(outputStringStream);
- }
- void bmx_date_facet_format(date_facet * f, BBString * fmt) {
- char * s = (char*)bbStringToUTF8String(fmt);
- f->format(s);
- bbMemFree(s);
- }
- void bmx_date_facet_set_iso_format(date_facet * f) {
- f->set_iso_format();
- }
- void bmx_date_facet_set_iso_extended_format(date_facet * f) {
- f->set_iso_extended_format();
- }
- void bmx_date_facet_short_month_names(date_facet * f, BBArray * names) {
- std::string m_names[12];
- BBString **s=(BBString**)BBARRAYDATA( names,names->dims );
- for (int i = 0; i < 12; i++) {
- char * n = (char*)bbStringToUTF8String(s[i]);
- m_names[i] = std::string(n);
- bbMemFree(n);
- }
-
- std::vector<std::string> v_names(&m_names[0], &m_names[12]);
-
- f->short_month_names(v_names);
- }
- void bmx_date_facet_long_month_names(date_facet * f, BBArray * names) {
- std::string m_names[12];
- BBString **s=(BBString**)BBARRAYDATA( names,names->dims );
- for (int i = 0; i < 12; i++) {
- char * n = (char*)bbStringToUTF8String(s[i]);
- m_names[i] = std::string(n);
- bbMemFree(n);
- }
-
- std::vector<std::string> v_names(&m_names[0], &m_names[12]);
-
- f->long_month_names(v_names);
- }
- void bmx_date_facet_short_weekday_names(date_facet * f, BBArray * names) {
- std::string m_names[7];
- BBString **s=(BBString**)BBARRAYDATA( names,names->dims );
- for (int i = 0; i < 7; i++) {
- char * n = (char*)bbStringToUTF8String(s[i]);
- m_names[i] = std::string(n);
- bbMemFree(n);
- }
-
- std::vector<std::string> v_names(&m_names[0], &m_names[7]);
-
- f->short_weekday_names(v_names);
- }
- void bmx_date_facet_long_weekday_names(date_facet * f, BBArray * names) {
- std::string m_names[7];
- BBString **s=(BBString**)BBARRAYDATA( names,names->dims );
- for (int i = 0; i < 7; i++) {
- char * n = (char*)bbStringToUTF8String(s[i]);
- m_names[i] = std::string(n);
- bbMemFree(n);
- }
-
- std::vector<std::string> v_names(&m_names[0], &m_names[7]);
-
- f->long_weekday_names(v_names);
- }
- void bmx_date_facet_month_format(date_facet * f, BBString * fmt) {
- char * s = (char*)bbStringToUTF8String(fmt);
- f->month_format(s);
- bbMemFree(s);
- }
- void bmx_date_facet_weekday_format(date_facet * f, BBString * fmt) {
- char * s = (char*)bbStringToUTF8String(fmt);
- f->weekday_format(s);
- bbMemFree(s);
- }
- void bmx_time_facet_format(time_facet * f, BBString * fmt) {
- char * s = (char*)bbStringToUTF8String(fmt);
- f->format(s);
- bbMemFree(s);
- }
- void bmx_time_facet_set_iso_format(time_facet * f) {
- f->set_iso_format();
- }
- void bmx_time_facet_set_iso_extended_format(time_facet * f) {
- f->set_iso_extended_format();
- }
- void bmx_time_facet_month_format(time_facet * f, BBString * fmt) {
- char * s = (char*)bbStringToUTF8String(fmt);
- f->month_format(s);
- bbMemFree(s);
- }
- void bmx_time_facet_weekday_format(time_facet * f, BBString * fmt) {
- char * s = (char*)bbStringToUTF8String(fmt);
- f->weekday_format(s);
- bbMemFree(s);
- }
- void bmx_time_facet_time_duration_format(time_facet * f, BBString * fmt) {
- char * s = (char*)bbStringToUTF8String(fmt);
- f->time_duration_format(s);
- bbMemFree(s);
- }
- nth_day_of_the_week_in_month * bmx_nth_day_of_week_in_month_new(int nth, int weekday, int month) {
- nth_day_of_the_week_in_month::week_num w;
- switch (nth) {
- case 1:
- w = nth_day_of_the_week_in_month::first;
- break;
- case 2:
- w = nth_day_of_the_week_in_month::second;
- break;
- case 3:
- w = nth_day_of_the_week_in_month::third;
- break;
- case 4:
- w = nth_day_of_the_week_in_month::fourth;
- break;
- case 5:
- w = nth_day_of_the_week_in_month::fifth;
- break;
- default:
- w = nth_day_of_the_week_in_month::first;
- }
- return new nth_day_of_the_week_in_month(w, weekday, month);
- }
- date * bmx_nth_day_of_week_in_month_get_date(nth_day_of_the_week_in_month * p, int year) {
- return new date(p->get_date(year));
- }
- void bmx_nth_day_of_week_in_month_free(nth_day_of_the_week_in_month * p) {
- delete p;
- }
- first_day_of_the_week_after * bmx_first_day_of_week_after_new(int weekday) {
- return new first_day_of_the_week_after(weekday);
- }
- date * bmx_first_day_of_week_after_get_date(first_day_of_the_week_after * p, date * d) {
- return new date(p->get_date(*d));
- }
- void bmx_first_day_of_week_after_free(first_day_of_the_week_after * p) {
- delete p;
- }
- first_day_of_the_week_before * bmx_first_day_of_week_before_new(int weekday) {
- return new first_day_of_the_week_before(greg_weekday(weekday));
- }
- date * bmx_first_day_of_week_before_get_date(first_day_of_the_week_before * p, date * d) {
- return new date(p->get_date(*d));
- }
- void bmx_first_day_of_week_before_free(first_day_of_the_week_before * p) {
- delete p;
- }
- int bmx_days_until_weekday(date * d, int weekday) {
- return days_until_weekday(*d, greg_weekday(weekday)).days();
- }
- int bmx_days_before_weekday(date * d, int weekday) {
- return days_before_weekday(*d, greg_weekday(weekday)).days();
- }
- date * bmx_next_weekday(date * d, int weekday) {
- return new date(next_weekday(*d, greg_weekday(weekday)));
- }
- date * bmx_previous_weekday(date * d, int weekday) {
- return new date(previous_weekday(*d, greg_weekday(weekday)));
- }
- MaxTimeZone * bmx_local_date_time_zone(local_date_time * ldt) {
- return new MaxTimeZone(ldt->zone());
- }
- int bmx_local_date_time_is_dst(local_date_time * ldt) {
- return ldt->is_dst();
- }
- ptime * bmx_local_date_time_utc_time(local_date_time * ldt) {
- return new ptime(ldt->utc_time());
- }
- ptime * bmx_local_date_time_local_time(local_date_time * ldt) {
- return new ptime(ldt->local_time());
- }
- BBString * bmx_local_date_time_to_string(local_date_time * ldt) {
- std::stringstream outputStringStream;
- outputStringStream << *ldt;
- return bmx_BBString_from_stream(outputStringStream);
- }
- int bmx_local_date_time_less(local_date_time * ldt1, local_date_time * ldt2) {
- return *ldt1 < *ldt2;
- }
- int bmx_local_date_time_greater(local_date_time * ldt1, local_date_time * ldt2) {
- return *ldt1 > *ldt2;
- }
- int bmx_local_date_time_equal(local_date_time * ldt1, local_date_time * ldt2) {
- return *ldt1 == *ldt2;
- }
- local_date_time * bmx_local_date_time_add_days(local_date_time * ldt, int value) {
- return new local_date_time(*ldt + days(value));
- }
- local_date_time * bmx_local_date_time_add_months(local_date_time * ldt, int value) {
- return new local_date_time(*ldt + months(value));
- }
- local_date_time * bmx_local_date_time_add_years(local_date_time * ldt, int value) {
- return new local_date_time(*ldt + years(value));
- }
- local_date_time * bmx_local_date_time_subtract_days(local_date_time * ldt, int value) {
- return new local_date_time(*ldt - days(value));
- }
- local_date_time * bmx_local_date_time_subtract_months(local_date_time * ldt, int value) {
- return new local_date_time(*ldt - months(value));
- }
- local_date_time * bmx_local_date_time_subtract_years(local_date_time * ldt, int value) {
- return new local_date_time(*ldt - years(value));
- }
- local_date_time * bmx_local_date_time_add_duration(local_date_time * ldt, time_duration * td) {
- return new local_date_time(*ldt + *td);
- }
- local_date_time * bmx_local_date_time_subtract_duration(local_date_time * ldt, time_duration * td) {
- return new local_date_time(*ldt - *td);
- }
- void bmx_local_date_time_free(local_date_time * ldt) {
- delete ldt;
- }
- local_time_period * bmx_local_time_period_new(local_date_time * ldt1, local_date_time * ldt2) {
- return new local_time_period(*ldt1, *ldt2);
- }
- local_time_period * bmx_local_time_period_new_duration(local_date_time * ldt, time_duration * d) {
- return new local_time_period(*ldt, *d);
- }
- void bmx_local_time_period_free(local_time_period * ldt) {
- delete ldt;
- }
- local_date_time * bmx_local_time_period_begin(local_time_period * ldt) {
- return new local_date_time(ldt->begin());
- }
- local_date_time * bmx_local_time_period_last(local_time_period * ldt) {
- return new local_date_time(ldt->last());
- }
- local_date_time * bmx_local_time_period_end(local_time_period * ldt) {
- return new local_date_time(ldt->end());
- }
- time_duration * bmx_local_time_period_length(local_time_period * ldt) {
- return new time_duration(ldt->length());
- }
- int bmx_local_time_period_is_null(local_time_period * ldt) {
- return ldt->is_null();
- }
- int bmx_local_time_period_contains_time(local_time_period * ldt, local_date_time * t) {
- return ldt->contains(*t);
- }
- int bmx_local_time_period_contains(local_time_period * ldt1, local_time_period * ldt2) {
- return ldt1->contains(*ldt2);
- }
- int bmx_local_time_period_intersects(local_time_period * ldt1, local_time_period * ldt2) {
- return ldt1->intersects(*ldt2);
- }
- local_time_period * bmx_local_time_period_intersection(local_time_period * ldt1, local_time_period * ldt2) {
- return new local_time_period(ldt1->intersection(*ldt2));
- }
- local_time_period * bmx_local_time_period_merge(local_time_period * ldt1, local_time_period * ldt2) {
- return new local_time_period(ldt1->merge(*ldt2));
- }
- local_time_period * bmx_local_time_period_span(local_time_period * ldt1, local_time_period * ldt2) {
- return new local_time_period(ldt1->span(*ldt2));
- }
- void bmx_local_time_period_shift(local_time_period * ldt, time_duration * d) {
- ldt->shift(*d);
- }
- int bmx_local_time_period_less(local_time_period * ldt1, local_time_period * ldt2) {
- return *ldt1 < *ldt2;
- }
- int bmx_local_time_period_greater(local_time_period * ldt1, local_time_period * ldt2) {
- return *ldt1 > *ldt2;
- }
- int bmx_local_time_period_equal(local_time_period * ldt1, local_time_period * ldt2) {
- return *ldt1 == *ldt2;
- }
- int bmx_end_of_month_day(int y, int m) {
- return gregorian_calendar::end_of_month_day(y, m);
- }
|