Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Alchemy Viewer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Silent mode is enabled
All outbound communications are blocked.
Learn more
.
Show more breadcrumbs
Alchemy Viewer
Alchemy Viewer
Commits
305ec89a
Commit
305ec89a
authored
15 years ago
by
James Cook
Browse files
Options
Downloads
Patches
Plain Diff
Added ageFromDateISO() for YYYY-MM-DD dates
parent
087736c1
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
indra/newview/lldateutil.cpp
+26
-5
26 additions, 5 deletions
indra/newview/lldateutil.cpp
indra/newview/lldateutil.h
+6
-0
6 additions, 0 deletions
indra/newview/lldateutil.h
indra/newview/tests/lldateutil_test.cpp
+10
-0
10 additions, 0 deletions
indra/newview/tests/lldateutil_test.cpp
with
42 additions
and
5 deletions
indra/newview/lldateutil.cpp
+
26
−
5
View file @
305ec89a
...
@@ -59,12 +59,9 @@ static S32 days_from_month(S32 year, S32 month)
...
@@ -59,12 +59,9 @@ static S32 days_from_month(S32 year, S32 month)
}
}
}
}
std
::
string
LLDateUtil
::
age
F
rom
D
ate
(
const
std
::
string
&
date_string
,
static
std
::
string
age
_f
rom
_d
ate
(
S32
born_year
,
S32
born_month
,
S32
born_day
,
const
LLDate
&
now
)
const
LLDate
&
now
)
{
{
S32
born_month
,
born_day
,
born_year
;
S32
matched
=
sscanf
(
date_string
.
c_str
(),
"%d/%d/%d"
,
&
born_month
,
&
born_day
,
&
born_year
);
if
(
matched
!=
3
)
return
"???"
;
LLDate
born_date
;
LLDate
born_date
;
born_date
.
fromYMDHMS
(
born_year
,
born_month
,
born_day
);
born_date
.
fromYMDHMS
(
born_year
,
born_month
,
born_day
);
F64
born_date_secs_since_epoch
=
born_date
.
secondsSinceEpoch
();
F64
born_date_secs_since_epoch
=
born_date
.
secondsSinceEpoch
();
...
@@ -155,7 +152,31 @@ std::string LLDateUtil::ageFromDate(const std::string& date_string,
...
@@ -155,7 +152,31 @@ std::string LLDateUtil::ageFromDate(const std::string& date_string,
return
LLTrans
::
getString
(
"TodayOld"
);
return
LLTrans
::
getString
(
"TodayOld"
);
}
}
std
::
string
LLDateUtil
::
ageFromDate
(
const
std
::
string
&
date_string
,
const
LLDate
&
now
)
{
S32
born_month
,
born_day
,
born_year
;
S32
matched
=
sscanf
(
date_string
.
c_str
(),
"%d/%d/%d"
,
&
born_month
,
&
born_day
,
&
born_year
);
if
(
matched
!=
3
)
return
"???"
;
return
age_from_date
(
born_year
,
born_month
,
born_day
,
now
);
}
std
::
string
LLDateUtil
::
ageFromDate
(
const
std
::
string
&
date_string
)
std
::
string
LLDateUtil
::
ageFromDate
(
const
std
::
string
&
date_string
)
{
{
return
ageFromDate
(
date_string
,
LLDate
::
now
());
return
ageFromDate
(
date_string
,
LLDate
::
now
());
}
}
std
::
string
LLDateUtil
::
ageFromDateISO
(
const
std
::
string
&
date_string
,
const
LLDate
&
now
)
{
S32
born_month
,
born_day
,
born_year
;
S32
matched
=
sscanf
(
date_string
.
c_str
(),
"%d-%d-%d"
,
&
born_year
,
&
born_month
,
&
born_day
);
if
(
matched
!=
3
)
return
"???"
;
return
age_from_date
(
born_year
,
born_month
,
born_day
,
now
);
}
std
::
string
LLDateUtil
::
ageFromDateISO
(
const
std
::
string
&
date_string
)
{
return
ageFromDateISO
(
date_string
,
LLDate
::
now
());
}
This diff is collapsed.
Click to expand it.
indra/newview/lldateutil.h
+
6
−
0
View file @
305ec89a
...
@@ -44,6 +44,12 @@ namespace LLDateUtil
...
@@ -44,6 +44,12 @@ namespace LLDateUtil
// Calls the above with LLDate::now()
// Calls the above with LLDate::now()
std
::
string
ageFromDate
(
const
std
::
string
&
date_string
);
std
::
string
ageFromDate
(
const
std
::
string
&
date_string
);
// As above, for YYYY-MM-DD dates
std
::
string
ageFromDateISO
(
const
std
::
string
&
date_string
,
const
LLDate
&
now
);
// Calls the above with LLDate::now()
std
::
string
ageFromDateISO
(
const
std
::
string
&
date_string
);
}
}
#endif
#endif
This diff is collapsed.
Click to expand it.
indra/newview/tests/lldateutil_test.cpp
+
10
−
0
View file @
305ec89a
...
@@ -189,4 +189,14 @@ namespace tut
...
@@ -189,4 +189,14 @@ namespace tut
LLDateUtil
::
ageFromDate
(
"12/13/2009"
,
now
),
LLDateUtil
::
ageFromDate
(
"12/13/2009"
,
now
),
"3 weeks old"
);
"3 weeks old"
);
}
}
template
<
>
template
<
>
void
dateutil_object_t
::
test
<
6
>
()
{
set_test_name
(
"ISO dates"
);
LLDate
now
(
std
::
string
(
"2010-01-04T12:00:00Z"
));
ensure_equals
(
"days"
,
LLDateUtil
::
ageFromDateISO
(
"2009-12-13"
,
now
),
"3 weeks old"
);
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment