Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d32bad7
some more build options
pkyoyetera Jun 4, 2021
0af71b5
chrono workspace
pkyoyetera Jun 4, 2021
ef205e9
build options, fix DayOfTheWeekParser regex bug
pkyoyetera Jun 4, 2021
ce27e09
one more regex bug
pkyoyetera Jun 4, 2021
6d14401
optimize build file, fix some compiler warnings
pkyoyetera Jun 4, 2021
2b2b7f7
might be smarter to use an enum than strings
pkyoyetera Jun 4, 2021
1dd0846
another broke regex in ENTimeLaterParser
pkyoyetera Jun 4, 2021
ca38726
clean up
pkyoyetera Jun 4, 2021
accce59
small issue with this test
pkyoyetera Jun 4, 2021
5229aaf
create call chain in place of using a container
pkyoyetera Jun 5, 2021
fcdaca0
unused result container smh
pkyoyetera Jun 5, 2021
097020d
namespace and a small abstraction between result and it's components
pkyoyetera Jun 5, 2021
62f7a13
namespace
pkyoyetera Jun 5, 2021
ab86603
changelog, simple af makefile, bazelrc
pkyoyetera Jun 5, 2021
359158c
workflow
pkyoyetera Jun 5, 2021
d39d859
oops
pkyoyetera Jun 5, 2021
e2bd55e
space
pkyoyetera Jun 5, 2021
871fb58
perhaps make
pkyoyetera Jun 5, 2021
478647a
issa bazel event
pkyoyetera Jun 5, 2021
85a31be
.
pkyoyetera Jun 5, 2021
74f9e89
tab
pkyoyetera Jun 5, 2021
0fd3b33
c++17
pkyoyetera Jun 5, 2021
bbf28cf
one more
pkyoyetera Jun 5, 2021
76ff7bd
set gcc version in workflow
pkyoyetera Jun 7, 2021
e904da1
syntax
pkyoyetera Jun 7, 2021
e2472ac
get compiler first
pkyoyetera Jun 7, 2021
7778bd6
perhaps in the makefile?
pkyoyetera Jun 7, 2021
c813b9f
10 not 8
pkyoyetera Jun 7, 2021
208f622
syntax
pkyoyetera Jun 7, 2021
0262263
not sure why you can't find string_view, wrong gcc version?
pkyoyetera Jun 7, 2021
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
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test --test_output=all --test_arg=--gtest_color=yes
22 changes: 22 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

on: push
name: build
jobs:
checks:
name: run
runs-on: ubuntu-latest
steps:
- run: |
sudo apt update
sudo apt install gcc-10 g++-10
- uses: actions/checkout@v2
with:
ref: pk/re2

- name: run
uses: ngalaiko/bazel-action/2.0.0@master
with:
environment:
CC: gcc-10
CXX: g++-10
args: build //...
41 changes: 16 additions & 25 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
load("//:boost.bzl", "boost")
load("//:chrono.bzl", "copts", "linkopts")

cc_binary(
name = "time",
srcs = glob(
[
"time.cpp",
"src/**/*.hpp",
"src/**/*.cpp",
],
),
copts = [
"-std=c++17",
"-g",
"-O0",
],
includes = ["src"],
deps = [
"@boost//:date_time",
],
)
COPTS = copts(stdc="-std=c++17")
LINKOPTS = linkopts()

cc_library(
name = "libtime",
Expand All @@ -28,14 +12,21 @@ cc_library(
hdrs = glob(
["src/**/*.hpp"],
),
copts = [
"-std=c++17",
"-g",
"-O0",
],
#includes = ["src"],
copts = COPTS,
visibility = ["//visibility:public"],
deps = [
"@boost//:algorithm",
"@boost//:date_time",
],
)

cc_binary(
name = "time",
srcs = glob([
"time.cpp",
]),
copts = COPTS,
deps = [
"//:libtime",
],
)
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
* Some abstraction between `parsed_result` and `parsed_components`
* namespace fixes
* bug fixes
* Add easier configuration for debug and optimized build options
* Added changelog
* Added simple makefile for github actions
* set up build github workflow for the repository

16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@


export CC := gcc-10
export CXX := g++-10

debug:
bazel build -c dbg ...

release:
bazel build -c opt :time

clean:
bazek clean

test:
bazel test ...
19 changes: 14 additions & 5 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
workspace(name = "time")
workspace(name = "chrono")

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

# =====================================================================
# Boost
# Boost
# =====================================================================
load("@time//:boost.bzl", "boost")
load("@chrono//:boost.bzl", "boost")
boost()

load("@com_github_nelhage_rules_boost//:boost/boost.bzl", "boost_deps")
boost_deps()

# =====================================================================
# Googletest
# Googletest
# =====================================================================
git_repository(
name = "googletest",
tag = "release-1.8.1",
remote = "https://github.com/google/googletest",
tag = "release-1.8.1",
)

# =====================================================================
# Google RE2
# =====================================================================
git_repository(
name = "re2",
remote = "https://github.com/google/re2",
tag = "2021-06-01",
)
61 changes: 61 additions & 0 deletions chrono.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
def default_settings():
native.config_setting(
name = "C++17",
values = {
"define": "C++=17",
},
visibility = ["//visibility:public"],
)

native.config_setting(
name = "C++2a",
values = {
"define": "C++=2a",
},
visibility = ["//visibility:public"],
)

native.config_setting(
name = "dbg_mode",
values = {
"compilation_mode": "dbg",
},
visibility = ["//visibility:public"],
)

native.config_setting(
name = "opt_mode",
values = {
"compilation_mode": "opt",
},
visibility = ["//visibility:public"],
)

native.config_setting(
name = "fastbuild_mode",
values = {
"compilation_mode": "fastbuild",
},
visibility = ["//visibility:public"],
)

def copts(stdc = "-std=c++17", O = "02"):
default_settings()
return select({
"//:C++17": ["-std=c++17"],
"//:C++2a": ["-std=c++2a"],
"//conditions:default": [stdc],
}) + select({
"//:dbg_mode": ["-Wall", "-Wextra", "-Wpedantic"],
"//:fastbuild_mode": ["-g1"],
"//:opt_mode": ["-DNDEBUG", O],
"//conditions:default": []
})

def linkopts():
return select({
"//:dbg_mode": ["-g", "-rdynamic"],
"//:fastbuild_mode": ["-g1", "-rdynamic"],
"//:opt_mode": ["-rdynamic"],
"//conditions:default": []
})
175 changes: 1 addition & 174 deletions src/result.cpp → src/parsed_component.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "src/result.hpp"
#include "parsed_component.hpp"

using namespace parse;
using namespace std;
Expand Down Expand Up @@ -324,176 +324,3 @@ bool ParsedComponents::isPossibleDate() {
}

/***************************************************************************************/

ParsedResult::ParsedResult() {
index = 0;
text = "";

ParsedComponents tmp1; //, tmp2{};
startDate = tmp1;
__end = false;
// endDate = tmp2;

/*
for(auto val: startDate.knownValues) {
val->second().first() = false;
val->second().second() = 0;
}

for(auto val: startDate.impliedValues) {
val->second().first() = false;
val->second().second() = 0;
}

for(auto val: endDate.knownValues) {
val->second().first() = false;
val->second().second() = 0;
}

for(auto val: endDate.impliedValues) {
val->second().first() = false;
val->second().second() = 0;
}
*/
}

ParsedResult::ParsedResult(posix_time::ptime an, long idx, std::string tx) {
anchor = an;
index = idx;
text = tx;

ParsedComponents tmp; //, _tmp{};
startDate = tmp;
__end = false;
// endDate = tmp;
}

// need to implement use of endDate
ParsedResult::ParsedResult(const ParsedResult& pr) {
anchor = pr.anchor;
index = pr.index;
text = pr.text;
tags = pr.tags;
startDate = pr.startDate;
__end = false;

if(pr.end()) {
endDate = pr.endDate;
__end = true;
}
}

bool ParsedResult::hasPossibleDates() {
/**
* @brief checks if (*this) result contains a valid date
*/
if(startDate.getYear() == 0 and startDate.getMonth() == 0 and
startDate.get_mDay() == 0 and// startDate.get_wDay() == 0 and
startDate.getHour() == 0 and startDate.getMinute() == 0 and
startDate.getSeconds() == 0 and end() == false)
return false;

//return startDate.isPossibleDate() and (!end() or endDate.isPossibleDate());
return true;
}

ParsedResult::~ParsedResult() { }

std::string ParsedResult::toDate() {
// todo: take into account timezone offset
// temporary timezone adjustment to UTC.
// NOTE: this is machine dependent. Be very careful where/when its used
// typedef date_time::local_adjustor<posix_time::ptime, -5, posix_time::us_dst> us_eastern;
struct tm date_start, date_end;
std::string res;

date_start.tm_year = startDate.getYear() - 1900;
date_start.tm_mon = startDate.getMonth() - 1;
date_start.tm_mday = startDate.get_mDay();
date_start.tm_hour = startDate.getHour();
date_start.tm_min = startDate.getMinute();
date_start.tm_sec = startDate.getSeconds();

posix_time::ptime st = posix_time::ptime_from_tm(date_start);
// posix_time::ptime st = us_eastern::local_to_utc(posix_time::ptime_from_tm(date_start));

if(getTag(utils::ExtractTimeZoneAbbreviation))
st += posix_time::minutes(startDate.getTimeZoneOffset());

res = posix_time::to_simple_string(st);

if(end()) {
date_end.tm_year = endDate.getYear() - 1900;
date_end.tm_mon = endDate.getMonth() - 1;
date_end.tm_mday = endDate.get_mDay();
date_end.tm_hour = endDate.getHour();
date_end.tm_min = endDate.getMinute();
date_end.tm_sec = endDate.getSeconds();

posix_time::ptime ed = posix_time::ptime_from_tm(date_end);
if(getTag(utils::ExtractTimeZoneAbbreviation))
ed += posix_time::minutes(startDate.getTimeZoneOffset());

res += " - " + posix_time::to_simple_string(posix_time::ptime_from_tm(date_end));
}

return res;
}

unsigned ParsedResult::getIndex() const {
return index;
}

void ParsedResult::setIndex(int idx) {
index = idx;
return;
}

void ParsedResult::setText(std::string tx) {
text = tx;
}

size_t ParsedResult::textLength() const {
return text.length();
}

void ParsedResult::setTag(utils::Modifiers tag_name) {
if(tags.count(tag_name) < 1)
this->tags.insert({tag_name, true});
}

bool ParsedResult::isEmpty() const {
if(index == 0 and text.empty())
return true;
return false;
} // better way to check for empty result

bool ParsedResult::end() const {
return __end;
}

void ParsedResult::makeEndDateValid() {
__end = true;
}

bool ParsedResult::getTag(utils::Modifiers m) {
return tags[m];

}

ParsedResult& ParsedResult::operator=(ParsedResult pr) {
anchor = pr.anchor;
endDate = pr.endDate;
startDate = pr.startDate;
text = pr.text;
index = pr.index;
tags = pr.tags;
__end = pr.end();

return *(this);
}

/*ParsedResult& ParsedResult::operator=(ParsedResult &) {
return <#initializer#>;
}
*/
Loading