LyonsTheWay2Gold
LyonsTheWay2Gold

Reputation: 373

Retrieve TimeStamp Values From FireStore C#

Having a really hard time retrieving any TimeStamp values from my Firestore DB and displaying them. I am able to return all other values I request.

[FirestoreData]
class FireBaseJobs 
{
    [FirestoreProperty]
    public string jobstatus { get; set; }
    [FirestoreProperty]
    public string workcompleted { get; set; }
    [FirestoreProperty]
    public string labour { get; set; }
    [FirestoreProperty]
    public string materials { get; set; }
    [FirestoreProperty]
    public string descriptionmaterials { get; set; }
    [FirestoreProperty]
    public string starttime { get; set; }
    [FirestoreProperty]
    public string endtime { get; set; }
    [FirestoreProperty]
    public string value { get; set; }
}

I am listening to any updates made.

starttime, endtime and value are all UTC timestamps.

void checkFirestore()
    {

        CollectionReference docRef = database.Collection("jobs");

        Query query = database.Collection("jobs").WhereNotEqualTo("jobstatus", new[] { "Allocated", "Unallocated" });

        FirestoreChangeListener listener = query.Listen(snapshot =>
        {

            foreach (DocumentSnapshot documentSnapshot in snapshot.Documents)
            {
                FireBaseJobs job = documentSnapshot.ConvertTo<FireBaseJobs>();


            }
        });
    }

Updated

[FirestoreProperty]
    public object starttime { get; set; }
    [FirestoreProperty]
    public object endtime { get; set; }
    [FirestoreProperty]
    public object value { get; set; }

Upvotes: 0

Views: 1185

Answers (2)

LyonsTheWay2Gold
LyonsTheWay2Gold

Reputation: 373

Fixed by changing starttime, endtime and value to objects in my CLASS, then converting each object to a string and then converting to date or datetime.

Upvotes: 0

DIGI Byte
DIGI Byte

Reputation: 4163

If the Timestamp is a Firestore.Timestamp, then it is stored as a nanosecond accurate date.Time object. Firestore has this object accessible and defined as Firebase.Firestore.Timestamp

Reference: Unity C# Firestore.Timestamp

If you are dealing with a string value: you can remove the last 3 digits to make it Date.now() compliant

Upvotes: 2

Related Questions