Date System using negative Numbers

Ga
Gantra
Posts: 4
Joined: Fri Dec 01, 2017 10:13 pm
Platform: Mac + Windows

Fri Dec 01, 2017 10:49 pm Post

I am writing a sci-fi novel set a million years in the future. I have decided the simplest way is to use positive and negative numbers around a key point in time where my narrative formally begins which is date 0.

However, at present if I use a simple text field for the meta-field and use a negative sign it will not order the negative numbers correctly. Do you have a suggestion as to how I could do this? Or can you create an enhancement to the metafield options that would handle this scenario? This is like a BC/AD type of date system.

Example:

-1,000,000/01/01
-800,000/01/01
-700,000/01/01
-200,000/01/01
0/01/01
14/01/01
120/01/01
300/01/01

Thanks so much! Loving Scrivener 3.

User avatar
AmberV
Posts: 21575
Joined: Sun Jun 18, 2006 4:30 am
Platform: Mac + Linux
Location: Santiago de Compostela, Galiza
Contact:

Mon Jan 08, 2018 1:56 pm Post

I’m not thinking of anything off of the top of my head, but it wouldn’t surprise me if someone has battled this one before. Basically the problem is that you want the following variables:

  • Million+ year date reckoning.
  • Positive and negative nomenclature.
  • A system that works in a typical alphanumeric sorting algorithm.
Maybe see what geologists do? ;)
.:.
Ioa Petra'ka
“Whole sight, or all the rest is desolation.” —John Fowles

User avatar
rdale
Posts: 1160
Joined: Tue Jul 14, 2015 1:07 pm
Platform: Mac, Win + iOS
Location: St. Louis, MO
Contact:

Mon Jan 08, 2018 3:00 pm Post

EDIT: I was not thinking this through, or I would have noted that alphabetic sorting treats -1 as "less than" -9, since it just storts minus signs (both the same), and then sorts 1 vs 9. Please disregard this post.

-----------------------------

Since scrivener doesn't have a numeric metadata field type (date doesn't count), you have to rely on sorting numbers like text, which works just like alphabetic sorting does. In other words...
  1. Sort everything by 1st character, then by 2nd character within groups that have the same 1st, then by 3rd character within groups with the same 1st & 2nd character, etc....
  2. Sort shorter strings (words) before longer strings (words) if the longer string starts with the shorter string. (Ex: "too" comes before "took", alphabetically)
  3. Sorting numbers this way means ALL numbers must have the same number of digits (and must include the same punctuation in the same positions). Padding to the left with zeroes is how you do that. You're already doing something similar with the month and day numbers, adding leading zeroes to the 1s.
  4. Sorting "dates" like this also requires that you start with the largest unit of time as the first part of each date, and get smaller as you move right, which you're doing. The American standard of Month-Day-Year wouldn't sort that way (which is why I'm glad Scrivener backups get a date formatted to sort properly, instead of relying on the system default).
  5. You can get more precise to the right, adding a time stamp (24 hour time, or equivalent for whatever planet you're telling time on). Adding extra sortable time units to the right assumes midnight on those dates without any time specified.
  6. Lucky for you, I believe "-" sorts before "+", so you can continue using those symbols.

In your example, the numbers/dates have to all be changed to this to sort properly:
-1,000,000/01/01
-0,800,000/01/01
-0,700,000/01/01
-0,200,000/01/01
+0,000,000/01/01
+0,000,014/01/01
+0,000,120/01/01
+0.000,300/01/01

This also makes things line up properly, so you have that going for you.
Last edited by rdale on Mon Jan 08, 2018 6:32 pm, edited 2 times in total.
FKA: robertdguthrie
AKA: R Dale Guthrie, Robert, Mr. Obscure, and "Oh, it's you again".

User avatar
Silverdragon
Posts: 601
Joined: Mon Jul 29, 2013 2:52 pm
Platform: Mac + iOS
Location: Tarzana, California, USA
Contact:

Mon Jan 08, 2018 5:14 pm Post

rdale wrote:...
In your example, the numbers/dates have to all be changed to this to sort properly:
-1,000,000/01/01
-0,800,000/01/01
-0,700,000/01/01
-0,200,000/01/01
+0,000,000/01/01
+0,000,014/01/01
+0,000,120/01/01
+0.000,300/01/01

This also makes things line up properly, so you have that going for you.

Sadly, I just tried this and the numbers actually sorted:

-0,200,000/01/01
-0,700,000/01/01
-0,800,000/01/01
-1,000,000/01/01
+0,000,000/01/01
+0,000,014/01/01
+0,000,120/01/01
+0.000,300/01/01
So you know where I'm coming from:
  • I'm a user, not an L&L employee.
  • Mac Scrivener 3.0.3, MacBook Air 11, MacOS 10.13.5 (High Sierra)
  • IOS Scrivener 1.1.5, iPhone 6s, iPad Air 2, iOS 11.4

User avatar
rdale
Posts: 1160
Joined: Tue Jul 14, 2015 1:07 pm
Platform: Mac, Win + iOS
Location: St. Louis, MO
Contact:

Mon Jan 08, 2018 5:28 pm Post

Silverdragon wrote:Sadly, I just tried this and the numbers actually sorted:

-0,200,000/01/01
-0,700,000/01/01
-0,800,000/01/01
-1,000,000/01/01
+0,000,000/01/01
+0,000,014/01/01
+0,000,120/01/01
+0.000,300/01/01

Dammit! I forgot about negative magnitudes... alpha-sorting ignores that -1 million is less than -1 hundred, even with leading zeroes making everything line up. Sorry. For positive numbers only, alphabetic sorting works on numbers & numerical dates and times that are left-padded with zeroes (and which use 24hr time); I have to deal with file names with dates being the most accurate way to sort data all the time, but my dates never go negative.

Thanks for testing my hypothesis, SilverDragon.
FKA: robertdguthrie
AKA: R Dale Guthrie, Robert, Mr. Obscure, and "Oh, it's you again".

User avatar
Bridey
Posts: 390
Joined: Wed Nov 22, 2017 2:24 pm
Platform: Mac

Mon Jan 08, 2018 5:46 pm Post

Following rdale's suggestion, does it work in two stages: sort the negative numbers descending; the positive numbers ascending?

User avatar
rdale
Posts: 1160
Joined: Tue Jul 14, 2015 1:07 pm
Platform: Mac, Win + iOS
Location: St. Louis, MO
Contact:

Mon Jan 08, 2018 6:29 pm Post

Bridey wrote:Following rdale's suggestion, does it work in two stages: sort the negative numbers descending; the positive numbers ascending?

No, I was wrong in how alpha sorting treats negative numbers. Please disregard my post.
FKA: robertdguthrie
AKA: R Dale Guthrie, Robert, Mr. Obscure, and "Oh, it's you again".

User avatar
Bridey
Posts: 390
Joined: Wed Nov 22, 2017 2:24 pm
Platform: Mac

Mon Jan 08, 2018 6:32 pm Post

rdale wrote:
Bridey wrote:Following rdale's suggestion, does it work in two stages: sort the negative numbers descending; the positive numbers ascending?

No, I was wrong in how alpha sorting treats negative numbers. Please disregard my post.


Okay, but in my test, the numbers come out as you list them...

User avatar
rdale
Posts: 1160
Joined: Tue Jul 14, 2015 1:07 pm
Platform: Mac, Win + iOS
Location: St. Louis, MO
Contact:

Mon Jan 08, 2018 6:40 pm Post

Bridey wrote:
rdale wrote:
Bridey wrote:Following rdale's suggestion, does it work in two stages: sort the negative numbers descending; the positive numbers ascending?

No, I was wrong in how alpha sorting treats negative numbers. Please disregard my post.


Okay, but in my test, the numbers come out as you list them...

How odd. I don't have my Mac with me today, so I can't test this... Scrivener sorts this information as a custom metadata text field the same as my example? Or are you using some other metadata type? Because the negative years should sort in the opposite order, as SilverDragon claims they do.
FKA: robertdguthrie
AKA: R Dale Guthrie, Robert, Mr. Obscure, and "Oh, it's you again".

User avatar
Bridey
Posts: 390
Joined: Wed Nov 22, 2017 2:24 pm
Platform: Mac

Mon Jan 08, 2018 6:58 pm Post

rdale wrote:How odd. I don't have my Mac with me today, so I can't test this... Scrivener sorts this information as a custom metadata text field the same as my example? Or are you using some other metadata type? Because the negative years should sort in the opposite order, as SilverDragon claims they do.


Ah, I’m just dropping the numbers into the body of a text file and then using the sort tools. My error. Apologies.

User avatar
Bridey
Posts: 390
Joined: Wed Nov 22, 2017 2:24 pm
Platform: Mac

Mon Jan 08, 2018 7:22 pm Post

My meta sort doesn’t look like Silverdragon’s. I get...

Meta Sort.jpg
Meta Sort.jpg (38.59 KiB) Viewed 1557 times

User avatar
rdale
Posts: 1160
Joined: Tue Jul 14, 2015 1:07 pm
Platform: Mac, Win + iOS
Location: St. Louis, MO
Contact:

Mon Jan 08, 2018 7:56 pm Post

Bridey: Did you use a Text metadata field, or a Date metadata field? I assume it's not a Checkbox metadata field, and I don't recall any other types... That may be the key to how people are getting different results.
FKA: robertdguthrie
AKA: R Dale Guthrie, Robert, Mr. Obscure, and "Oh, it's you again".

User avatar
Bridey
Posts: 390
Joined: Wed Nov 22, 2017 2:24 pm
Platform: Mac

Mon Jan 08, 2018 8:08 pm Post

rdale wrote:Bridey: Did you use a Text metadata field, or a Date metadata field? I assume it's not a Checkbox metadata field, and I don't recall any other types... That may be the key to how people are getting different results.


Hi.

I called the field ‘date’, but used a ‘text’ type.

Types are: text, checkbox, list, and date

Meta Type.jpg
Meta Type.jpg (136.4 KiB) Viewed 1541 times

User avatar
rdale
Posts: 1160
Joined: Tue Jul 14, 2015 1:07 pm
Platform: Mac, Win + iOS
Location: St. Louis, MO
Contact:

Tue Jan 09, 2018 12:34 am Post

Now that I'm less distracted, I just noticed that your sorted dates are in descending order if you ignore the postive/negative symbols. The order it should be (to reflect how our own BC/AD dates work) would be as I originally listed them. Your sort order has the largest positive date (year 300) as the next value after -0,200,000/01/01. The first positive date after the year -200,000 should be +0,000,000/01/01.
FKA: robertdguthrie
AKA: R Dale Guthrie, Robert, Mr. Obscure, and "Oh, it's you again".

User avatar
Bridey
Posts: 390
Joined: Wed Nov 22, 2017 2:24 pm
Platform: Mac

Tue Jan 09, 2018 6:44 am Post

rdale wrote:Now that I'm less distracted, I just noticed that your sorted dates are in descending order if you ignore the postive/negative symbols. The order it should be (to reflect how our own BC/AD dates work) would be as I originally listed them. Your sort order has the largest positive date (year 300) as the next value after -0,200,000/01/01. The first positive date after the year -200,000 should be +0,000,000/01/01.


Absolutely. I posted just to show the difference to what Silverdragon saw in her test.

Sort again and the positive dates go into the right order, but the negative dates are inverted. If it were possible to treat the negatives and positives as two discrete groups, each could be sorted correctly. As it is, one group is right at any time (I think), which might well help the OP with their needs. So, I believe your idea pretty much works...unless I have misunderstood all along.

Negaitve and Positive Dates.jpg
Negaitve and Positive Dates.jpg (89.74 KiB) Viewed 1469 times


Removing the plus signs impacts on the sort, but not in a meaningful way. As such, the OP doesn't need to use the plus signs.

Plus Removed.jpg
Plus Removed.jpg (86.13 KiB) Viewed 1466 times