Пример #1
0
        public void PlusDays_ReturnsExpectedDate(int count)
        {
            var result   = Today.PlusDays(count);
            var expected = LocalDate.FromDateTime(DateTime.Now.AddDays(count).Date);

            result.Should().Be(expected);
        }
Пример #2
0
        protected override void RunJournalCommand()
        {
            var journal   = OpenJournal();
            var entryDate = Date == null?Today.PlusDays(DateOffset) : LocalDate.FromDateTime(Date.Value).PlusDays(DateOffset);

            var hour = Now.Time().Hour;

            if (hour >= 0 && hour <= 4)
            {
                var dayPrior = entryDate.Minus(Period.FromDays(1));
                var question = $"Did you mean to create an entry for '{dayPrior}' or '{entryDate}'?";
                var result   = Choice("It's after midnight!", question, 0, dayPrior.DayOfWeek.ToChoiceString(), entryDate.DayOfWeek.ToChoiceString());
                if (result == 0)
                {
                    entryDate = dayPrior;
                }
            }

            Commit(GitCommitType.PreNewJournalEntry);

            try
            {
                journal.CreateNewEntry(entryDate, Tags, Readme);
                Commit(GitCommitType.PostNewJournalEntry);
            }
            catch (JournalEntryAlreadyExistsException e)
            {
                var question = $"An entry for {entryDate} already exists. Do you want to open it instead?";
                if (YesOrNo(question))
                {
                    SystemProcess.Start(e.EntryFilePath);
                }
            }
        }
Пример #3
0
        protected override void RunJournalCommand()
        {
            if (Last)
            {
                var journal   = OpenJournal();
                var lastEntry = journal.CreateIndex <JournalEntryFile>().SelectMany(x => x.Entries).OrderByDescending(x => x.EntryDate).First();
                SystemProcess.Start(lastEntry.FilePath);
                return;
            }

            var       fileSystem    = new FileSystem();
            var       journalWriter = new JournalWriter(fileSystem, Location);
            string    path;
            LocalDate entryDate;

            switch (ParameterSetName)
            {
            case "Name":
            {
                entryDate = EntryName.EndsWith(".md") ? Journal.FileNameWithExtensionPattern.Parse(EntryName).Value : Journal.FileNamePattern.Parse(EntryName).Value;
                path      = journalWriter.GetJournalEntryFilePath(entryDate);
                break;
            }

            case "Date":
            {
                entryDate = LocalDate.FromDateTime(Date);
                path      = journalWriter.GetJournalEntryFilePath(entryDate);
                break;
            }

            case "DateOffset":
            {
                entryDate = Today.PlusDays(DateOffset);
                path      = journalWriter.GetJournalEntryFilePath(entryDate);
                break;
            }

            case "Entry":
            {
                entryDate = Journal.FileNamePattern.Parse(Entry.EntryName).Value;
                path      = journalWriter.GetJournalEntryFilePath(entryDate);
                break;
            }

            default:
                throw new NotSupportedException();
            }

            if (!fileSystem.File.Exists(path))
            {
                throw new PSInvalidOperationException($"An entry does not exist for '{entryDate}'.");
            }

            SystemProcess.Start(path);
        }
Пример #4
0
        protected override void RunJournalCommand()
        {
            if (Last)
            {
                var journal   = OpenJournal();
                var lastEntry = journal.CreateIndex <JournalEntryFile>().SelectMany(x => x.Entries).OrderByDescending(x => x.EntryDate).FirstOrDefault();
                if (lastEntry == null)
                {
                    throw new PSInvalidOperationException("No entries found!");
                }
                SystemProcess.Start(lastEntry.FilePath);
                return;
            }

            var       fileSystem    = new FileSystem();
            var       journalWriter = new JournalWriter(fileSystem, Location);
            string    path;
            LocalDate entryDate;

            switch (ParameterSetName)
            {
            case "Name":
            {
                entryDate = EntryName.EndsWith(".md") ? Journal.FileNameWithExtensionPattern.Parse(EntryName).Value : Journal.FileNamePattern.Parse(EntryName).Value;
                path      = journalWriter.GetJournalEntryFilePath(entryDate);
                break;
            }

            case "Date":
            {
                entryDate = LocalDate.FromDateTime(Date);
                path      = journalWriter.GetJournalEntryFilePath(entryDate);
                break;
            }

            case "DateOffset":
            {
                entryDate = Today.PlusDays(DateOffset);
                path      = journalWriter.GetJournalEntryFilePath(entryDate);
                break;
            }

            case "Entry":
            {
                entryDate = Journal.FileNamePattern.Parse(Entry.EntryName).Value;
                path      = journalWriter.GetJournalEntryFilePath(entryDate);
                break;
            }

            default:
                throw new NotSupportedException();
            }

            if (!fileSystem.File.Exists(path))
            {
                throw new PSInvalidOperationException($"An entry does not exist for '{entryDate}'.");
            }

            Commit(GitCommitType.PreOpenJournalEntry);
            SystemProcess.Start(path);

            if (Wait)
            {
                var result = Choice($"Reading entry for {entryDate}", "Continue on to next entry?", 0, "&Continue", "&Quit");
                Commit(GitCommitType.PostOpenJournalEntry);
                if (result == 1)
                {
                    ThrowTerminatingError("Pipeline terminated at user's request.", ErrorCategory.NotSpecified);
                }
            }
        }